aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/relay.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/swarm/relay.rs b/src/swarm/relay.rs
index 5f7b8c0..54749b0 100644
--- a/src/swarm/relay.rs
+++ b/src/swarm/relay.rs
@@ -59,6 +59,11 @@ const PULL_TIMEOUT: Duration = Duration::from_secs(15);
/// was missed waits no longer.
const PULL_GRACE_MAX: Duration = Duration::from_secs(1);
+/// The least they wait: a STATUS sent right after a change went along a tree can
+/// overtake it by more than a short round trip (delays vary per message, and links
+/// reorder), and a round trip measured long ago, or none, says nothing.
+const PULL_GRACE_MIN: Duration = Duration::from_millis(50);
+
/// How long an announcement waits for further changes to ride along, and a random part
/// on top (`ANNOUNCE_JITTER`), so that of two neighbours with the same news one usually
/// announces first and the other, seeing the first's heads are its own, skips it
@@ -325,8 +330,8 @@ pub(crate) async fn lacks(state: &AppState, heads: &HeadsSummary) -> bool {
}
/// A STATUS from `peer` (a keepalive's, or an announcement): if it has heads we lack,
-/// pull them, but only those we still lack after a round trip to it (`PULL_GRACE_MAX` at
-/// most; at once if we know none). While writes go on, the newest of them are usually
+/// pull them, but only those we still lack after a round trip to it (`PULL_GRACE_MIN` at
+/// least, `PULL_GRACE_MAX` at most). 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. One wait per peer: a STATUS that comes meanwhile is the one judged at the
@@ -342,10 +347,9 @@ pub(crate) async fn pull_after_grace(state: &AppState, peer: &str, remote: &tran
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 {
- tokio::time::sleep(grace).await;
- }
+ .unwrap_or_default()
+ .clamp(PULL_GRACE_MIN, PULL_GRACE_MAX);
+ tokio::time::sleep(grace).await;
}
}
let latest = match state.get_peer_state(peer).await {