diff options
| author | tv <tv@krebsco.de> | 2026-10-28 03:43:37 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-28 03:43:37 +0100 |
| commit | ff6d98bdd5f921942eb2b37d313d3b9d18acee40 (patch) | |
| tree | ef98a1542aee821006ece373c1ece536cc0e9596 /src/transport | |
| parent | 5184885fcec433d636060e5a4e889fa78827dadc (diff) | |
get swarm RTT from paths
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/identity.rs | 6 | ||||
| -rw-r--r-- | src/transport/mod.rs | 7 | ||||
| -rw-r--r-- | src/transport/paths.rs | 5 | ||||
| -rw-r--r-- | src/transport/traffic.rs | 4 |
4 files changed, 22 insertions, 0 deletions
diff --git a/src/transport/identity.rs b/src/transport/identity.rs index 153dacc..0c4cda4 100644 --- a/src/transport/identity.rs +++ b/src/transport/identity.rs @@ -496,6 +496,12 @@ impl Transport for IdentityTransport { true } + /// The best path's, where messages to `peer` go. + fn rtt(&self, peer: &str) -> Option<Duration> { + let address = self.shared.proven_at(peer).into_iter().next()?; + self.shared.paths.rtt(&address) + } + /// The identity layer's, and each transport's. fn stats(&self) -> TransportStats { let mut stats = self.shared.paths.stats(); diff --git a/src/transport/mod.rs b/src/transport/mod.rs index f60a9f6..80b71cd 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -649,6 +649,13 @@ pub(crate) trait Transport: Send + Sync { None } + /// The smoothed round-trip time of the path messages to `peer` go over, if + /// measured (`transport::paths`). By default none. + fn rtt(&self, peer: &str) -> Option<std::time::Duration> { + let _ = peer; + None + } + /// Whether the transport answers PINGs with PONGs itself (the paths layer, /// `transport::paths`); if not (a bare transport, in tests), the node does. By /// default not. diff --git a/src/transport/paths.rs b/src/transport/paths.rs index 643a238..a9bac49 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -420,6 +420,11 @@ impl Paths { self.table.lock_or_recover().rank(usable, Instant::now()) } + /// The smoothed round-trip time of the path to `address`, if measured. + pub(crate) fn rtt(&self, address: &str) -> Option<Duration> { + self.table.lock_or_recover().paths.get(address)?.rtt + } + /// What paths knows about each of `addresses`. pub(crate) fn info(&self, addresses: &[String]) -> Vec<PathInfo> { let now = Instant::now(); diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index b070023..64595cb 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -192,6 +192,10 @@ impl Transport for CountingTransport { self.inner.answers_pings() } + fn rtt(&self, peer: &str) -> Option<std::time::Duration> { + self.inner.rtt(peer) + } + async fn resolve_seed(&self, seed: &str) -> Result<String> { self.inner.resolve_seed(seed).await } |
