From 8facb69c3fabf23cc331f476506fb7d487987bac Mon Sep 17 00:00:00 2001 From: Revertron Date: Thu, 10 Jun 2021 22:31:05 +0200 Subject: [PATCH] Implemented purging ignored IPs. --- src/p2p/peers.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/p2p/peers.rs b/src/p2p/peers.rs index 4287c07..e50b7af 100644 --- a/src/p2p/peers.rs +++ b/src/p2p/peers.rs @@ -2,6 +2,7 @@ use std::cmp::min; use std::collections::{HashMap, HashSet}; use std::io; use std::net::{IpAddr, Shutdown, SocketAddr, ToSocketAddrs}; +use std::time::Instant; use chrono::Utc; #[allow(unused_imports)] @@ -21,6 +22,7 @@ pub struct Peers { peers: HashMap, new_peers: Vec, ignored: HashSet, + ignore_timer: Instant, my_id: String, behind_ping_sent_time: i64 } @@ -31,6 +33,7 @@ impl Peers { peers: HashMap::new(), new_peers: Vec::new(), ignored: HashSet::new(), + ignore_timer: Instant::now(), my_id: commons::random_string(6), behind_ping_sent_time: 0 } @@ -270,6 +273,12 @@ impl Peers { } } + // Just purging ignored/banned IPs every 10 minutes + // TODO make it individual + if self.ignore_timer.elapsed().as_secs() >= 600 { + self.ignored.clear(); + } + // If someone has more blocks we sync if nodes >= MIN_CONNECTED_NODES_START_SYNC { if height < max_height {