From f55d314185254a9417b1691aec841a91ecfdbce7 Mon Sep 17 00:00:00 2001 From: David Craven Date: Sat, 18 Jul 2020 20:26:22 +0200 Subject: [PATCH] Dial using first listening address. --- swarm/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index fbf3bfe805d9..70c7ddfdde9a 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -371,7 +371,8 @@ where TBehaviour: NetworkBehaviour, /// Returns an error if the address is not supported. pub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), ConnectionLimit> { let handler = me.behaviour.new_handler(); - me.network.dial(&addr, handler.into_node_handler_builder()).map(|_id| ()) + let local_addr = &me.listened_addrs[0]; + me.network.dial(local_addr, &addr, handler.into_node_handler_builder()).map(|_id| ()) } /// Tries to initiate a dialing attempt to the given peer. @@ -386,12 +387,13 @@ where TBehaviour: NetworkBehaviour, let mut addrs = me.behaviour.addresses_of_peer(peer_id) .into_iter() .filter(|a| !self_listening.contains(a)); + let local_addr = &me.listened_addrs[0]; let result = if let Some(first) = addrs.next() { let handler = me.behaviour.new_handler().into_node_handler_builder(); me.network.peer(peer_id.clone()) - .dial(first, addrs, handler) + .dial(local_addr.clone(), first, addrs, handler) .map(|_| ()) .map_err(DialError::ConnectionLimit) } else {