Skip to content

Commit

Permalink
Make sure inject_dial_failure is called (#1549)
Browse files Browse the repository at this point in the history
* 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 80c0d3d.

* Bump versions and CHANGELOG

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

Co-authored-by: Toralf Wittner <tw@dtex.org>
  • Loading branch information
tomaka and twittner committed Apr 17, 2020
1 parent 77a34c0 commit 87b5efb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 28 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion swarm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libp2p-swarm"
edition = "2018"
description = "The libp2p swarm"
version = "0.18.0"
version = "0.18.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
54 changes: 29 additions & 25 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
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)
},
Expand All @@ -419,6 +425,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
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)
}
Expand All @@ -427,6 +439,7 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
Ok(false)
},
Peer::Local => {
me.behaviour.inject_dial_failure(&peer_id);
Err(ConnectionLimit { current: 0, limit: 0 })
}
}
Expand Down Expand Up @@ -701,34 +714,25 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
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);
}
}
}
Expand Down

0 comments on commit 87b5efb

Please sign in to comment.