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

manual_session: delete 2nd death loop

this would loop forever in the case that the manual connection has been
successfully established.

we don't need `continue`, we can safely execute the function since
HostState is protecting from any invalid state changes (such
as changing a host state from Connected to Pending)

also move the HostState reset remove() after the sleep.
draoi 2 лет назад
Родитель
Сommit
2c15d0ad38
1 измененных файлов с 6 добавлено и 7 удалено
  1. 6 7
      src/net/session/manual_session.rs

+ 6 - 7
src/net/session/manual_session.rs

@@ -32,7 +32,7 @@
 use std::sync::Arc;
 use std::sync::Arc;
 
 
 use async_trait::async_trait;
 use async_trait::async_trait;
-use log::{info, warn};
+use log::{debug, info, warn};
 use smol::lock::Mutex;
 use smol::lock::Mutex;
 use url::Url;
 use url::Url;
 
 
@@ -114,10 +114,10 @@ impl ManualSession {
                 addr, tried_attempts,
                 addr, tried_attempts,
             );
             );
 
 
-            if let Err(_) =
+            if let Err(e) =
                 self.p2p().hosts().try_update_registry(addr.clone(), HostState::Pending).await
                 self.p2p().hosts().try_update_registry(addr.clone(), HostState::Pending).await
             {
             {
-                continue
+                warn!(target: "net::manual_session", "{}", e);
             }
             }
 
 
             match connector.connect(&addr).await {
             match connector.connect(&addr).await {
@@ -157,10 +157,6 @@ impl ManualSession {
                         "[P2P] Unable to connect to manual outbound [{}]: {}",
                         "[P2P] Unable to connect to manual outbound [{}]: {}",
                         addr, e,
                         addr, e,
                     );
                     );
-
-                    // Stop tracking this address in the HostRegistry.
-                    // Otherwise, host will be stuck in Pending state.
-                    self.p2p().hosts().remove(&addr).await;
                 }
                 }
             }
             }
 
 
@@ -187,6 +183,9 @@ impl ManualSession {
             "[P2P] Suspending manual connection to {} after {} failed attempts",
             "[P2P] Suspending manual connection to {} after {} failed attempts",
             addr, attempts,
             addr, attempts,
         );
         );
+        // Stop tracking this address in the HostRegistry.
+        // Otherwise, host will be stuck in Pending state.
+        self.p2p().hosts().remove(&addr).await;
 
 
         Ok(())
         Ok(())
     }
     }