Implemented purging ignored IPs.

This commit is contained in:
Revertron
2021-06-10 22:31:05 +02:00
parent 428ed92d87
commit 8facb69c3f
+9
View File
@@ -2,6 +2,7 @@ use std::cmp::min;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::io; use std::io;
use std::net::{IpAddr, Shutdown, SocketAddr, ToSocketAddrs}; use std::net::{IpAddr, Shutdown, SocketAddr, ToSocketAddrs};
use std::time::Instant;
use chrono::Utc; use chrono::Utc;
#[allow(unused_imports)] #[allow(unused_imports)]
@@ -21,6 +22,7 @@ pub struct Peers {
peers: HashMap<Token, Peer>, peers: HashMap<Token, Peer>,
new_peers: Vec<SocketAddr>, new_peers: Vec<SocketAddr>,
ignored: HashSet<IpAddr>, ignored: HashSet<IpAddr>,
ignore_timer: Instant,
my_id: String, my_id: String,
behind_ping_sent_time: i64 behind_ping_sent_time: i64
} }
@@ -31,6 +33,7 @@ impl Peers {
peers: HashMap::new(), peers: HashMap::new(),
new_peers: Vec::new(), new_peers: Vec::new(),
ignored: HashSet::new(), ignored: HashSet::new(),
ignore_timer: Instant::now(),
my_id: commons::random_string(6), my_id: commons::random_string(6),
behind_ping_sent_time: 0 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 someone has more blocks we sync
if nodes >= MIN_CONNECTED_NODES_START_SYNC { if nodes >= MIN_CONNECTED_NODES_START_SYNC {
if height < max_height { if height < max_height {