diff options
| author | tv <tv@krebsco.de> | 2026-11-30 14:26:30 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 14:26:30 +0000 |
| commit | c73199a2114916097703b846841413f61d79c5f9 (patch) | |
| tree | 936e27a86d3f97a526576a5cfb515e94c98db51c /src/transport/wire.rs | |
| parent | af9de78d7de36848f6ff115c9710fb90d2468af2 (diff) | |
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.
Diffstat (limited to 'src/transport/wire.rs')
| -rw-r--r-- | src/transport/wire.rs | 15 |
1 files changed, 14 insertions, 1 deletions
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<Vec<u8>, /// 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 |
