Add a small ban when we get disconnected from a node (#3325)

This commit is contained in:
Pierre Krieger
2019-08-09 17:25:28 +02:00
committed by André Silva
parent 59c88cb2f3
commit a29f5763a7
@@ -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 {