diff --git a/core/Cargo.toml b/core/Cargo.toml index 77dd01bc..438cbec8 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -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 "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/src/nodes/raw_swarm.rs b/core/src/nodes/raw_swarm.rs index 5c3e5283..42221d0a 100644 --- a/core/src/nodes/raw_swarm.rs +++ b/core/src/nodes/raw_swarm.rs @@ -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) { + 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. diff --git a/core/src/swarm.rs b/core/src/swarm.rs index 4c12b1fd..adb36385 100644 --- a/core/src/swarm.rs +++ b/core/src/swarm.rs @@ -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); - 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); + match me.raw_swarm.peer(peer_id.clone()) { + raw_swarm::Peer::NotConnected(peer) => { + let handler = me.behaviour.new_handler().into_node_handler_builder(); + 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 => {} } }