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 <tw@dtex.org>

* Revert "Fix again"

This reverts commit 80c0d3d908aff282d492f213d2ce34d12489167d.

* Bump versions and CHANGELOG

* Oops, didn't bump libp2p-swarm in libp2p

Co-authored-by: Toralf Wittner <tw@dtex.org>
This commit is contained in:
Pierre Krieger 2020-04-17 18:13:16 +02:00 committed by GitHub
parent 77a34c0a0d
commit 87b5efb3e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 28 deletions

View File

@ -1,6 +1,11 @@
# Version ??? # 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) # Version 0.18.0 (2020-04-09)
- `libp2p-core`: Treat connection limit errors as pending connection errors. - `libp2p-core`: Treat connection limit errors as pending connection errors.

View File

@ -2,7 +2,7 @@
name = "libp2p" name = "libp2p"
edition = "2018" edition = "2018"
description = "Peer-to-peer networking library" description = "Peer-to-peer networking library"
version = "0.18.0" version = "0.18.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT" license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p" 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 = { version = "0.18.0", path = "core" }
libp2p-core-derive = { version = "0.18.0", path = "misc/core-derive" } 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-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-uds = { version = "0.18.0", path = "transports/uds", optional = true }
libp2p-wasm-ext = { version = "0.18.0", path = "transports/wasm-ext", 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 } libp2p-yamux = { version = "0.18.0", path = "muxers/yamux", optional = true }

View File

@ -2,7 +2,7 @@
name = "libp2p-swarm" name = "libp2p-swarm"
edition = "2018" edition = "2018"
description = "The libp2p swarm" description = "The libp2p swarm"
version = "0.18.0" version = "0.18.1"
authors = ["Parity Technologies <admin@parity.io>"] authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT" license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p" repository = "https://github.com/libp2p/rust-libp2p"

View File

@ -403,6 +403,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
return Err(error) 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) Ok(false)
}, },
@ -419,6 +425,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
return Err(error) 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) Ok(false)
} }
@ -427,6 +439,7 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
Ok(false) Ok(false)
}, },
Peer::Local => { Peer::Local => {
me.behaviour.inject_dial_failure(&peer_id);
Err(ConnectionLimit { current: 0, limit: 0 }) Err(ConnectionLimit { current: 0, limit: 0 })
} }
} }
@ -701,34 +714,25 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
if this.banned_peers.contains(&peer_id) { if this.banned_peers.contains(&peer_id) {
this.behaviour.inject_dial_failure(&peer_id); this.behaviour.inject_dial_failure(&peer_id);
} else { } else {
let result = match condition { let condition_matched = match condition {
DialPeerCondition::Disconnected DialPeerCondition::Disconnected
if this.network.is_disconnected(&peer_id) => if this.network.is_disconnected(&peer_id) => true,
{
ExpandedSwarm::dial(this, &peer_id)
}
DialPeerCondition::NotDialing DialPeerCondition::NotDialing
if !this.network.is_dialing(&peer_id) => if !this.network.is_dialing(&peer_id) => true,
{ _ => false
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)
}
}; };
match result {
Ok(false) => {}, if condition_matched {
Ok(true) => return Poll::Ready(SwarmEvent::Dialing(peer_id)), if let Ok(true) = ExpandedSwarm::dial(this, &peer_id) {
Err(err) => { return Poll::Ready(SwarmEvent::Dialing(peer_id));
log::debug!("Initiating dialing attempt to {:?} failed: {:?}", }
&peer_id, err);
this.behaviour.inject_dial_failure(&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);
} }
} }
} }