Explorar el Código

hosts: make quarantine_limit a configurable setting

x hace 3 años
padre
commit
a53e84f5ea
Se han modificado 2 ficheros con 8 adiciones y 1 borrados
  1. 1 1
      src/net/hosts.rs
  2. 7 0
      src/net/settings.rs

+ 1 - 1
src/net/hosts.rs

@@ -185,7 +185,7 @@ impl Hosts {
         if let Some(retries) = q.get_mut(url) {
             *retries += 1;
             debug!(target: "net::hosts::quarantine()", "Peer {} quarantined {} times", url, retries);
-            if *retries == 50 {
+            if *retries == self.settings.hosts_quarantine_limit {
                 debug!(target: "net::hosts::quarantine()", "Deleting peer {}", url);
                 q.remove(url);
             }

+ 7 - 0
src/net/settings.rs

@@ -59,6 +59,8 @@ pub struct Settings {
     pub channel_heartbeat_interval: u64,
     /// Allow localnet hosts
     pub localnet: bool,
+    /// Delete a peer from hosts if they've been quarantined N times
+    pub hosts_quarantine_limit: usize,
 }
 
 impl Default for Settings {
@@ -81,6 +83,7 @@ impl Default for Settings {
             channel_handshake_timeout: 10,
             channel_heartbeat_interval: 10,
             localnet: false,
+            hosts_quarantine_limit: 50,
         }
     }
 }
@@ -152,6 +155,9 @@ pub struct SettingsOpt {
     #[serde(default)]
     #[structopt(long)]
     pub localnet: bool,
+
+    #[structopt(skip)]
+    pub hosts_quarantine_limit: Option<usize>,
 }
 
 impl From<SettingsOpt> for Settings {
@@ -174,6 +180,7 @@ impl From<SettingsOpt> for Settings {
             channel_handshake_timeout: opt.channel_handshake_timeout.unwrap_or(10),
             channel_heartbeat_interval: opt.channel_heartbeat_interval.unwrap_or(10),
             localnet: opt.localnet,
+            hosts_quarantine_limit: opt.hosts_quarantine_limit.unwrap_or(15),
         }
     }
 }