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

net,dht,error: Include the endpoint address in connector error messages so upstream code can log it. In transport mixing scenarios, the mixed URL will appear in logs.

oars 11 месяцев назад
Родитель
Сommit
79d276ca32

+ 1 - 1
src/dht/mod.rs

@@ -566,7 +566,7 @@ impl<H: DhtHandler> Dht<H> {
                 return Err(Error::ConnectTimeout);
                 return Err(Error::ConnectTimeout);
             };
             };
             if connect_res.is_err() {
             if connect_res.is_err() {
-                warn!(target: "dht::get_channel()", "Error while connecting to {addr}: {}", connect_res.unwrap_err());
+                warn!(target: "dht::get_channel()", "Error while connecting: {}", connect_res.unwrap_err());
                 continue;
                 continue;
             }
             }
             let (_, channel) = connect_res.unwrap();
             let (_, channel) = connect_res.unwrap();

+ 4 - 4
src/error.rs

@@ -115,8 +115,8 @@ pub enum Error {
     #[error("Transport request exceeds number of accepted transports")]
     #[error("Transport request exceeds number of accepted transports")]
     InvalidTransportRequest,
     InvalidTransportRequest,
 
 
-    #[error("Connection failed")]
-    ConnectFailed,
+    #[error("Connection failed: {0}")]
+    ConnectFailed(String),
 
 
     #[cfg(feature = "system")]
     #[cfg(feature = "system")]
     #[error(transparent)]
     #[error(transparent)]
@@ -146,8 +146,8 @@ pub enum Error {
     #[error("Accept a new tls connection from the listener {0} failed")]
     #[error("Accept a new tls connection from the listener {0} failed")]
     AcceptTlsConnectionFailed(String),
     AcceptTlsConnectionFailed(String),
 
 
-    #[error("Connector stopped")]
-    ConnectorStopped,
+    #[error("Connector stopped: {0}")]
+    ConnectorStopped(String),
 
 
     #[error("Network operation failed")]
     #[error("Network operation failed")]
     NetworkOperationFailed,
     NetworkOperationFailed,

+ 8 - 4
src/net/connector.rs

@@ -59,7 +59,7 @@ impl Connector {
         let hosts = self.session.upgrade().unwrap().p2p().hosts();
         let hosts = self.session.upgrade().unwrap().p2p().hosts();
         if hosts.container.contains(HostColor::Black as usize, url) || hosts.block_all_ports(url) {
         if hosts.container.contains(HostColor::Black as usize, url) || hosts.block_all_ports(url) {
             warn!(target: "net::connector::connect", "Peer {url} is blacklisted");
             warn!(target: "net::connector::connect", "Peer {url} is blacklisted");
-            return Err(Error::ConnectFailed)
+            return Err(Error::ConnectFailed(format!("[{url}]: Peer is blacklisted")));
         }
         }
 
 
         let settings = self.settings.read().await;
         let settings = self.settings.read().await;
@@ -86,7 +86,11 @@ impl Connector {
             (url.clone(), false)
             (url.clone(), false)
         };
         };
 
 
-        let dialer = Dialer::new(endpoint.clone(), datastore, Some(i2p_socks5_proxy)).await?;
+        let dialer = match Dialer::new(endpoint.clone(), datastore, Some(i2p_socks5_proxy)).await {
+            Ok(dialer) => dialer,
+            Err(err) => return Err(Error::ConnectFailed(format!("[{endpoint}]: {err}"))),
+        };
+
         let timeout = Duration::from_secs(outbound_connect_timeout);
         let timeout = Duration::from_secs(outbound_connect_timeout);
 
 
         let stop_fut = async {
         let stop_fut = async {
@@ -121,10 +125,10 @@ impl Connector {
                         .ipv6_available
                         .ipv6_available
                         .store(false, Ordering::SeqCst);
                         .store(false, Ordering::SeqCst);
                 }
                 }
-                Err(e.into())
+                Err(Error::ConnectFailed(format!("[{endpoint}]: {e}")))
             }
             }
 
 
-            Either::Right((_, _)) => Err(Error::ConnectorStopped),
+            Either::Right((_, _)) => Err(Error::ConnectorStopped(format!("[{endpoint}]"))),
         }
         }
     }
     }
 
 

