Skip to content

Commit

Permalink
Fix incoming dial failure handling for connection pool behavior
Browse files Browse the repository at this point in the history
Fix incoming dial failure handling for connection pool behaviour.
Since the recent update of libp2p, [this
change](libp2p/rust-libp2p#2191) introduces
state to dial request that can be transmitted in
`inject_dial_failure`. So there are a couple of cases where the
function is called but we can ignore the error since the connection
is still to be completed or is already connected.
  • Loading branch information
jsdanielh committed Nov 22, 2021
1 parent 32b92d2 commit 9a55f24
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions network-libp2p/src/connection_pool/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,15 +598,35 @@ impl NetworkBehaviour for ConnectionPoolBehaviour {
_handler: Self::ProtocolsHandler,
error: &DialError,
) {
let peer_id = match peer_id {
Some(id) => id,
// Not interested in dial failures to unknown peers right now.
None => return,
};

log::debug!("Failed to dial peer {}: {:?}", peer_id, error);
self.peer_ids.mark_failed(peer_id);
self.maintain_peers();
match error {
DialError::Banned
| DialError::ConnectionLimit(_)
| DialError::LocalPeerId
| DialError::InvalidPeerId
| DialError::Aborted
| DialError::ConnectionIo(_)
| DialError::Transport(_)
| DialError::NoAddresses => {
let peer_id = match peer_id {
Some(id) => id,
// Not interested in dial failures to unknown peers right now.
None => return,
};

log::debug!("Failed to dial peer {}: {:?}", peer_id, error);
self.peer_ids.mark_failed(peer_id);
self.maintain_peers();
}
DialError::DialPeerConditionFalse(
DialPeerCondition::Disconnected | DialPeerCondition::NotDialing,
) => {
// We might (still) be connected, or about to be connected, thus do not report the
// failure.
}
DialError::DialPeerConditionFalse(DialPeerCondition::Always) => {
unreachable!("DialPeerCondition::Always can not trigger DialPeerConditionFalse.");
}
}
}

fn poll(
Expand Down

0 comments on commit 9a55f24

Please sign in to comment.