diff options
| author | tv <tv@krebsco.de> | 2026-11-13 20:24:39 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-13 20:24:39 +0000 |
| commit | 5913c6cc383ade12a8edc01d0f47d9671fb53227 (patch) | |
| tree | e78aef7551e544f3d73175a680e3990e97bda0bc /src/swarm | |
| parent | e8a6110722b3d9cb6611631eeafedddd4f9b4cec (diff) | |
relay: a STATUS's heads wait at least 50 ms before they are pulled
A neighbour pulls heads a STATUS listed only if it still lacks them after
a round trip to the sender, as they are usually on their way along a
writer's tree. With no round trip known, or one measured long ago (busy
pairs send no keepalives), it pulled at once; with a short one, a STATUS
sent right after a change can overtake it by more than that round trip,
delays varying per message. Either way the change came twice
(`trees_hold_through_continuous_writes`: c pulled once while every write
reached it along x's tree).
The wait is the round trip, but 50 ms at least (and 1 s at most, as
before).
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/relay.rs | 16 |
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 { |
