Kaynağa Gözat

refinery: only refine nodes that match our transports

this commit means each node's whitelist will only consist of nodes that match their own transports.
lunar-mining 2 yıl önce
ebeveyn
işleme
453a712b9e
2 değiştirilmiş dosya ile 17 ekleme ve 3 silme
  1. 3 2
      src/net/hosts/refinery.rs
  2. 14 1
      src/net/hosts/store.rs

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

@@ -87,13 +87,14 @@ impl GreylistRefinery {
             let hosts = self.p2p().hosts();
 
             if hosts.is_empty_greylist().await {
-                warn!(target: "net::refinery",
+                debug!(target: "net::refinery",
                 "Greylist is empty! Cannot start refinery process");
 
                 continue
             }
 
-            let (entry, position) = hosts.greylist_fetch_random().await;
+            // Only attempt to refine peers that match our transports.
+            let (entry, position) = hosts.greylist_fetch_random_with_schemes().await;
             let url = &entry.0;
 
             // Skip this node if it's being migrated currently.

+ 14 - 1
src/net/hosts/store.rs

@@ -800,7 +800,20 @@ impl Hosts {
         (entry.clone(), position)
     }
 
-    /// Get up to n random whitelisted peers that match the given transport schemes from the hosts set.
+    /// Get a random greylist peer that matches the given transport schemes.
+    pub async fn greylist_fetch_random_with_schemes(&self) -> ((Url, u64), usize) {
+        trace!(target: "store::greylist_fetch_random_with_schemes", "[START]");
+
+        // Retrieve all peers corresponding to that transport schemes
+        let schemes = &self.settings.allowed_transports;
+        let greylist = self.greylist_fetch_with_schemes(&schemes, None).await;
+
+        let position = rand::thread_rng().gen_range(0..greylist.len());
+        let entry = &greylist[position];
+        (entry.clone(), position)
+    }
+
+    /// Get up to n random whitelist peers that match the given transport schemes.
     pub async fn whitelist_fetch_n_random_with_schemes(
         &self,
         schemes: &[String],