From be58ebd7dc5b7e1665e4d058b03248f9035d13a6 Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 28 Oct 2026 06:35:27 +0100 Subject: show peer destination path address in canonical form --- docs/openapi.yaml | 7 +------ src/transport/libp2p.rs | 8 +++++++- src/transport/mod.rs | 5 +++-- src/transport/paths.rs | 20 ++++++++++---------- src/transport/stats.rs | 10 ++++------ 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/openapi.yaml b/docs/openapi.yaml index b3496f8..b4c9c19 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1153,10 +1153,7 @@ components: properties: address: type: string - description: '`:`: a libp2p peer ID, a Mycelium public key, an onion service (`.onion:`).' - location: - type: [string, 'null'] - description: Where the path goes now, where the address doesn't say (libp2p, the remote address of its connection). Null for Mycelium and Tor (the address is where it goes), or with no connection. + description: 'Where the path goes now, `:`: for libp2p the remote address of its connection, ending in the peer ID (just the peer ID without one); a Mycelium public key; an onion service (`.onion:`).' rttMs: type: [number, 'null'] description: Smoothed round-trip time of its PINGs (the keepalive's, and the paths layer's own); null before an answer. @@ -1461,8 +1458,6 @@ components: properties: address: type: string - location: - type: [string, 'null'] rttMs: type: [number, 'null'] down: diff --git a/src/transport/libp2p.rs b/src/transport/libp2p.rs index 995d074..58fbf64 100644 --- a/src/transport/libp2p.rs +++ b/src/transport/libp2p.rs @@ -1318,7 +1318,13 @@ impl Transport for Libp2pTransport { fn location(&self, target: &str) -> Option { let peer = PeerId::from_str(target).ok()?; - lock(&self.book).location(&peer).map(Multiaddr::to_string) + let address = lock(&self.book).location(&peer)?.clone(); + Some( + address + .with_p2p(peer) + .unwrap_or_else(|address| address) + .to_string(), + ) } fn stats(&self) -> TransportStats { diff --git a/src/transport/mod.rs b/src/transport/mod.rs index c70d27f..25ad56d 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -669,8 +669,9 @@ pub(crate) trait Transport: Send + Sync { None } - /// Where messages to `target` (a transport identity) go now: the remote address of - /// the connection in use, say. By default nowhere but `target` itself (Mycelium). + /// Where messages to `target` (a transport identity) go now, as an address that + /// names `target` too: the remote address of the connection in use, say. By default + /// nowhere but `target` itself (Mycelium). fn location(&self, target: &str) -> Option { let _ = target; None diff --git a/src/transport/paths.rs b/src/transport/paths.rs index 1f6d078..ba16794 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -334,7 +334,6 @@ impl Table { let path = self.paths.get(address); PathInfo { address: address.to_owned(), - location: None, rtt_ms: path .and_then(|path| path.rtt) .map(|rtt| rtt.as_secs_f64() * 1000.0), @@ -450,13 +449,16 @@ impl Paths { self.located(infos) } - /// `infos` with where each path goes (`Transport::location`); asked outside the - /// table's lock. + /// `infos` with where each path goes, where the transport knows + /// (`Transport::location`); asked outside the table's lock. fn located(&self, mut infos: Vec) -> Vec { for info in &mut infos { - info.location = self + if let Some((link, location)) = self .split(&info.address) - .and_then(|(link, target)| link.inner.location(&target)); + .and_then(|(link, target)| Some((link, link.inner.location(&target)?))) + { + info.address = link.address(&location); + } } infos } @@ -658,7 +660,7 @@ impl Paths { stats.merge(link.inner.stats()); } let now = Instant::now(); - let (mut paths, counts) = { + let (paths, counts) = { let table = self.table.lock_or_recover(); let paths: Vec = table .paths @@ -667,11 +669,9 @@ impl Paths { .collect(); (paths, table.counts) }; + let mut paths = self.located(paths); paths.sort_by(|a, b| a.address.cmp(&b.address)); - stats.paths = Some(PathsStats { - paths: self.located(paths), - counts, - }); + stats.paths = Some(PathsStats { paths, counts }); stats } diff --git a/src/transport/stats.rs b/src/transport/stats.rs index 8b456cc..398ffdf 100644 --- a/src/transport/stats.rs +++ b/src/transport/stats.rs @@ -47,13 +47,11 @@ pub(crate) struct PathsStats { #[derive(Debug, Clone, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub(crate) struct PathInfo { - /// `:`: whom the path goes to, as the transport knows it - /// (a libp2p peer ID, a Mycelium public key, an onion service). + /// `:`: where the transport says the path goes now + /// (`Transport::location`; libp2p: the remote address of its connection, ending in + /// the peer ID), else whom it goes to, `:` (a libp2p + /// peer ID without a connection, a Mycelium public key, an onion service). pub(crate) address: String, - /// Where the path goes now (`Transport::location`): for libp2p, the remote address of - /// its connection. Absent where the address says it all (Mycelium, Tor), or with no - /// connection. - pub(crate) location: Option, /// Smoothed round-trip time of its PINGs (ours, and our keepalives); absent before /// an answer. pub(crate) rtt_ms: Option, -- cgit v1.3.1