aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/relay.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-06 04:32:20 +0100
committertv <tv@krebsco.de>2026-11-06 04:32:20 +0100
commitc85e4efec5bf8c5d83401816b6de4f46fbedd99e (patch)
tree53d2190f00bc015d7c62852d246df8459cd95846 /src/swarm/relay.rs
parentc51bb8a4d8ece9f48d40482b0af8e4be9f771432 (diff)
one grace wait per peer
Diffstat (limited to 'src/swarm/relay.rs')
-rw-r--r--src/swarm/relay.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 31df0d3..0f8a697 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -325,21 +325,25 @@ pub(crate) async fn lacks(state: &AppState, heads: &HeadsSummary) -> bool {
/// most; at once if we know none). While writes go on, the newest of them are usually
/// on their way to us along their writers' trees, as fast as the STATUS: they come
/// meanwhile, and pulling them would only fetch them twice. What is still missing then
-/// was missed.
+/// was missed. One wait per peer: a STATUS that comes meanwhile is the one judged at the
+/// end (`PeerState::pull_pending`).
pub(crate) async fn pull_after_grace(state: &AppState, peer: &str, remote: &transport::Status) {
- if HeadsSummary::of(state.stamp.borrow().heads.to_vec()) == remote.heads {
- return;
- }
- let grace = state
- .lock_rtt()
- .effective(peer, Instant::now(), state.timing.rtt_fresh_for())
- .map(|rtt| rtt.min(PULL_GRACE_MAX));
- if let Some(grace) = grace
- && lacks(state, &remote.heads).await
- {
- tokio::time::sleep(grace).await;
+ if HeadsSummary::of(state.stamp.borrow().heads.to_vec()) != remote.heads {
+ let grace = state
+ .lock_rtt()
+ .effective(peer, Instant::now(), state.timing.rtt_fresh_for())
+ .map(|rtt| rtt.min(PULL_GRACE_MAX));
+ if let Some(grace) = grace
+ && lacks(state, &remote.heads).await
+ {
+ tokio::time::sleep(grace).await;
+ }
}
- pull_if_behind(state, peer, remote).await;
+ let latest = match state.get_peer_state(peer).await {
+ Some(peer_state) => peer_state.lock().await.pull_pending.take(),
+ None => None,
+ };
+ pull_if_behind(state, peer, latest.as_ref().unwrap_or(remote)).await;
}
/// If `peer` has heads we lack (as its STATUS `remote` says), pull them (one peer at a