summaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-22 21:55:36 +0200
committertv <tv@krebsco.de>2026-10-22 21:55:36 +0200
commita098d7e5eaf486fe3d9813f690745619121bac65 (patch)
tree8fbff9c158c2bbadcb70ad30fc4b485f16bd10bb /src/swarm/sync.rs
parentc97161adb3142041c00d649a51924318b5a2d6e4 (diff)
don't resend sync messages to up-to-date peers
When an sync messages arrives and automerge has nothing to say about it, then no reply is generated. With c9279e4 it was assumed that every sync message gets an answer, so missing replies caused unnecessary resends. Now a reply is only awaited if the peer's last reported heads differ from ours. If the peer's heads become equal through a third peer without replying, the waiting will also abort if a ping or pong showss the same heads digest on both sides.
Diffstat (limited to 'src/swarm/sync.rs')
-rw-r--r--src/swarm/sync.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 810c3de..47c3b7f 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -110,9 +110,19 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool
peer_state.needs_generate = false;
let epoch = replica.epoch;
let sent_before = peer_state.sync_state.sent_hashes.clone();
- let sync_doc = replica.doc.sync();
- let message = sync_doc.generate_sync_message(&mut peer_state.sync_state);
- if message.is_some() {
+ let message = {
+ let sync_doc = replica.doc.sync();
+ sync_doc.generate_sync_message(&mut peer_state.sync_state)
+ };
+ // A peer whose heads are ours already has everything; Automerge
+ // answers only when it has something to say, so it will stay
+ // silent. Waiting for an answer would only end in a pointless
+ // resend.
+ let in_step = peer_state.sync_state.their_heads.as_ref()
+ == Some(&replica.doc.get_heads());
+ if in_step {
+ peer_state.sync_in_step();
+ } else if message.is_some() {
let sent = peer_state
.sync_state
.sent_hashes