Swarm::dial adds addresses when pending (#919)

* Swarm::dial adds addresses when pending

* Bump libp2p-core to 0.3.3
This commit is contained in:
Pierre Krieger
2019-02-05 17:29:30 +01:00
committed by GitHub
parent 479924f8dc
commit 909f50f989
3 changed files with 20 additions and 5 deletions

View File

@ -2,7 +2,7 @@
name = "libp2p-core"
edition = "2018"
description = "Core traits and structs of libp2p"
version = "0.3.2"
version = "0.3.3"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -1613,6 +1613,15 @@ where
self.attempt.get().next_attempts.iter()
}
/// Adds new multiaddrs to attempt if the current dialing fails.
///
/// Doesn't do anything for multiaddresses that are already in the queue.
pub fn append_multiaddr_attempts(&mut self, addrs: impl IntoIterator<Item = Multiaddr>) {
for addr in addrs {
self.append_multiaddr_attempt(addr);
}
}
/// Adds a new multiaddr to attempt if the current dialing fails.
///
/// Doesn't do anything if that multiaddress is already in the queue.

View File

@ -47,7 +47,7 @@ use crate::{
nodes::{
handled_node::NodeHandler,
node::Substream,
raw_swarm::{RawSwarm, RawSwarmEvent}
raw_swarm::{self, RawSwarm, RawSwarmEvent}
},
protocols_handler::{NodeHandlerWrapperBuilder, NodeHandlerWrapper, IntoProtocolsHandler, ProtocolsHandler},
transport::TransportError,
@ -180,9 +180,15 @@ where TBehaviour: NetworkBehaviour,
#[inline]
pub fn dial(me: &mut Self, peer_id: PeerId) {
let addrs = me.behaviour.addresses_of_peer(&peer_id);
match me.raw_swarm.peer(peer_id.clone()) {
raw_swarm::Peer::NotConnected(peer) => {
let handler = me.behaviour.new_handler().into_node_handler_builder();
if let Some(peer) = me.raw_swarm.peer(peer_id).into_not_connected() {
let _ = peer.connect_iter(addrs, handler);
},
raw_swarm::Peer::PendingConnect(mut peer) => {
peer.append_multiaddr_attempts(addrs)
},
raw_swarm::Peer::Connected(_) | raw_swarm::Peer::LocalNode => {}
}
}