Преглед изворни кода

Revert "net: downgrade whitelist to greylist on stop"

This reverts commit 4bf43ec521280509a9f317fed3d8421f5cfd6492.
lunar-mining пре 2 година
родитељ
комит
b5119dff94
2 измењених фајлова са 9 додато и 32 уклоњено
  1. 0 3
      src/net/hosts/refinery.rs
  2. 9 29
      src/net/hosts/store.rs

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

@@ -67,9 +67,6 @@ impl GreylistRefinery {
     }
     }
 
 
     pub async fn stop(self: Arc<Self>) {
     pub async fn stop(self: Arc<Self>) {
-        // First save whitelist entries on the greylist.
-        self.p2p().hosts().whitelist_downgrade().await;
-
         match self.p2p().hosts().save_hosts().await {
         match self.p2p().hosts().save_hosts().await {
             Ok(()) => {
             Ok(()) => {
                 debug!(target: "net::refinery::stop()", "Save hosts successful!");
                 debug!(target: "net::refinery::stop()", "Save hosts successful!");

+ 9 - 29
src/net/hosts/store.rs

@@ -696,28 +696,20 @@ impl Hosts {
         anchorlist.iter().find(|(url, _)| url == addr).map(|(url, time)| (url.clone(), *time))
         anchorlist.iter().find(|(url, _)| url == addr).map(|(url, time)| (url.clone(), *time))
     }
     }
 
 
-    /// Return all known greylisted hosts
-    pub async fn greylist_fetch_all(&self) -> Vec<(Url, u64)> {
-        self.greylist.read().await.iter().cloned().collect()
-    }
-
     /// Return all known whitelisted hosts
     /// Return all known whitelisted hosts
     pub async fn whitelist_fetch_all(&self) -> Vec<(Url, u64)> {
     pub async fn whitelist_fetch_all(&self) -> Vec<(Url, u64)> {
         self.whitelist.read().await.iter().cloned().collect()
         self.whitelist.read().await.iter().cloned().collect()
     }
     }
 
 
-    /// Return all known anchorlisted hosts
-    pub async fn anchorlist_fetch_all(&self) -> Vec<(Url, u64)> {
-        self.anchorlist.read().await.iter().cloned().collect()
-    }
-
-    /// Return anchorlist and greylist hosts. Called on stop().
-    pub async fn hostlist_fetch_safe(&self) -> HashMap<String, Vec<(Url, u64)>> {
+    /// Return all known hosts
+    pub async fn hostlist_fetch_all(&self) -> HashMap<String, Vec<(Url, u64)>> {
         let mut hostlist = HashMap::new();
         let mut hostlist = HashMap::new();
         hostlist.insert(
         hostlist.insert(
             "anchorlist".to_string(),
             "anchorlist".to_string(),
             self.anchorlist.read().await.iter().cloned().collect(),
             self.anchorlist.read().await.iter().cloned().collect(),
         );
         );
+        hostlist
+            .insert("whitelist".to_string(), self.whitelist.read().await.iter().cloned().collect());
         hostlist
         hostlist
             .insert("greylist".to_string(), self.greylist.read().await.iter().cloned().collect());
             .insert("greylist".to_string(), self.greylist.read().await.iter().cloned().collect());
         hostlist
         hostlist
@@ -970,18 +962,6 @@ impl Hosts {
         ret
         ret
     }
     }
 
 
-    /// Downgrade all whitelist entries to the greylist. Called on GreylistRefinery::stop().
-    pub async fn whitelist_downgrade(&self) {
-        let mut greylist = self.greylist.write().await;
-
-        for (url, last_seen) in self.whitelist.read().await.iter() {
-            if !self.greylist_contains(&url).await {
-                greylist.push((url.clone(), *last_seen));
-            }
-        }
-
-    }
-
     /// Load the hostlist from a file.
     /// Load the hostlist from a file.
     pub async fn load_hosts(&self) -> Result<()> {
     pub async fn load_hosts(&self) -> Result<()> {
         let path = expand_path(&self.settings.hostlist)?;
         let path = expand_path(&self.settings.hostlist)?;
@@ -1023,6 +1003,9 @@ impl Hosts {
                 "greylist" => {
                 "greylist" => {
                     self.greylist_store(url, last_seen).await;
                     self.greylist_store(url, last_seen).await;
                 }
                 }
+                "whitelist" => {
+                    self.whitelist_store(url, last_seen).await;
+                }
                 "anchorlist" => {
                 "anchorlist" => {
                     self.anchorlist_store(url, last_seen).await;
                     self.anchorlist_store(url, last_seen).await;
                 }
                 }
@@ -1035,16 +1018,13 @@ impl Hosts {
         Ok(())
         Ok(())
     }
     }
 
 
-    /// Save the greylist and anchorlist to a file.
-    /// Note: we do not save the whitelist here as doing so would make the whitelist
-    /// effectively static. Instead, we first downgrade whitelist entries as greylist before
-    /// storing them on disk. This forces all whitelist entries through the refinery.
+    /// Save the hostlist to a file.
     pub async fn save_hosts(&self) -> Result<()> {
     pub async fn save_hosts(&self) -> Result<()> {
         let path = expand_path(&self.settings.hostlist)?;
         let path = expand_path(&self.settings.hostlist)?;
 
 
         let mut tsv = String::new();
         let mut tsv = String::new();
 
 
-        for (name, list) in self.hostlist_fetch_safe().await {
+        for (name, list) in self.hostlist_fetch_all().await {
             for (url, last_seen) in list {
             for (url, last_seen) in list {
                 tsv.push_str(&format!("{}\t{}\t{}\n", name, url, last_seen));
                 tsv.push_str(&format!("{}\t{}\t{}\n", name, url, last_seen));
             }
             }