From 2311d0cc57a2e0d5776b355983ca2e3f82f9980f Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 23 Oct 2026 21:25:34 +0200 Subject: use only ready peers as sync source Sync messages now carries a ready flag, telling whether the sending peer itself is joined or is itself still (re-)joining. In the latter case, the peer won't be used as sync source. --- src/transport/mod.rs | 4 ++++ src/transport/mycelium.rs | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'src/transport') diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 69d9e70..eeba47f 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -62,6 +62,10 @@ pub struct SyncEnvelope { /// Epoch of the document the message was generated from. pub epoch: Epoch, pub message: Message, + /// The sender was ready when it generated the message: its document is the swarm's, + /// not one it is still filling (joining, rejoining). Only such a peer can tell a + /// catching-up node that it has everything; an empty document says nothing else. + pub ready: bool, } /// A message serialized for the wire. Cloning is cheap (shared buffer). diff --git a/src/transport/mycelium.rs b/src/transport/mycelium.rs index 84a34ea..193beaa 100644 --- a/src/transport/mycelium.rs +++ b/src/transport/mycelium.rs @@ -818,6 +818,9 @@ pub struct SyncEnvelopeShadow<'a> { pub message: automerge::sync::Message, #[serde(default)] epoch: EpochShadow, + /// Absent from nodes that predate it: never counts as ready. + #[serde(default)] + ready: bool, } // ===================================================================== @@ -890,6 +893,7 @@ pub fn sync_envelope_to_bytes(msg: &SyncEnvelope) -> Result, rmp_serde:: swarm_id: Cow::Borrowed(&msg.swarm_id), message: msg.message.clone(), // Clone required by automerge_msg_codec ownership rules epoch: epoch_to_shadow(&msg.epoch), + ready: msg.ready, }; rmp_serde::to_vec(&shadow) } @@ -899,6 +903,7 @@ pub fn bytes_to_sync_envelope(bytes: &[u8]) -> Result