aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 21:01:43 +0100
committertv <tv@krebsco.de>2026-11-01 21:01:43 +0100
commitee8ce39bf3901786d3767cf2d690ba1d73a369ae (patch)
tree237519074f84dacd54a979cbd780dfcf127d178b /src/transport
parent13b1061ee221a03168ba99f311e56d0896ef319b (diff)
introduce per-transport sync reply timeout
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/identity.rs4
-rw-r--r--src/transport/mod.rs7
-rw-r--r--src/transport/paths.rs10
-rw-r--r--src/transport/tor.rs8
-rw-r--r--src/transport/traffic.rs4
5 files changed, 33 insertions, 0 deletions
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<String> {
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<String> {
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<String> {
self.inner.local_addresses()
}