mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Add a small ban when we get disconnected from a node (#3325)
This commit is contained in:
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 {
|
||||
|
||||
Reference in New Issue
Block a user