From 7af8f58d46737bb5835aa1625485f22ecf374ebe Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 27 Oct 2026 00:33:03 +0100 Subject: add Transport::delivery_limit --- src/state/timing.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/state/timing.rs') diff --git a/src/state/timing.rs b/src/state/timing.rs index 3c4afe1..0dab3da 100644 --- a/src/state/timing.rs +++ b/src/state/timing.rs @@ -4,18 +4,16 @@ use std::time::Duration; use crate::backoff::Backoff; -/// First wait for a sync answer; generous, since Mycelium delivers large messages in -/// many small packets. +/// 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); -/// Upper bound, as a multiple of the first wait: 5 minutes (Mycelium gives up on a -/// message after five minutes). +/// 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; /// Upper bound on the wait between probes of an unreachable peer, as a multiple of /// `dormant_probe`: an hour at the default keepalive (1m). A returning node HELLOs its own /// neighbours, so this only bounds how long one we never hear from stays out. const PROBE_MAX_FACTOR: u32 = 6; -/// How long Mycelium tries to deliver a message before dropping it. -const MYCELIUM_DELIVERY_LIMIT: Duration = Duration::from_secs(300); #[derive(Clone, Copy, Debug)] pub(crate) struct Timing { @@ -28,8 +26,9 @@ pub(crate) struct Timing { /// First wait for an answer to a sync message before sending again; doubles while /// answers stay out (`SyncSession::reply_backoff`). pub(crate) sync_reply_timeout: Duration, - /// How long the transport tries to deliver a message before dropping it (Mycelium: - /// five minutes): a peer silent for longer has nothing on the way to us any more. + /// How long the transport tries to deliver a message before dropping it + /// (`Transport::delivery_limit`): a peer silent for longer has nothing on the way to + /// us any more. pub(crate) delivery_limit: Duration, } @@ -54,13 +53,19 @@ impl Timing { /// | Tests | 250 ms – 2 s | dormancy within seconds keeps tests short | /// | 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 | - pub(crate) fn from_keepalive(keepalive: Duration) -> Self { - Self::new(keepalive, SYNC_REPLY_TIMEOUT) + /// + /// `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. - pub(crate) fn new(keepalive: Duration, sync_reply_timeout: Duration) -> Self { + pub(crate) fn new( + keepalive: Duration, + sync_reply_timeout: Duration, + delivery_limit: Duration, + ) -> Self { Self { keepalive, dormant_after: keepalive * 4, // dormant_after >= 4* keepalive to tolerate three lost PINGs in a row @@ -72,7 +77,7 @@ impl Timing { // Only the source gets these, and only while catching up. catch_up_probe: (keepalive / 30).clamp(Duration::from_secs(1), Duration::from_secs(5)), sync_reply_timeout, - delivery_limit: MYCELIUM_DELIVERY_LIMIT, + delivery_limit, } } -- cgit v1.3.1