From c73199a2114916097703b846841413f61d79c5f9 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 14:26:30 +0000 Subject: wire: a handshake of another kind doesn't go in a version that says none A HELLO in version 52 says no kind, and is read as of an Automerge document: a node holding another kind would be refused for it. Such a handshake is not written in a version before 53 (WireError::OtherKind), and waits for the peer to say what it speaks. --- src/transport/wire.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/transport') diff --git a/src/transport/wire.rs b/src/transport/wire.rs index 54efd0f..dda052b 100644 --- a/src/transport/wire.rs +++ b/src/transport/wire.rs @@ -183,6 +183,10 @@ pub(crate) fn encode_in(message: &ParsedMessage, version: u8) -> Result, /// which only the versions from `KINDS` on carry. fn of_another_kind(message: &ParsedMessage) -> bool { match message { + // A handshake in a version that says no kind is taken for an Automerge + // document's: one of another kind waits for a version that says it. + ParsedMessage::Hello(hello) => hello.kind != crate::document::KIND, + ParsedMessage::HelloReply(reply) => reply.kind != crate::document::KIND, ParsedMessage::Sync(envelope) => { matches!(envelope.body, crate::transport::SyncBody::Kind(_)) } @@ -1238,7 +1242,16 @@ mod tests { other => panic!("{other:?}"), }; assert_eq!(read(&hello("another"), KINDS), "another"); - assert_eq!(read(&hello("another"), KINDS - 1), crate::document::KIND); + // The version before says no kind, and one read in it is Automerge's: a + // handshake of another kind doesn't go in it. + assert_eq!( + read(&hello(crate::document::KIND), KINDS - 1), + crate::document::KIND + ); + assert!(matches!( + encode_in(&hello("another"), KINDS - 1), + Err(WireError::OtherKind(_)) + )); assert_eq!( read(&hello(crate::document::KIND), VERSION), crate::document::KIND -- cgit v1.3.1