Explorar o código

p2p: add is_pending() method

fixes a misuse of the API in greylist refinery that was adding a host to
the set of pending connections during the refinery process.
draoi %!s(int64=2) %!d(string=hai) anos
pai
achega
7ec08e76b4
Modificáronse 2 ficheiros con 6 adicións e 6 borrados
  1. 1 6
      src/net/hosts/refinery.rs
  2. 5 0
      src/net/p2p.rs

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

@@ -114,7 +114,7 @@ impl GreylistRefinery {
                     }
                     }
 
 
                     // Don't refine nodes that we are trying to connect to.
                     // Don't refine nodes that we are trying to connect to.
-                    if !self.p2p().add_pending(url).await {
+                    if self.p2p().is_pending(url).await {
                         continue
                         continue
                     }
                     }
 
 
@@ -122,8 +122,6 @@ impl GreylistRefinery {
                     if !ping_node(url.clone(), self.p2p().clone()).await {
                     if !ping_node(url.clone(), self.p2p().clone()).await {
                         greylist.remove(position);
                         greylist.remove(position);
 
 
-                        // Remove connection from pending
-                        self.p2p().remove_pending(url).await;
                         debug!(
                         debug!(
                             target: "net::refinery",
                             target: "net::refinery",
                             "Peer {} is non-responsive. Removed from greylist", url,
                             "Peer {} is non-responsive. Removed from greylist", url,
@@ -140,9 +138,6 @@ impl GreylistRefinery {
 
 
                     // Remove whitelisted peer from the greylist.
                     // Remove whitelisted peer from the greylist.
                     hosts.greylist_remove(url, position).await;
                     hosts.greylist_remove(url, position).await;
-
-                    // Remove connection from pending
-                    self.p2p().remove_pending(url).await;
                 }
                 }
                 None => {
                 None => {
                     debug!(target: "net::refinery", "No matching greylist entries found. Cannot proceed with refinery");
                     debug!(target: "net::refinery", "No matching greylist entries found. Cannot proceed with refinery");

+ 5 - 0
src/net/p2p.rs

@@ -248,6 +248,11 @@ impl P2p {
         self.pending.lock().await.insert(addr.clone())
         self.pending.lock().await.insert(addr.clone())
     }
     }
 
 
+    /// Check whether a connection is currently pending.
+    pub(super) async fn is_pending(&self, addr: &Url) -> bool {
+        self.pending.lock().await.contains(addr)
+    }
+
     /// Remove a channel from the list of pending channels.
     /// Remove a channel from the list of pending channels.
     pub(super) async fn remove_pending(&self, addr: &Url) {
     pub(super) async fn remove_pending(&self, addr: &Url) {
         self.pending.lock().await.remove(addr);
         self.pending.lock().await.remove(addr);