diff options
| author | tv <tv@krebsco.de> | 2026-10-28 06:01:40 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-28 06:01:40 +0100 |
| commit | fe4c11424d0ad8b155fe1b45c95b5b472a536b8e (patch) | |
| tree | 5b6e778e9ab7ad407f6529d9adbe6b28cdbaea7a /src/transport/paths.rs | |
| parent | de75b63c44235fab3547ac2e060e610bff94646a (diff) | |
add location info to paths
Diffstat (limited to 'src/transport/paths.rs')
| -rw-r--r-- | src/transport/paths.rs | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/transport/paths.rs b/src/transport/paths.rs index 6696e1a..1f6d078 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -334,6 +334,7 @@ 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), @@ -439,11 +440,25 @@ impl Paths { /// What paths knows about each of `addresses`. pub(crate) fn info(&self, addresses: &[String]) -> Vec<PathInfo> { let now = Instant::now(); - let table = self.table.lock_or_recover(); - addresses - .iter() - .map(|address| table.info(address, now)) - .collect() + let infos = { + let table = self.table.lock_or_recover(); + addresses + .iter() + .map(|address| table.info(address, now)) + .collect() + }; + self.located(infos) + } + + /// `infos` with where each path goes (`Transport::location`); asked outside the + /// table's lock. + fn located(&self, mut infos: Vec<PathInfo>) -> Vec<PathInfo> { + for info in &mut infos { + info.location = self + .split(&info.address) + .and_then(|(link, target)| link.inner.location(&target)); + } + infos } /// Whether `address` is one of ours. @@ -643,16 +658,19 @@ impl Paths { stats.merge(link.inner.stats()); } let now = Instant::now(); - let table = self.table.lock_or_recover(); - let mut paths: Vec<PathInfo> = table - .paths - .keys() - .map(|address| table.info(address, now)) - .collect(); + let (mut paths, counts) = { + let table = self.table.lock_or_recover(); + let paths: Vec<PathInfo> = table + .paths + .keys() + .map(|address| table.info(address, now)) + .collect(); + (paths, table.counts) + }; paths.sort_by(|a, b| a.address.cmp(&b.address)); stats.paths = Some(PathsStats { - paths, - counts: table.counts, + paths: self.located(paths), + counts, }); stats } |
