diff --git a/network-p2p/peerset/src/lib.rs b/network-p2p/peerset/src/lib.rs index e69a75d78e..d51a27f842 100644 --- a/network-p2p/peerset/src/lib.rs +++ b/network-p2p/peerset/src/lib.rs @@ -520,9 +520,6 @@ impl Peerset { let before = peer_reputation.reputation(); let after = reput_tick(before); trace!(target: "peerset", "Fleeting {}: {} -> {}", peer_id, before, after); - if after < BANNED_THRESHOLD { - self.message_queue.push_back(Message::Banned(peer_id)) - } peer_reputation.set_reputation(after); drop(peer_reputation); // If the peer has no connection to it, @@ -533,6 +530,9 @@ impl Peerset { peersstate::Peer::NotConnected(peer) => { if peer.last_connected_or_discovered() + FORGET_AFTER < now { peer.forget_peer(); + if after < BANNED_THRESHOLD { + self.message_queue.push_back(Message::Banned(peer_id)) + } } } peersstate::Peer::Unknown(_) => { diff --git a/network-p2p/src/protocol.rs b/network-p2p/src/protocol.rs index 57c596f4db..9c26c916fb 100644 --- a/network-p2p/src/protocol.rs +++ b/network-p2p/src/protocol.rs @@ -491,8 +491,7 @@ impl Protocol { ); } self.peerset_handle.report_peer(who, rep::GENESIS_MISMATCH); - self.behaviour.disconnect_peer(&who, set_id); - return CustomMessageOutcome::Banned(who); + return CustomMessageOutcome::None; } if status.version < MIN_VERSION || CURRENT_VERSION < status.min_supported_version { log!( @@ -501,8 +500,7 @@ impl Protocol { "Peer {:?} using unsupported protocol version {}", who, status.version ); self.peerset_handle.report_peer(who, rep::BAD_PROTOCOL); - self.behaviour.disconnect_peer(&who, set_id); - return CustomMessageOutcome::Banned(who); + return CustomMessageOutcome::None; } debug!(target: "network-p2p", "Connected {}", who); let peer = Peer { diff --git a/network-p2p/src/protocol/generic_proto/behaviour.rs b/network-p2p/src/protocol/generic_proto/behaviour.rs index 3cb4548973..7f3647975a 100644 --- a/network-p2p/src/protocol/generic_proto/behaviour.rs +++ b/network-p2p/src/protocol/generic_proto/behaviour.rs @@ -1235,8 +1235,6 @@ impl NetworkBehaviour for GenericProto { let mut entry = if let Entry::Occupied(entry) = self.peers.entry((*peer_id, set_id)) { entry } else { - error!(target: "sub-libp2p", "inject_connection_closed: State mismatch in the custom protos handler"); - debug_assert!(false); return; }; match mem::replace(entry.get_mut(), PeerState::Poisoned) { diff --git a/network-p2p/src/request_responses.rs b/network-p2p/src/request_responses.rs index df9994559f..79f1275da0 100644 --- a/network-p2p/src/request_responses.rs +++ b/network-p2p/src/request_responses.rs @@ -348,7 +348,9 @@ impl NetworkBehaviour for RequestResponsesBehaviour { endpoint: &ConnectedPoint, ) { for (p, _) in self.protocols.values_mut() { - NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint) + if p.is_connected(peer_id) { + NetworkBehaviour::inject_connection_closed(p, peer_id, conn, endpoint) + } } }