Optimized failing nodes banning.
This commit is contained in:
Generated
+8
-2
@@ -86,7 +86,7 @@ dependencies = [
|
|||||||
name = "alfis"
|
name = "alfis"
|
||||||
version = "0.8.4"
|
version = "0.8.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64 0.20.0",
|
||||||
"bincode",
|
"bincode",
|
||||||
"blakeout",
|
"blakeout",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
@@ -162,6 +162,12 @@ version = "0.13.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.20.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bincode"
|
name = "bincode"
|
||||||
version = "1.3.3"
|
version = "1.3.3"
|
||||||
@@ -1453,7 +1459,7 @@ version = "2.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f"
|
checksum = "b97acb4c28a254fd7a4aeec976c46a7fa404eac4d7c134b30c75144846d7cb8f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64 0.13.1",
|
||||||
"chunked_transfer",
|
"chunked_transfer",
|
||||||
"flate2",
|
"flate2",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@ serde = { version = "1.0.144", features = ["derive"] }
|
|||||||
serde_json = "1.0.85"
|
serde_json = "1.0.85"
|
||||||
bincode = "1.3.3"
|
bincode = "1.3.3"
|
||||||
serde_cbor = "0.11.2"
|
serde_cbor = "0.11.2"
|
||||||
base64 = "0.13.1"
|
base64 = "0.20.0"
|
||||||
num-bigint = "0.4.3"
|
num-bigint = "0.4.3"
|
||||||
num-traits = "0.2.15"
|
num-traits = "0.2.15"
|
||||||
chrono = { version = "0.4.20", features = ["serde"] }
|
chrono = { version = "0.4.20", features = ["serde"] }
|
||||||
|
|||||||
+11
-17
@@ -15,15 +15,14 @@ use rand::seq::IteratorRandom;
|
|||||||
|
|
||||||
use crate::commons::*;
|
use crate::commons::*;
|
||||||
use crate::p2p::{Message, Peer, State};
|
use crate::p2p::{Message, Peer, State};
|
||||||
use crate::{commons, Bytes};
|
use crate::Bytes;
|
||||||
|
|
||||||
const PING_PERIOD: u64 = 30;
|
const PING_PERIOD: u64 = 30;
|
||||||
|
|
||||||
pub struct Peers {
|
pub struct Peers {
|
||||||
peers: HashMap<Token, Peer>,
|
peers: HashMap<Token, Peer>,
|
||||||
new_peers: Vec<SocketAddr>,
|
new_peers: Vec<SocketAddr>,
|
||||||
ignored: HashSet<IpAddr>,
|
ignored: HashMap<IpAddr, Instant>,
|
||||||
ignore_timer: Instant,
|
|
||||||
my_id: String,
|
my_id: String,
|
||||||
behind_ping_sent_time: i64
|
behind_ping_sent_time: i64
|
||||||
}
|
}
|
||||||
@@ -33,9 +32,8 @@ impl Peers {
|
|||||||
Peers {
|
Peers {
|
||||||
peers: HashMap::new(),
|
peers: HashMap::new(),
|
||||||
new_peers: Vec::new(),
|
new_peers: Vec::new(),
|
||||||
ignored: HashSet::new(),
|
ignored: HashMap::new(),
|
||||||
ignore_timer: Instant::now(),
|
my_id: random_string(6),
|
||||||
my_id: commons::random_string(6),
|
|
||||||
behind_ping_sent_time: 0
|
behind_ping_sent_time: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +72,7 @@ impl Peers {
|
|||||||
}
|
}
|
||||||
State::Banned => {
|
State::Banned => {
|
||||||
debug!("Peer connection {} to {:?} has shut down, banned", &token.0, &addr);
|
debug!("Peer connection {} to {:?} has shut down, banned", &token.0, &addr);
|
||||||
self.ignored.insert(addr.ip());
|
self.ignored.insert(addr.ip(), Instant::now());
|
||||||
}
|
}
|
||||||
State::Offline { .. } => {
|
State::Offline { .. } => {
|
||||||
debug!("Peer connection {} to {:?} is offline", &token.0, &addr);
|
debug!("Peer connection {} to {:?} is offline", &token.0, &addr);
|
||||||
@@ -138,7 +136,7 @@ impl Peers {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.ignored.contains(&addr.ip()) {
|
if self.ignored.contains_key(&addr.ip()) {
|
||||||
debug!("Skipping ignored address from exchange: {}", &addr);
|
debug!("Skipping ignored address from exchange: {}", &addr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -164,7 +162,7 @@ impl Peers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_ignored(&self, addr: &IpAddr) -> bool {
|
pub fn is_ignored(&self, addr: &IpAddr) -> bool {
|
||||||
self.ignored.contains(addr)
|
self.ignored.contains_key(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_peers_for_exchange(&self, peer_address: &SocketAddr) -> Vec<String> {
|
pub fn get_peers_for_exchange(&self, peer_address: &SocketAddr) -> Vec<String> {
|
||||||
@@ -224,7 +222,7 @@ impl Peers {
|
|||||||
}
|
}
|
||||||
let ip = peer.get_addr().ip();
|
let ip = peer.get_addr().ip();
|
||||||
self.close_peer(registry, token);
|
self.close_peer(registry, token);
|
||||||
self.ignored.insert(ip);
|
self.ignored.insert(ip, Instant::now());
|
||||||
match self.peers
|
match self.peers
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(_, p)| p.get_addr().ip() == ip)
|
.find(|(_, p)| p.get_addr().ip() == ip)
|
||||||
@@ -238,7 +236,7 @@ impl Peers {
|
|||||||
|
|
||||||
pub fn ignore_ip(&mut self, ip: &IpAddr) {
|
pub fn ignore_ip(&mut self, ip: &IpAddr) {
|
||||||
info!("Adding {} to ignored peers", &ip);
|
info!("Adding {} to ignored peers", &ip);
|
||||||
self.ignored.insert(*ip);
|
self.ignored.insert(*ip, Instant::now());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn skip_peer_connection(&self, addr: &SocketAddr) -> bool {
|
pub fn skip_peer_connection(&self, addr: &SocketAddr) -> bool {
|
||||||
@@ -286,11 +284,7 @@ impl Peers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Just purging ignored/banned IPs every 10 minutes
|
// Just purging ignored/banned IPs every 10 minutes
|
||||||
// TODO make it individual for every IP
|
self.ignored.retain(|_addr, time| { time.elapsed().as_secs() < 600 });
|
||||||
if self.ignore_timer.elapsed().as_secs() >= 600 {
|
|
||||||
self.ignored.clear();
|
|
||||||
self.ignore_timer = Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If someone has more blocks we sync
|
// If someone has more blocks we sync
|
||||||
if nodes >= MIN_CONNECTED_NODES_START_SYNC && height < max_height {
|
if nodes >= MIN_CONNECTED_NODES_START_SYNC && height < max_height {
|
||||||
@@ -455,7 +449,7 @@ impl Peers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn connect_peer(&mut self, addr: &SocketAddr, registry: &Registry, unique_token: &mut Token, yggdrasil_only: bool) -> io::Result<()> {
|
fn connect_peer(&mut self, addr: &SocketAddr, registry: &Registry, unique_token: &mut Token, yggdrasil_only: bool) -> io::Result<()> {
|
||||||
if self.ignored.contains(&addr.ip()) {
|
if self.ignored.contains_key(&addr.ip()) {
|
||||||
return Err(io::Error::from(io::ErrorKind::ConnectionAborted));
|
return Err(io::Error::from(io::ErrorKind::ConnectionAborted));
|
||||||
}
|
}
|
||||||
if yggdrasil_only && !is_yggdrasil(&addr.ip()) {
|
if yggdrasil_only && !is_yggdrasil(&addr.ip()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user