diff options
| -rw-r--r-- | docs/peers.md | 3 | ||||
| -rw-r--r-- | src/swarm/relay.rs | 16 |
2 files changed, 12 insertions, 7 deletions
diff --git a/docs/peers.md b/docs/peers.md index 4aa1334..f5b6ab6 100644 --- a/docs/peers.md +++ b/docs/peers.md @@ -330,7 +330,8 @@ own announcement or STATUS brought them, are this node's: announcements wait 200 the other skips it; nor one whose latest heads, as it said them in a STATUS or a sync message, have all of this node's in their history: it is as far or further), and a neighbour that lacks those heads pulls them (it sets them as the peer's heads in its sync state, so Automerge asks for what's missing), if it still lacks them after a round trip to the announcer (at -most 1 s): while writes go on, the newest are usually on their way to it along a +least 50 ms, at most 1 s: a STATUS can overtake a change sent just before it by more +than a short round trip, and a round trip measured long ago says nothing): while writes go on, the newest are usually on their way to it along a writer's tree, and would otherwise come twice. It pulls from one neighbour at a time (until the answer is overdue, by the sync reply timeout, or 15 s); neighbours that announce heads it lacks meanwhile wait their turn and are pulled from as soon as the 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 { |