+ 1 - 1
src/net/hosts.rs

@@ -1133,7 +1133,7 @@ impl Hosts {
         // This will error if we are already connected to this peer, this peer
         // This will error if we are already connected to this peer, this peer
         // is suspended, or this peer is currently being inserted into the hostlist.
         // is suspended, or this peer is currently being inserted into the hostlist.
         // None of these scenarios should ever happen.
         // None of these scenarios should ever happen.
-        if let Err(e) = self.try_register(address.clone(), HostState::Connected(channel.clone())) {
+        if let Err(e) = self.try_register(address, HostState::Connected(channel.clone())) {
             warn!(target: "net::hosts::register_channel", "Error while registering channel {channel:?}: {e:?}");
             warn!(target: "net::hosts::register_channel", "Error while registering channel {channel:?}: {e:?}");
             return
             return
         }
         }

+ 16 - 14
src/net/session/manual_session.rs

@@ -185,7 +185,7 @@ impl Slot {
             }
             }
 
 
             match self.connector.connect(&self.addr).await {
             match self.connector.connect(&self.addr).await {
-                Ok((url, channel)) => {
+                Ok((_, channel)) => {
                     info!(
                     info!(
                         target: "net::manual_session",
                         target: "net::manual_session",
                         "[P2P] Manual outbound connected [{}]",
                         "[P2P] Manual outbound connected [{}]",
@@ -209,12 +209,25 @@ impl Slot {
                             );
                             );
                         }
                         }
                         Err(e) => {
                         Err(e) => {
-                            self.handle_failure(e, &url);
+                            warn!(
+                                target: "net::manual_session",
+                                "[P2P] Unable to connect to manual outbound [{}]: {e}",
+                                channel.display_address(),
+                            );
+
+                            // Free up this addr for future operations.
+                            self.p2p().hosts().unregister(channel.address());
                         }
                         }
                     }
                     }
                 }
                 }
                 Err(e) => {
                 Err(e) => {
-                    self.handle_failure(e, &self.addr);
+                    warn!(
+                        target: "net::manual_session",
+                        "[P2P] Unable to connect to manual outbound: {e}",
+                    );
+
+                    // Free up this addr for future operations.
+                    self.p2p().hosts().unregister(&self.addr);
                 }
                 }
             }
             }
 
 
@@ -228,17 +241,6 @@ impl Slot {
         }
         }
     }
     }
 
 
-    fn handle_failure(&self, error: Error, addr: &Url) {
-        warn!(
-            target: "net::manual_session",
-            "[P2P] Unable to connect to manual outbound [{}]: {error}",
-            self.addr
-        );
-
-        // Free up this addr for future operations.
-        self.p2p().hosts().unregister(addr);
-    }
-
     fn session(&self) -> ManualSessionPtr {
     fn session(&self) -> ManualSessionPtr {
         self.session.upgrade().unwrap()
         self.session.upgrade().unwrap()
     }
     }

+ 6 - 6
src/net/session/outbound_session.rs

@@ -306,7 +306,7 @@ impl Slot {
                 addr: host.clone(),
                 addr: host.clone(),
             });
             });
 
 
