From 7e59d05975765f2547468e9dcfd1361516c41e06 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 23 Feb 2023 12:21:37 +0400 Subject: [PATCH] do not accept incoming conns if peer was banned --- client/network/src/protocol/notifications/behaviour.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client/network/src/protocol/notifications/behaviour.rs b/client/network/src/protocol/notifications/behaviour.rs index 7bd3e8b430f94..8417ce8434ad4 100644 --- a/client/network/src/protocol/notifications/behaviour.rs +++ b/client/network/src/protocol/notifications/behaviour.rs @@ -413,7 +413,7 @@ impl Notifications { } /// Disconnects the given peer if we are connected to it. - /// + /// /// Note the peer will be banned for 10s after this. pub fn disconnect_peer(&mut self, peer_id: &PeerId, set_id: sc_peerset::SetId) { trace!(target: "sub-libp2p", "External API => Disconnect({}, {:?})", peer_id, set_id); @@ -1592,6 +1592,12 @@ impl NetworkBehaviour for Notifications { // Disabled => Disabled | Incoming PeerState::Disabled { mut connections, backoff_until } => { + // Do not accept incoming connections if the peer is still banned. + if backoff_until.map_or(false, |t| t > Instant::now()) { + *entry.into_mut() = PeerState::Disabled { connections, backoff_until }; + return + } + if let Some((_, connec_state)) = connections.iter_mut().find(|(c, _)| *c == connection_id) {