From ff6d98bdd5f921942eb2b37d313d3b9d18acee40 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 28 Oct 2026 03:43:37 +0100 Subject: get swarm RTT from paths --- src/transport/identity.rs | 6 ++++++ src/transport/mod.rs | 7 +++++++ src/transport/paths.rs | 5 +++++ src/transport/traffic.rs | 4 ++++ 4 files changed, 22 insertions(+) (limited to 'src/transport') 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 { + 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 { + 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 { + self.table.lock_or_recover().paths.get(address)?.rtt + } + /// What paths knows about each of `addresses`. pub(crate) fn info(&self, addresses: &[String]) -> Vec { 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 { + self.inner.rtt(peer) + } + async fn resolve_seed(&self, seed: &str) -> Result { self.inner.resolve_seed(seed).await } -- cgit v1.3.1