diff options
| author | tv <tv@krebsco.de> | 2026-11-01 13:20:08 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 13:20:08 +0100 |
| commit | 7348524430ab2af7ccdcf38bfe76461b476337a5 (patch) | |
| tree | cbf45f6f50d37c8ade4ca4f74382ecdae7c6cc9b /src/transport/paths.rs | |
| parent | 7a5a7408179c5fe9943bd2ce60295e86f1afaa40 (diff) | |
libp2p: revise published address count/selection
Diffstat (limited to 'src/transport/paths.rs')
| -rw-r--r-- | src/transport/paths.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/transport/paths.rs b/src/transport/paths.rs index 658f681..ce19fd4 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -620,17 +620,30 @@ impl Paths { .unwrap_or_default() } - /// Each transport's (`Transport::local_addresses`), with its scheme. + /// 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. pub(crate) fn local_addresses(&self) -> Vec<String> { - self.links + let mut each: Vec<std::vec::IntoIter<String>> = self + .links .iter() - .flat_map(|link| { + .map(|link| { link.inner .local_addresses() .into_iter() .map(|target| link.address(&target)) + .collect::<Vec<_>>() + .into_iter() }) - .collect() + .collect(); + let mut addresses = Vec::new(); + loop { + let before = addresses.len(); + addresses.extend(each.iter_mut().filter_map(Iterator::next)); + if addresses.len() == before { + return addresses; + } + } } /// The schemes of the transports, in order of preference. |
