Skip to content

Commit 87b5efb

Browse files
tomakatwittner
andauthored
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 <[email protected]> * Revert "Fix again" This reverts commit 80c0d3d. * Bump versions and CHANGELOG * Oops, didn't bump libp2p-swarm in libp2p Co-authored-by: Toralf Wittner <[email protected]>
1 parent 77a34c0 commit 87b5efb

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Version ???
22

33

4+
# Version 0.18.1 (2020-04-17)
5+
6+
- `libp2p-swarm`: Make sure inject_dial_failure is called in all situations.
7+
[PR 1549](https://github.com/libp2p/rust-libp2p/pull/1549)
8+
49
# Version 0.18.0 (2020-04-09)
510

611
- `libp2p-core`: Treat connection limit errors as pending connection errors.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p"
33
edition = "2018"
44
description = "Peer-to-peer networking library"
5-
version = "0.18.0"
5+
version = "0.18.1"
66
authors = ["Parity Technologies <[email protected]>"]
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"
@@ -68,7 +68,7 @@ libp2p-pnet = { version = "0.18.0", path = "protocols/pnet", optional = true }
6868
libp2p-core = { version = "0.18.0", path = "core" }
6969
libp2p-core-derive = { version = "0.18.0", path = "misc/core-derive" }
7070
libp2p-secio = { version = "0.18.0", path = "protocols/secio", default-features = false, optional = true }
71-
libp2p-swarm = { version = "0.18.0", path = "swarm" }
71+
libp2p-swarm = { version = "0.18.1", path = "swarm" }
7272
libp2p-uds = { version = "0.18.0", path = "transports/uds", optional = true }
7373
libp2p-wasm-ext = { version = "0.18.0", path = "transports/wasm-ext", optional = true }
7474
libp2p-yamux = { version = "0.18.0", path = "muxers/yamux", optional = true }

swarm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "libp2p-swarm"
33
edition = "2018"
44
description = "The libp2p swarm"
5-
version = "0.18.0"
5+
version = "0.18.1"
66
authors = ["Parity Technologies <[email protected]>"]
77
license = "MIT"
88
repository = "https://github.com/libp2p/rust-libp2p"

swarm/src/lib.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
403403
return Err(error)
404404
}
405405
}
406+
} else {
407+
log::debug!(
408+
"New dialing attempt to disconnected peer {:?} failed: no address.",
409+
peer_id
410+
);
411+
me.behaviour.inject_dial_failure(&peer_id);
406412
}
407413
Ok(false)
408414
},
@@ -419,6 +425,12 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
419425
return Err(error)
420426
}
421427
}
428+
} else {
429+
log::debug!(
430+
"New dialing attempt to disconnected peer {:?} failed: no address.",
431+
peer_id
432+
);
433+
me.behaviour.inject_dial_failure(&peer_id);
422434
}
423435
Ok(false)
424436
}
@@ -427,6 +439,7 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
427439
Ok(false)
428440
},
429441
Peer::Local => {
442+
me.behaviour.inject_dial_failure(&peer_id);
430443
Err(ConnectionLimit { current: 0, limit: 0 })
431444
}
432445
}
@@ -701,34 +714,25 @@ where TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
701714
if this.banned_peers.contains(&peer_id) {
702715
this.behaviour.inject_dial_failure(&peer_id);
703716
} else {
704-
let result = match condition {
717+
let condition_matched = match condition {
705718
DialPeerCondition::Disconnected
706-
if this.network.is_disconnected(&peer_id) =>
707-
{
708-
ExpandedSwarm::dial(this, &peer_id)
709-
}
719+
if this.network.is_disconnected(&peer_id) => true,
710720
DialPeerCondition::NotDialing
711-
if !this.network.is_dialing(&peer_id) =>
712-
{
713-
ExpandedSwarm::dial(this, &peer_id)
714-
}
715-
_ => {
716-
log::trace!("Condition for new dialing attempt to {:?} not met: {:?}",
717-
peer_id, condition);
718-
if let Some(mut peer) = this.network.peer(peer_id.clone()).into_dialing() {
719-
let addrs = this.behaviour.addresses_of_peer(peer.id());
720-
peer.connection().add_addresses(addrs);
721-
}
722-
Ok(false)
723-
}
721+
if !this.network.is_dialing(&peer_id) => true,
722+
_ => false
724723
};
725-
match result {
726-
Ok(false) => {},
727-
Ok(true) => return Poll::Ready(SwarmEvent::Dialing(peer_id)),
728-
Err(err) => {
729-
log::debug!("Initiating dialing attempt to {:?} failed: {:?}",
730-
&peer_id, err);
731-
this.behaviour.inject_dial_failure(&peer_id);
724+
725+
if condition_matched {
726+
if let Ok(true) = ExpandedSwarm::dial(this, &peer_id) {
727+
return Poll::Ready(SwarmEvent::Dialing(peer_id));
728+
}
729+
730+
} else {
731+
log::trace!("Condition for new dialing attempt to {:?} not met: {:?}",
732+
peer_id, condition);
733+
if let Some(mut peer) = this.network.peer(peer_id.clone()).into_dialing() {
734+
let addrs = this.behaviour.addresses_of_peer(peer.id());
735+
peer.connection().add_addresses(addrs);
732736
}
733737
}
734738
}

0 commit comments

Comments
 (0)