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

net: combine remove_(..) etc methods into a single remove() method.

draoi 2 лет назад
Родитель
Сommit
1f9a01b94f
4 измененных файлов с 13 добавлено и 51 удалено
  1. 4 1
      src/net/hosts/refinery.rs
  2. 7 48
      src/net/hosts/store.rs
  3. 1 1
      src/net/session/inbound_session.rs
  4. 1 1
      src/net/session/mod.rs

+ 4 - 1
src/net/hosts/refinery.rs

@@ -122,7 +122,10 @@ impl GreylistRefinery {
 
 
                         // Remove this entry from HostRegistry to avoid this host getting
                         // Remove this entry from HostRegistry to avoid this host getting
                         // stuck in the Refining state.
                         // stuck in the Refining state.
-                        hosts.remove_refining(url).await;
+                        //
+                        // It is not necessary to call this when the refinery passes, since the
+                        // state will be changed to Connected.
+                        hosts.remove(url).await;
 
 
                         continue
                         continue
                     }
                     }

+ 7 - 48
src/net/hosts/store.rs

@@ -245,53 +245,12 @@ impl Hosts {
         None
         None
     }
     }
 
 
-    /// Remove a channel from the list of connected channels. Called
-    /// when a channel disconnects.
-    pub async fn remove_connected(&self, channel: ChannelPtr) {
-        debug!(target: "store", "remove_connected() Removing {}", channel.address());
-        let mut registry = self.registry.write().await;
-        let addr = channel.address();
-
-        let state = registry.get(addr).unwrap();
-
-        if let HostState::Connected(_) = state {
-            debug!(target: "store", "remove_connected() Removed {}", channel.address());
-            registry.remove(addr);
-        }
-    }
-
-    /// Remove a host from the list of downgrading hosts. Must be called
-    /// when downgrade process is finished to avoid the host getting stuck
-    /// in the Downgrading state.
-    pub async fn remove_downgrading(&self, addr: &Url) {
-        debug!(target: "store", "remove_downgrading() Removing {}", addr);
-        let mut registry = self.registry.write().await;
-
-        let state = registry.get(addr).unwrap();
-
-        if let HostState::Downgrading = state {
-            debug!(target: "store", "remove_downgrading() Removed {}", addr);
-            registry.remove(addr);
-        }
-    }
-
-    /// Remove a host from the list of refining hosts. Must be called
-    /// when refinery process fails to avoid the host getting stuck
-    /// in the Refining state.
-    ///
-    /// It is not necessary to call this when the refinery passes, since the
-    /// host state will be changed to Connected (and then the host will be removed
-    /// from the HostRegistry with remove_connected()).
-    pub async fn remove_refining(&self, addr: &Url) {
-        debug!(target: "store", "remove_refining() Removing {}", addr);
-        let mut registry = self.registry.write().await;
-
-        let state = registry.get(addr).unwrap();
-
-        if let HostState::Refining = state {
-            debug!(target: "store", "remove_refining() Removed {}", addr);
-            registry.remove(addr);
-        }
+    /// Remove a host from the HostRegistry. Must be called after downgrade(), when the refinery
+    /// process fails, or when a channel stops. Prevents hosts from getting trapped in the
+    /// HostState logical machinery.
+    pub async fn remove(&self, addr: &Url) {
+        debug!(target: "store", "remove() Removing {} from HostRegistry", addr);
+        self.registry.write().await.remove(addr);
     }
     }
 
 
     /// Returns the list of connected channels.
     /// Returns the list of connected channels.
@@ -497,7 +456,7 @@ impl Hosts {
 
 
         // Remove this entry from HostRegistry to avoid this host getting
         // Remove this entry from HostRegistry to avoid this host getting
         // stuck in the Downgrading state.
         // stuck in the Downgrading state.
-        self.remove_downgrading(&addr).await;
+        self.remove(&addr).await;
     }
     }
 
 
     /// Stores an address on the greylist or updates its last_seen field if we already
     /// Stores an address on the greylist or updates its last_seen field if we already

+ 1 - 1
src/net/session/inbound_session.rs

@@ -199,7 +199,7 @@ impl InboundSession {
 
 
         stop_sub.receive().await;
         stop_sub.receive().await;
 
 
-        self.p2p().hosts().remove_connected(channel.clone()).await;
+        self.p2p().hosts().remove(channel.clone().address()).await;
 
 
         debug!(
         debug!(
             target: "net::inbound_session::setup_channel()",
             target: "net::inbound_session::setup_channel()",

+ 1 - 1
src/net/session/mod.rs

@@ -62,7 +62,7 @@ pub async fn remove_sub_on_stop(p2p: P2pPtr, channel: ChannelPtr) {
     );
     );
 
 
     // Remove channel from p2p
     // Remove channel from p2p
-    p2p.hosts().remove_connected(channel).await;
+    p2p.hosts().remove(channel.address()).await;
     debug!(target: "net::session::remove_sub_on_stop()", "[END]");
     debug!(target: "net::session::remove_sub_on_stop()", "[END]");
 }
 }