-            let (addr, channel) = match self.try_connect(host.clone(), last_seen).await {
+            let (_, channel) = match self.try_connect(host.clone(), last_seen).await {
                 Ok(connect_info) => connect_info,
                 Ok(connect_info) => connect_info,
                 Err(err) => {
                 Err(err) => {
                     debug!(
                     debug!(
@@ -397,15 +397,15 @@ impl Slot {
             Err(err) => {
             Err(err) => {
                 info!(
                 info!(
                     target: "net::outbound_session::try_connect()",
                     target: "net::outbound_session::try_connect()",
-                    "[P2P] Unable to connect outbound slot #{} [{addr}]: {err}",
+                    "[P2P] Unable to connect outbound slot #{} {err}",
                     self.slot
                     self.slot
                 );
                 );
 
 
                 // Immediately return if the Connector has stopped.
                 // Immediately return if the Connector has stopped.
                 // This indicates a shutdown of the P2P network and
                 // This indicates a shutdown of the P2P network and
                 // should not result in hostlist modifications.
                 // should not result in hostlist modifications.
-                if let Error::ConnectorStopped = err {
-                    return Err(Error::ConnectFailed);
+                if let Error::ConnectorStopped(message) = err {
+                    return Err(Error::ConnectFailed(message));
                 }
                 }
 
 
                 // At this point we failed to connect. We'll downgrade this peer now.
                 // At this point we failed to connect. We'll downgrade this peer now.
@@ -415,9 +415,9 @@ impl Slot {
                 self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).unwrap();
                 self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).unwrap();
 
 
                 // Notify that channel processing failed
                 // Notify that channel processing failed
-                self.p2p().hosts().channel_publisher.notify(Err(Error::ConnectFailed)).await;
+                self.p2p().hosts().channel_publisher.notify(Err(err.clone())).await;
 
 
-                Err(Error::ConnectFailed)
+                Err(err)
             }
             }
         }
         }
     }
     }

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

@@ -163,7 +163,7 @@ impl RefineSession {
             }
             }
 
 
             Err(e) => {
             Err(e) => {
-                debug!(target: "net::refinery::handshake_node()", "Failed to connect to {addr}, ({e})");
+                debug!(target: "net::refinery::handshake_node()", "Failed to connect ({e})");
                 false
                 false
             }
             }
         }
         }

+ 13 - 10
src/net/session/seedsync_session.rs

@@ -213,7 +213,7 @@ impl Slot {
             }
             }
 
 
             match self.connector.connect(&self.addr).await {
             match self.connector.connect(&self.addr).await {
-                Ok((url, ch)) => {
+                Ok((_, ch)) => {
                     info!(
                     info!(
                         target: "net::session::seedsync_session",
                         target: "net::session::seedsync_session",
                         "[P2P] Connected seed [{}]",
                         "[P2P] Connected seed [{}]",
@@ -242,7 +242,12 @@ impl Slot {
                         }
                         }
 
 
                         Err(e) => {
                         Err(e) => {
-                            self.handle_failure(e, ch.address());
+                            warn!(
+                                target: "net::session::seedsync_session",
+                                "[P2P] Unable to connect to seed [{}]: {e}",
+                                ch.display_address()
+                            );
+                            self.handle_failure(ch.address());
 
 
                             continue
                             continue
                         }
                         }
@@ -250,7 +255,11 @@ impl Slot {
                 }
                 }
 
 
                 Err(e) => {
                 Err(e) => {
-                    self.handle_failure(e, &self.addr);
+                    warn!(
+                        target: "net::session::seedsync_session",
+                        "[P2P] Unable to connect to seed: {e}",
+                    );
+                    self.handle_failure(&self.addr);
 
 
                     continue
                     continue
                 }
                 }
@@ -262,13 +271,7 @@ impl Slot {
         }
         }
     }
     }
 
 
-    fn handle_failure(&self, error: Error, addr: &Url) {
-        warn!(
-            target: "net::session::seedsync_session",
-            "[P2P] Unable to connect to seed [{}]: {error}",
-            self.addr
-        );
-
+    fn handle_failure(&self, addr: &Url) {
         self.failed.store(true, SeqCst);
         self.failed.store(true, SeqCst);
 
 
         // Free up this addr for future operations.
         // Free up this addr for future operations.