From 87b5efb3e8394b7609d894954b9af6cf4d49798b Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 17 Apr 2020 18:13:16 +0200 Subject: [PATCH] Make sure inject_dial_failure is called (#1549) * Make sure inject_dial_failure is called * Update CHANGELOG * Make libp2p-kad tests pass * Fix again * Update swarm/src/lib.rs Co-Authored-By: Toralf Wittner * Revert "Fix again" This reverts commit 80c0d3d908aff282d492f213d2ce34d12489167d. * Bump versions and CHANGELOG * Oops, didn't bump libp2p-swarm in libp2p Co-authored-by: Toralf Wittner --- CHANGELOG.md | 5 +++++ Cargo.toml | 4 ++-- swarm/Cargo.toml | 2 +- swarm/src/lib.rs | 54 ++++++++++++++++++++++++++---------------------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fc8577b..94790dae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Version ??? +# Version 0.18.1 (2020-04-17) + +- `libp2p-swarm`: Make sure inject_dial_failure is called in all situations. + [PR 1549](https://github.com/libp2p/rust-libp2p/pull/1549) + # Version 0.18.0 (2020-04-09) - `libp2p-core`: Treat connection limit errors as pending connection errors. diff --git a/Cargo.toml b/Cargo.toml index 9f34ae20..c00945dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p" edition = "2018" description = "Peer-to-peer networking library" -version = "0.18.0" +version = "0.18.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -68,7 +68,7 @@ libp2p-pnet = { version = "0.18.0", path = "protocols/pnet", optional = true } libp2p-core = { version = "0.18.0", path = "core" } libp2p-core-derive = { version = "0.18.0", path = "misc/core-derive" } libp2p-secio = { version = "0.18.0", path = "protocols/secio", default-features = false, optional = true } -libp2p-swarm = { version = "0.18.0", path = "swarm" } +libp2p-swarm = { version = "0.18.1", path = "swarm" } libp2p-uds = { version = "0.18.0", path = "transports/uds", optional = true } libp2p-wasm-ext = { version = "0.18.0", path = "transports/wasm-ext", optional = true } libp2p-yamux = { version = "0.18.0", path = "muxers/yamux", optional = true } diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 27994090..7feaa30a 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -2,7 +2,7 @@ name = "libp2p-swarm" edition = "2018" description = "The libp2p swarm" -version = "0.18.0" +version = "0.18.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 11bb1a05..1c62d8d9 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -403,6 +403,12 @@ where TBehaviour: NetworkBehaviour, return Err(error) } } + } else { + log::debug!( + "New dialing attempt to disconnected peer {:?} failed: no address.", + peer_id + ); + me.behaviour.inject_dial_failure(&peer_id); } Ok(false) }, @@ -419,6 +425,12 @@ where TBehaviour: NetworkBehaviour, return Err(error) } } + } else { + log::debug!( + "New dialing attempt to disconnected peer {:?} failed: no address.", + peer_id + ); + me.behaviour.inject_dial_failure(&peer_id); } Ok(false) } @@ -427,6 +439,7 @@ where TBehaviour: NetworkBehaviour, Ok(false) }, Peer::Local => { + me.behaviour.inject_dial_failure(&peer_id); Err(ConnectionLimit { current: 0, limit: 0 }) } } @@ -701,34 +714,25 @@ where TBehaviour: NetworkBehaviour, if this.banned_peers.contains(&peer_id) { this.behaviour.inject_dial_failure(&peer_id); } else { - let result = match condition { + let condition_matched = match condition { DialPeerCondition::Disconnected - if this.network.is_disconnected(&peer_id) => - { - ExpandedSwarm::dial(this, &peer_id) - } + if this.network.is_disconnected(&peer_id) => true, DialPeerCondition::NotDialing - if !this.network.is_dialing(&peer_id) => - { - ExpandedSwarm::dial(this, &peer_id) - } - _ => { - log::trace!("Condition for new dialing attempt to {:?} not met: {:?}", - peer_id, condition); - if let Some(mut peer) = this.network.peer(peer_id.clone()).into_dialing() { - let addrs = this.behaviour.addresses_of_peer(peer.id()); - peer.connection().add_addresses(addrs); - } - Ok(false) - } + if !this.network.is_dialing(&peer_id) => true, + _ => false }; - match result { - Ok(false) => {}, - Ok(true) => return Poll::Ready(SwarmEvent::Dialing(peer_id)), - Err(err) => { - log::debug!("Initiating dialing attempt to {:?} failed: {:?}", - &peer_id, err); - this.behaviour.inject_dial_failure(&peer_id); + + if condition_matched { + if let Ok(true) = ExpandedSwarm::dial(this, &peer_id) { + return Poll::Ready(SwarmEvent::Dialing(peer_id)); + } + + } else { + log::trace!("Condition for new dialing attempt to {:?} not met: {:?}", + peer_id, condition); + if let Some(mut peer) = this.network.peer(peer_id.clone()).into_dialing() { + let addrs = this.behaviour.addresses_of_peer(peer.id()); + peer.connection().add_addresses(addrs); } } }