From 2ec7d7e0eedf504035417bebcace68f22f38ba10 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 13:20:08 +0100 Subject: libp2p: revise published address count/selection --- src/transport/paths.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/transport/paths.rs') 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 { - self.links + let mut each: Vec> = self + .links .iter() - .flat_map(|link| { + .map(|link| { link.inner .local_addresses() .into_iter() .map(|target| link.address(&target)) + .collect::>() + .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. -- cgit v1.3.1