diff options
| author | tv <tv@krebsco.de> | 2026-11-01 21:01:43 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 21:01:43 +0100 |
| commit | 9edf5e5d56596458c9f8faf289cc5328aef08226 (patch) | |
| tree | e1809beca905767d9d82ba4d5569a2925f9cbb2f /src/state | |
| parent | da18be3c9bbfdd5b3b4ff19f48863a7badf6074d (diff) | |
introduce per-transport sync reply timeout
Diffstat (limited to 'src/state')
| -rw-r--r-- | src/state/mod.rs | 2 | ||||
| -rw-r--r-- | src/state/timing.rs | 23 |
2 files changed, 14 insertions, 11 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs index a4ea553..cd96aaf 100644 --- a/src/state/mod.rs +++ b/src/state/mod.rs @@ -24,7 +24,7 @@ mod timing; pub(crate) use peer::{HelloState, Incidents, Keepalive, Liveness, PeerState, Standing}; pub(crate) use read::{ReadSource, StaleView}; -pub(crate) use timing::Timing; +pub(crate) use timing::{SYNC_REPLY_TIMEOUT, Timing}; use std::collections::HashMap; use std::sync::Arc; diff --git a/src/state/timing.rs b/src/state/timing.rs index 988e430..af5c0c0 100644 --- a/src/state/timing.rs +++ b/src/state/timing.rs @@ -4,9 +4,10 @@ use std::time::Duration; use crate::backoff::Backoff; -/// First wait for a sync answer; generous, since a transport may take a while with large -/// messages (Mycelium sends them in many small packets). -const SYNC_REPLY_TIMEOUT: Duration = Duration::from_secs(10); +/// First wait for a sync answer, unless a transport needs longer +/// (`Transport::sync_reply_timeout`); generous, since a transport may take a while with +/// large messages (Mycelium sends them in many small packets). +pub(crate) const SYNC_REPLY_TIMEOUT: Duration = Duration::from_secs(10); /// Upper bound, as a multiple of the first wait: 5 minutes, about as long as a transport /// tries to deliver a message (`Transport::delivery_limit`). const SYNC_REPLY_TIMEOUT_MAX_FACTOR: u32 = 30; @@ -47,6 +48,12 @@ impl Timing { self.keepalive * 5 } + /// [`new`](Self::new) with the default first sync reply timeout. + #[cfg(test)] + pub(crate) fn from_keepalive(keepalive: Duration, delivery_limit: Duration) -> Self { + Self::new(keepalive, SYNC_REPLY_TIMEOUT, delivery_limit) + } + /// The timings for `--keepalive`. /// /// Each node keeps about `k` neighbours (`--neighbours`) whatever the swarm's size, @@ -63,13 +70,9 @@ impl Timing { /// | LAN, servers | 15–30 s | a returning or silent peer is noticed within a minute or two | /// | WAN, mobile, metered (the default, 1m) | 60–120 s | about 0.4 messages per second per node at `k` = 12 and 1m | /// - /// `delivery_limit`: the transport's (`Transport::delivery_limit`). - pub(crate) fn from_keepalive(keepalive: Duration, delivery_limit: Duration) -> Self { - Self::new(keepalive, SYNC_REPLY_TIMEOUT, delivery_limit) - } - - /// [`from_keepalive`](Self::from_keepalive) with another first sync reply timeout: - /// for tests, whose messages don't travel for seconds. + /// `sync_reply_timeout`: the transports' (`Transport::sync_reply_timeout`), or for + /// tests, whose messages don't travel for seconds, a shorter one. `delivery_limit`: + /// the transports' (`Transport::delivery_limit`). pub(crate) fn new( keepalive: Duration, sync_reply_timeout: Duration, |
