summaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
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()