Skip to content

Commit

Permalink
Implemented purging ignored IPs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Jun 10, 2021
1 parent 428ed92 commit 8facb69
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/p2p/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -21,6 +22,7 @@ pub struct Peers {
peers: HashMap<Token, Peer>,
new_peers: Vec<SocketAddr>,
ignored: HashSet<IpAddr>,
ignore_timer: Instant,
my_id: String,
behind_ping_sent_time: i64
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8facb69

Please sign in to comment.