summaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-23 06:43:33 +0200
committertv <tv@krebsco.de>2026-10-23 06:43:33 +0200
commit55882636e3601c72af641c1096d96e7eff61b78b (patch)
tree05bb847e865126fd79d491be27998e60f2f03f15 /src/swarm
parenta098d7e5eaf486fe3d9813f690745619121bac65 (diff)
open sync only from one side
If both sides open, the openings cross, and an empty node's answer to the other opening (empty heads) makes the other side send the whole document a second time. Now after a sync reset, only the side with the smaller public key opens the sync; the other answers it, or opens itself if nothing arrives.
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/sync.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 47c3b7f..d82238e 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -58,10 +58,28 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool
return Ok(());
}
- match &peer_state.membership {
- PeerMembership::Unknown => return Ok(()),
- PeerMembership::Member { swarm_id } => swarm_id.clone(),
+ let PeerMembership::Member { swarm_id } = &peer_state.membership else {
+ return Ok(());
+ };
+
+ if !retry_delivery {
+ let we_open = state.local_id() < peer;
+ if let Some(wait) = peer_state.opening_wait(we_open, Instant::now()) {
+ trace!(
+ wait_ms = wait.as_millis(),
+ "Leaving the opening sync message to the peer"
+ );
+ let tx = state.sync_events.clone();
+ let peer = peer.to_owned();
+ tokio::spawn(async move {
+ tokio::time::sleep(wait).await;
+ let _ = tx.send(SyncEvent::PeerNeedsSync(peer));
+ });
+ return Ok(());
+ }
}
+
+ swarm_id.clone()
};
let swarm_id = state