Skip to content

Commit

Permalink
Dial using first listening address.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch committed Jul 18, 2020
1 parent 8398e02 commit f55d314
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
/// 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.
Expand All @@ -386,12 +387,13 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
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 {
Expand Down

0 comments on commit f55d314

Please sign in to comment.