aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/libp2p/relays.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 05:00:43 +0100
committertv <tv@krebsco.de>2026-11-01 05:00:43 +0100
commit67a476525bf23fec7aa10a962668cc77cce6c685 (patch)
treea259ef08154e1bc11efee95b22d3f615f564538b /src/transport/libp2p/relays.rs
parentc08574fac02c781b615969943e3d0d95ee402537 (diff)
libp2p: dial newly announced peer addresses
Diffstat (limited to 'src/transport/libp2p/relays.rs')
-rw-r--r--src/transport/libp2p/relays.rs23
1 files changed, 23 insertions, 0 deletions
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<Behaviour>, book: &Mutex<Book>, 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.