Explorar el Código

net: just patch any external_addr which is set to [::], rather than looping over inbounds

darkfi hace 1 año
padre
commit
0bf59aad78

+ 1 - 1
example/dchat/dchatd/example/node1.toml

@@ -5,7 +5,7 @@ verbose = 2
 hostlist = "example/node1.tsv"
 inbound = ["tcp://[::]:10202"]
 allowed_transports = ["tcp"]
-external_addrs = ["tcp://[::1]:10202"]
+external_addrs = ["tcp://[::]:10202"]
 seeds = ["tcp://[::1]:10200"]
 outbound_connections = 5
 magic_bytes = [127, 64, 12, 201]

+ 5 - 8
src/net/protocol/protocol_address.rs

@@ -226,16 +226,13 @@ impl ProtocolAddress {
             return Ok(())
         }
 
-        let settings = self.settings.read().await;
-        let mut external_addrs = settings.external_addrs.clone();
+        let mut external_addrs = self.settings.read().await.external_addrs.clone();
 
         // Auto-advertise the node's inbound address using the address that
         // was sent to use by the node in the version exchange.
-        for inbound in settings.inbound_addrs.clone() {
-            let Some(inbound) = Self::patch_inbound(&self.channel, inbound) else { continue };
-            external_addrs.push(inbound);
+        for external_addr in &mut external_addrs {
+            let _ = Self::patch_inbound(&self.channel, external_addr);
         }
-        drop(settings);
 
         if external_addrs.is_empty() {
             debug!(
@@ -272,7 +269,7 @@ impl ProtocolAddress {
     /// us by the version exchange.
     ///
     /// Also used by ProtocolSeed.
-    pub(super) fn patch_inbound(channel: &Channel, mut inbound: Url) -> Option<Url> {
+    pub(super) fn patch_inbound(channel: &Channel, inbound: &mut Url) -> Option<()> {
         if inbound.scheme() != "tcp" && inbound.scheme() != "tcp+tls" {
             return None
         }
@@ -307,7 +304,7 @@ impl ProtocolAddress {
             _ => return None,
         };
         inbound.set_host(version.connect_recv_addr.host_str()).ok()?;
-        Some(inbound)
+        Some(())
     }
 }
 

+ 3 - 8
src/net/protocol/protocol_seed.rs

@@ -63,18 +63,13 @@ impl ProtocolSeed {
             "[START] channel address={}", self.channel.address(),
         );
 
-        let settings = self.settings.read().await;
-        let mut external_addrs = settings.external_addrs.clone();
+        let mut external_addrs = self.settings.read().await.external_addrs.clone();
 
         // Auto-advertise the node's inbound address using the address that
         // was sent to use by the node in the version exchange.
-        for inbound in settings.inbound_addrs.clone() {
-            let Some(inbound) = ProtocolAddress::patch_inbound(&self.channel, inbound) else {
-                continue
-            };
-            external_addrs.push(inbound);
+        for external_addr in &mut external_addrs {
+            let _ = ProtocolAddress::patch_inbound(&self.channel, external_addr);
         }
-        drop(settings);
 
         if external_addrs.is_empty() {
             debug!(