From ab6a83c5c666dfc8603f0eae1537c30f7ee61ee1 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 05:00:43 +0100 Subject: libp2p: dial newly announced peer addresses --- src/transport/libp2p/relays.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/transport/libp2p/relays.rs') diff --git a/src/transport/libp2p/relays.rs b/src/transport/libp2p/relays.rs index dca031c..41d7e1d 100644 --- a/src/transport/libp2p/relays.rs +++ b/src/transport/libp2p/relays.rs @@ -175,6 +175,29 @@ pub(super) fn upgrade( } } +/// Dials `peer`, connected directly, at its other addresses, in case one is a better +/// path: one that came since (a new interface of its, identify tells), or, `again` +/// (one of ours came), every one, as our side may reach them better now, the one in +/// use too. Each once while connected (`Book::explored`); a connection that opens is +/// pinged at once, and of several the fastest is kept (`Book::duplicates`). Without +/// it, a connection stays on the path it was made on (the WLAN) when a better one comes +/// (ethernet): a connected peer isn't dialled again. +pub(super) fn explore(swarm: &mut Swarm, book: &Mutex, peer: PeerId, again: bool) { + let candidates = lock(book).to_explore(peer, again); + if candidates.is_empty() { + return; + } + debug!(peer = %Addressed(SCHEME, &peer), addresses = ?candidates, "Connected directly; dialling other addresses, for a better path"); + if let Err(error) = swarm.dial( + DialOpts::peer_id(peer) + .addresses(candidates) + .condition(PeerCondition::Always) + .build(), + ) { + debug!(peer = %Addressed(SCHEME, &peer), error = %error, "Couldn't dial for a better path"); + } +} + /// Tries hole punching again with the peers it failed with that are due (`punching`). /// libp2p punches as a relayed connection opens, started by the side that was dialled /// through the relay; that side is where a punch's failure is told, so it is this one. -- cgit v1.3.1