diff --git a/src/net/acceptor.rs b/src/net/acceptor.rs index 17a679330..0be7a2c7f 100644 --- a/src/net/acceptor.rs +++ b/src/net/acceptor.rs @@ -126,7 +126,8 @@ impl Acceptor { .hosts() .container .contains(HostColor::Black as usize, &url) - .await + .await || + self.session.upgrade().unwrap().p2p().settings().blacklist.contains(&url) { warn!(target: "net::acceptor::run_accept_loop()", "Peer {} is blacklisted", url); continue diff --git a/src/net/connector.rs b/src/net/connector.rs index 3c95a9dd6..7f5ad8206 100644 --- a/src/net/connector.rs +++ b/src/net/connector.rs @@ -54,7 +54,8 @@ impl Connector { .hosts() .container .contains(HostColor::Black as usize, url) - .await + .await || + self.session.upgrade().unwrap().p2p().settings().blacklist.contains(url) { warn!(target: "net::connector::connect", "Peer {} is blacklisted", url); return Err(Error::ConnectFailed) diff --git a/src/net/hosts.rs b/src/net/hosts.rs index 7b83ea4d5..46d68d500 100644 --- a/src/net/hosts.rs +++ b/src/net/hosts.rs @@ -303,7 +303,9 @@ impl HostContainer { HostColor::try_from(color).unwrap()); let mut list = self.hostlists[color].write().await; - list.push((addr, last_seen)); + list.push((addr.clone(), last_seen)); + debug!(target: "net::hosts::store()", "Added [{}] to {:?} list", + addr, HostColor::try_from(color).unwrap()); if color == 0 && list.len() == GREYLIST_MAX_LEN { let last_entry = list.pop().unwrap(); @@ -928,7 +930,6 @@ impl Hosts { /// process fails, or when a channel stops. Prevents hosts from getting trapped in the /// HostState logical machinery. pub async fn unregister(&self, addr: &Url) { - debug!(target: "net::hosts::unregister()", "Removing {} from HostRegistry", addr); self.registry.write().await.remove(addr); debug!(target: "net::hosts::unregister()", "Removed {} from HostRegistry", addr); } @@ -1069,7 +1070,9 @@ impl Hosts { } // Blacklist peers should never enter the hostlist. - if self.container.contains(HostColor::Black as usize, addr_).await { + if self.container.contains(HostColor::Black as usize, addr_).await || + settings.blacklist.contains(addr_) + { warn!(target: "net::hosts::filter_addresses()", "[{}] is blacklisted", addr_); continue @@ -1140,8 +1143,6 @@ impl Hosts { if !settings.allowed_transports.contains(&addr_.scheme().to_string()) { self.container.store_or_update(HostColor::Dark, addr_.clone(), *last_seen).await; - debug!(target: "net::hosts::filter_addresses()", - "Added unsupported peer {} to Dark list", addr_); continue } @@ -1152,8 +1153,7 @@ impl Hosts { self.container.contains(HostColor::White as usize, addr_).await || self.container.contains(HostColor::Grey as usize, addr_).await { - debug!(target: "net::hosts::filter_addresses()", - "We already have {} in the hostlist. Skipping", addr_); + debug!(target: "net::hosts::filter_addresses()", "[{}] exists! Skipping", addr_); continue } diff --git a/src/net/settings.rs b/src/net/settings.rs index f2275e450..bb88a1a1d 100644 --- a/src/net/settings.rs +++ b/src/net/settings.rs @@ -77,6 +77,8 @@ pub struct Settings { /// Number of seconds with no connections after which refinery /// process is paused. pub time_with_no_connections: u64, + /// Nodes to avoid interacting with for the duration of the program. + pub blacklist: Vec, } impl Default for Settings { @@ -107,6 +109,7 @@ impl Default for Settings { white_connect_count: 90, anchor_connect_count: 2, time_with_no_connections: 30, + blacklist: vec![], } } } @@ -213,6 +216,11 @@ pub struct SettingsOpt { /// process is paused. #[structopt(skip)] pub time_with_no_connections: Option, + + /// Nodes to avoid interacting with for the duration of the program. + #[serde(default)] + #[structopt(long)] + pub blacklist: Vec, } impl From for Settings { @@ -256,6 +264,7 @@ impl From for Settings { time_with_no_connections: opt .time_with_no_connections .unwrap_or(def.time_with_no_connections), + blacklist: opt.blacklist, } } }