aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/wire.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/wire.rs')
-rw-r--r--src/transport/wire.rs15
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