summaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-10-23 22:56:30 +0200
committertv <tv@krebsco.de>2026-10-23 23:08:00 +0200
commit487690bb0fb63c5dcc80d009632bd9430d946af1 (patch)
treefad60f7a09d681e6d4e2641adb04c54e601bbd75 /src/swarm/sync.rs
parentd1ea53c3b9c24fc07435b12ae46d8b519ffddba9 (diff)
both sides may open sync after reset
Ready nodes will leave the first message to the pear that isn't ready. Hello and hello reply now carry ready, so readiness is known from the very first contact, before any sync. Together with the sync messages and keepalives, reports_ready is always current. After epoch switch, pings go to everyone except ready members already on the new epoch, these learn from the lagging peer's opening.
Diffstat (limited to 'src/swarm/sync.rs')
-rw-r--r--src/swarm/sync.rs27
1 files changed, 8 insertions, 19 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 8a85b8c..c918fe8 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -41,6 +41,8 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool
return Ok(());
};
+ let we_ready = state.is_ready().await;
+
let validated_swarm = {
let peer_state = peer_state_mutex.lock().await;
@@ -80,27 +82,14 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str, retry_delivery: bool
return Ok(());
}
- let now = Instant::now();
- if let Some(wait) = peer_state.sync.opening_wait(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));
- });
+ if peer_state
+ .sync
+ .leave_opening(we_ready, peer_state.reports_ready)
+ {
+ // Its own opening (or anything else from it) brings us back here.
+ trace!("Leaving the opening sync message to the peer, which isn't ready");
return Ok(());
}
- if peer_state.sync.opening_overdue(now) {
- debug!(
- cause = ?peer_state.sync.cause,
- likely = peer_state.sync.cause.missing_opening_hint(),
- "The peer didn't open the sync within the grace period; opening ourselves"
- );
- }
}
swarm_id.clone()