From 9edf5e5d56596458c9f8faf289cc5328aef08226 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 21:01:43 +0100 Subject: introduce per-transport sync reply timeout --- src/transport/identity.rs | 4 ++++ src/transport/mod.rs | 7 +++++++ src/transport/paths.rs | 10 ++++++++++ src/transport/tor.rs | 8 ++++++++ src/transport/traffic.rs | 4 ++++ 5 files changed, 33 insertions(+) (limited to 'src/transport') diff --git a/src/transport/identity.rs b/src/transport/identity.rs index 8ef0535..7b4a8c7 100644 --- a/src/transport/identity.rs +++ b/src/transport/identity.rs @@ -495,6 +495,10 @@ impl Transport for IdentityTransport { self.shared.paths.delivery_limit() } + fn sync_reply_timeout(&self) -> Duration { + self.shared.paths.sync_reply_timeout() + } + fn local_addresses(&self) -> Vec { self.shared.paths.local_addresses() } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index a802269..1de0633 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -768,6 +768,13 @@ pub(crate) trait Transport: Send + Sync { /// a message sent is delivered or lost for good. fn delivery_limit(&self) -> std::time::Duration; + /// The first wait for an answer to a sync message (`Timing::sync_reply_timeout`): by + /// default `SYNC_REPLY_TIMEOUT`, longer on a transport whose round trips take + /// seconds. + fn sync_reply_timeout(&self) -> std::time::Duration { + crate::state::SYNC_REPLY_TIMEOUT + } + /// Where this node can be reached, as addresses other nodes can use: published in /// the member list (`swarm::members`). By default its identity, for a transport /// whose identities are addresses (Mycelium: a public key). diff --git a/src/transport/paths.rs b/src/transport/paths.rs index 8bb8533..1f88e0a 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -644,6 +644,16 @@ impl Paths { .unwrap_or_default() } + /// The longest of the transports' (`Transport::sync_reply_timeout`): an answer may + /// come over any of them. + pub(crate) fn sync_reply_timeout(&self) -> Duration { + self.links + .iter() + .map(|link| link.inner.sync_reply_timeout()) + .max() + .unwrap_or(crate::state::SYNC_REPLY_TIMEOUT) + } + /// Each transport's (`Transport::local_addresses`), with its scheme: taken in turns, /// each transport's first in the configured order, then each one's second, and so on, /// so a list cut short (`members::MAX_ADDRESSES`) still has every transport's best. diff --git a/src/transport/tor.rs b/src/transport/tor.rs index 26dab14..7ecd624 100644 --- a/src/transport/tor.rs +++ b/src/transport/tor.rs @@ -76,6 +76,8 @@ const CONNECT_TIMEOUT: Duration = Duration::from_secs(60); const HANDSHAKE_TIMEOUT: Duration = Duration::from_secs(30); /// How long a message may take, before what its size adds (`stream_timeout`). const STREAM_TIMEOUT: Duration = Duration::from_secs(30); +/// The first wait for an answer to a sync message (`Transport::sync_reply_timeout`). +const SYNC_REPLY_TIMEOUT: Duration = Duration::from_secs(30); /// The slowest a message is expected to go over Tor, in bytes per second. const MIN_RATE: u64 = 64 << 10; /// Messages read and not handled yet, at most. @@ -569,6 +571,12 @@ impl Transport for TorTransport { stream_timeout(MAX_MESSAGE) } + /// Round trips over Tor take a second or more, and the first message to a peer + /// waits for a connection (`CONNECT_TIMEOUT`, `HANDSHAKE_TIMEOUT`). + fn sync_reply_timeout(&self) -> Duration { + SYNC_REPLY_TIMEOUT + } + fn local_addresses(&self) -> Vec { vec![self.shared.local_id.clone()] } diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index 6385f2e..2e45a31 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -306,6 +306,10 @@ impl Transport for CountingTransport { self.inner.delivery_limit() } + fn sync_reply_timeout(&self) -> std::time::Duration { + self.inner.sync_reply_timeout() + } + fn local_addresses(&self) -> Vec { self.inner.local_addresses() } -- cgit v1.3.1