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

outbound_session: don't add to greylist if Connector stops

Also add a FIXME/ TODO note and various improved debug statements.
draoi 2 лет назад
Родитель
Сommit
e6cdcc80e1

+ 4 - 4
src/net/hosts.rs

@@ -494,7 +494,7 @@ impl HostContainer {
                 limit -= 1;
                 if limit == 0 {
                     debug!(target: "net::hosts::fetch_with_schemes()",
-                           "Found matching {:?} scheme, returning {} addresses",
+                           "Found matching addr on list={:?}, returning {} addresses",
                            HostColor::try_from(color).unwrap(), ret.len());
                     return ret
                 }
@@ -503,7 +503,7 @@ impl HostContainer {
 
         if ret.is_empty() {
             debug!(target: "net::hosts::fetch_with_schemes()",
-                   "No such {:?} schemes found!", HostColor::try_from(color).unwrap())
+                   "No matching schemes found on list={:?}!", HostColor::try_from(color).unwrap())
         }
 
         ret
@@ -1221,8 +1221,8 @@ impl Hosts {
         last_seen: u64,
         destination: HostColor,
     ) -> Result<()> {
-        debug!(target: "net::hosts::move_host()", "Trying to move addr={} node={} destination={:?}",
-               addr, self.settings.node_id, destination);
+        debug!(target: "net::hosts::move_host()", "Trying to move addr={} destination={:?}",
+               addr, destination);
 
         // This should never panic. Failure indicates a misuse of the HostState API.
         self.try_register(addr.clone(), HostState::Move).await.unwrap();

+ 20 - 3
src/net/session/outbound_session.rs

@@ -104,6 +104,7 @@ impl OutboundSession {
 
     /// Stops the outbound session.
     pub(crate) async fn stop(&self) {
+        debug!(target: "net::outbound_session", "Stopping outbound session..");
         let slots = &*self.slots.lock().await;
         let mut futures = FuturesUnordered::new();
 
@@ -114,6 +115,7 @@ impl OutboundSession {
         while (futures.next().await).is_some() {}
 
         self.peer_discovery.clone().stop().await;
+        debug!(target: "net::outbound_session", "Outbound session stopped!");
     }
 
     pub async fn slot_info(&self) -> Vec<u32> {
@@ -236,6 +238,10 @@ impl Slot {
         debug!(target: "net::outbound_session::fetch_addrs_with_preference()",
         "slot={}, preference={:?}", slot, preference);
 
+        // TODO: FIXME
+        // This address selection algorithm needs more thought.
+        // If we only have a white and gold list, and the slot number is 9,
+        // slot 9 will never find a host to connect to.
         match preference {
             SlotPreference::First => {
                 if slot < gold_count {
@@ -330,7 +336,8 @@ impl Slot {
             }
 
             let addr = if let Some(addr) = self.fetch_addrs().await {
-                debug!(target: "net::outbound_session::run()", "Fetched address: {:?}", addr);
+                debug!(target: "net::outbound_session::run()", "Fetched addr={}, slot #{}", addr.0,
+                self.slot);
                 addr
             } else {
                 debug!(target: "net::outbound_session::run()", "No address found! Activating peer discovery...");
@@ -436,13 +443,23 @@ impl Slot {
         match self.connector.connect(&addr).await {
             Ok((addr_final, channel)) => Ok((addr_final, channel)),
 
-            Err(e) => {
+            Err(err) => {
                 debug!(
                     target: "net::outbound_session::try_connect()",
                     "[P2P] Unable to connect outbound slot #{} [{}]: {}",
-                    self.slot, addr, e
+                    self.slot, addr, err
                 );
 
+                match err {
+                    // Immediately return if the Connector has stopped.
+                    // This indicates a shutdown of the P2P network and
+                    // should not result in hostlist modifications.
+                    Error::ConnectorStopped => {
+                        return Err(Error::ConnectFailed);
+                    }
+                    _ => {}
+                }
+
                 // At this point we failed to connect. We'll downgrade this peer now.
                 self.p2p().hosts().move_host(&addr, last_seen, HostColor::Grey).await?;
 

+ 0 - 1
src/net/session/refine_session.rs

@@ -199,7 +199,6 @@ impl GreylistRefinery {
     }
 
     pub async fn stop(self: Arc<Self>) {
-        debug!(target: "net::refinery", "Stopping refinery");
         self.process.stop().await;
     }
 

+ 2 - 0
src/net/session/seedsync_session.rs

@@ -113,6 +113,7 @@ impl SeedSyncSession {
 
     /// Stop the seedsync session.
     pub(crate) async fn stop(&self) {
+        debug!(target: "net::seedsync_session", "Stopping seed sync session...");
         let slots = &*self.slots.lock().await;
         let mut futures = FuturesUnordered::new();
 
@@ -121,6 +122,7 @@ impl SeedSyncSession {
         }
 
         while (futures.next().await).is_some() {}
+        debug!(target: "net::seedsync_session", "Seed sync session stopped!");
     }
 
     pub(crate) async fn failed(&self) -> bool {