From 9a55f2484ad4d223960ffe6772954983cf12fb88 Mon Sep 17 00:00:00 2001 From: Jose Daniel Hernandez Date: Sun, 21 Nov 2021 11:03:27 -0600 Subject: [PATCH] Fix incoming dial failure handling for connection pool behavior Fix incoming dial failure handling for connection pool behaviour. Since the recent update of libp2p, [this change](https://github.com/libp2p/rust-libp2p/pull/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. --- .../src/connection_pool/behaviour.rs | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/network-libp2p/src/connection_pool/behaviour.rs b/network-libp2p/src/connection_pool/behaviour.rs index 8f45e5cc31..0f3cbd65d5 100644 --- a/network-libp2p/src/connection_pool/behaviour.rs +++ b/network-libp2p/src/connection_pool/behaviour.rs @@ -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(