From a29f5763a7c00996273a4eb667deeb6617dd59e6 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 9 Aug 2019 17:25:28 +0200 Subject: [PATCH] Add a small ban when we get disconnected from a node (#3325) --- substrate/core/network/src/legacy_proto/behaviour.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/substrate/core/network/src/legacy_proto/behaviour.rs b/substrate/core/network/src/legacy_proto/behaviour.rs index 790c1d158d..1c83329ba0 100644 --- a/substrate/core/network/src/legacy_proto/behaviour.rs +++ b/substrate/core/network/src/legacy_proto/behaviour.rs @@ -24,6 +24,7 @@ use futures03::{compat::Compat, TryFutureExt as _, StreamExt as _, TryStreamExt use libp2p::core::{ConnectedPoint, Multiaddr, PeerId}; use libp2p::swarm::{NetworkBehaviour, NetworkBehaviourAction, PollParameters}; use log::{debug, error, trace, warn}; +use rand::distributions::{Distribution as _, Uniform}; use sr_primitives::traits::Block as BlockT; use smallvec::SmallVec; use std::{borrow::Cow, collections::hash_map::Entry, cmp, error, marker::PhantomData, mem, pin::Pin}; @@ -746,6 +747,11 @@ where debug!(target: "sub-libp2p", "PSM <= Dropped({:?})", peer_id); self.peerset.dropped(peer_id.clone()); + let ban_dur = Uniform::new(5, 10).sample(&mut rand::thread_rng()); + self.peers.insert(peer_id.clone(), PeerState::Banned { + until: Instant::now() + Duration::from_secs(ban_dur) + }); + if open { debug!(target: "sub-libp2p", "External API <= Closed({:?})", peer_id); let event = LegacyProtoOut::CustomProtocolClosed {