Browse Source

net/connector: Mark IPv6 unavailability if the connector gets ENETUNREACH

parazyd 2 years ago
parent
commit
9f838d6d40
2 changed files with 13 additions and 1 deletions
  1. 10 1
      src/net/connector.rs
  2. 3 0
      src/net/p2p.rs

+ 10 - 1
src/net/connector.rs

@@ -98,7 +98,16 @@ impl Connector {
                 .await;
                 Ok((endpoint, channel))
             }
-            Either::Left((Err(e), _)) => Err(e),
+
+            Either::Left((Err(e), _)) => {
+                // If we get ENETUNREACH, we don't have IPv6 connectivity so note it down.
+                if e.raw_os_error() == Some(libc::ENETUNREACH) {
+                    *self.session.upgrade().unwrap().p2p().ipv6_available.lock().await = false;
+                }
+
+                Err(e.into())
+            }
+
             Either::Right((_, _)) => Err(Error::ConnectorStopped),
         }
     }

+ 3 - 0
src/net/p2p.rs

@@ -63,6 +63,8 @@ pub struct P2p {
     session_refine: RefineSessionPtr,
     /// Reference to configured [`SeedSyncSession`]
     session_seedsync: SeedSyncSessionPtr,
+    /// Marker for IPv6 availability
+    pub(in crate::net) ipv6_available: Mutex<bool>,
     /// Enable network debugging
     pub dnet_enabled: Mutex<bool>,
     /// The subscriber for which we can give dnet info over
@@ -92,6 +94,7 @@ impl P2p {
             session_refine: RefineSession::new(),
             session_seedsync: SeedSyncSession::new(),
 
+            ipv6_available: Mutex::new(true),
             dnet_enabled: Mutex::new(false),
             dnet_subscriber: Subscriber::new(),
         });