Просмотр исходного кода

net: create greylist_refinery_interval in net::Settings and update TODOs

lunar-mining 2 лет назад
Родитель
Сommit
6e8671d5b0
3 измененных файлов с 15 добавлено и 13 удалено
  1. 2 5
      src/net/hosts/refinery.rs
  2. 3 8
      src/net/hosts/store.rs
  3. 10 0
      src/net/settings.rs

+ 2 - 5
src/net/hosts/refinery.rs

@@ -33,7 +33,6 @@ pub type GreylistRefineryPtr = Arc<GreylistRefinery>;
 //// Probe random peers on the greylist. If a peer is responsive, update the last_seen field and
 //// add it to the whitelist. If a node does not respond, remove it from the greylist.
 //// Called periodically.
-// NOTE: in monero this is called "greylist housekeeping" but that's a bit verbose.
 pub struct GreylistRefinery {
     /// Weak pointer to parent p2p object
     pub(in crate::net) p2p: LazyWeak<P2p>,
@@ -69,8 +68,7 @@ impl GreylistRefinery {
         self.process.stop().await
     }
 
-    //// Randomly select a peer on the greylist and probe it.
-    //// TODO: This frequency of this call can be set in net::Settings.
+    // Randomly select a peer on the greylist and probe it.
     async fn run(self: Arc<Self>) {
         debug!(target: "net::refinery::run()", "START");
         loop {
@@ -101,9 +99,8 @@ impl GreylistRefinery {
                 }
             }
 
-            // TODO: create a custom net setting for this timer
             debug!(target: "net::greylist_refinery::run()", "Sleeping...");
-            sleep(10).await;
+            sleep(self.p2p().settings().greylist_refinery_interval).await;
         }
     }
 

+ 3 - 8
src/net/hosts/store.rs

@@ -53,14 +53,9 @@ const WHITELIST_MAX_LEN: usize = 5000;
 const GREYLIST_MAX_LEN: usize = 2000;
 
 /// Manages a store of network addresses
-// TODO: 1. Hostlists will be stored on disk and loaded on start.
-//
-//       2. Potentially we should store the entire peer list as a single file,
-//       classified by grey/ white/ anchor (more in line with the monero impl).
-//
-//       3. Test the performance overhead of using vectors for white/grey/anchor lists.
-//
-//       3. Check whether anchorlist has a max size in Monero.
+// TODO:
+//       * Test the performance overhead of using vectors for white/grey/anchor lists.
+//       * Check whether anchorlist has a max size in Monero.
 pub struct Hosts {
     // Intermediary node list that is periodically probed and updated to whitelist.
     pub greylist: RwLock<Vec<(Url, u64)>>,

+ 10 - 0
src/net/settings.rs

@@ -72,6 +72,8 @@ pub struct Settings {
     pub advertise: bool,
     /// Hostlist storage path
     pub hostlist: String,
+    /// Pause interval within greylist refinery process
+    pub greylist_refinery_interval: u64,
 }
 
 impl Default for Settings {
@@ -101,6 +103,7 @@ impl Default for Settings {
             outbound_peer_discovery_attempt_time: 5,
             advertise: true,
             hostlist,
+            greylist_refinery_interval: 30,
         }
     }
 }
@@ -199,6 +202,10 @@ pub struct SettingsOpt {
     #[serde(default)]
     #[structopt(long)]
     pub hostlist: String,
+
+    /// Pause interval within greylist refinery process
+    #[structopt(skip)]
+    pub greylist_refinery_interval: Option<u64>,
 }
 
 impl From<SettingsOpt> for Settings {
@@ -238,6 +245,9 @@ impl From<SettingsOpt> for Settings {
                 .unwrap_or(def.outbound_peer_discovery_attempt_time),
             advertise: opt.advertise,
             hostlist: opt.hostlist,
+            greylist_refinery_interval: opt
+                .greylist_refinery_interval
+                .unwrap_or(def.greylist_refinery_interval),
         }
     }
 }