Przeglądaj źródła

net: fix bug that was causing duplicate connections to seed nodes

We establish some new rules:

1. Configured seed nodes should never enter the hostlist.
2. If by weird chance they enter the hostlist, they should never be connected to in outbound session.
3. Manual connections to configured seeds are also not allowed.
draoi 2 lat temu
rodzic
commit
1d6f1175be
2 zmienionych plików z 26 dodań i 2 usunięć
  1. 17 1
      src/net/hosts/store.rs
  2. 9 1
      src/net/session/manual_session.rs

+ 17 - 1
src/net/hosts/store.rs

@@ -852,10 +852,19 @@ impl Hosts {
         for (host, last_seen) in hosts {
         for (host, last_seen) in hosts {
             debug!(target: "net::hosts::check_addrs()", "Starting checks");
             debug!(target: "net::hosts::check_addrs()", "Starting checks");
 
 
+            // Print a warning if we are trying to connect to a seed node in
+            // Outbound session. This shouldn't happen as we reject configured
+            // seed nodes from entering our hostlist in filter_addrs().
+            if self.settings.seeds.contains(&host) {
+                warn!(target: "net::hosts::check_addrs",
+                      "Seed addr={} has entered the hostlist! Skipping",
+                      host.clone());
+                continue
+            }
+
             if let Err(e) = self.try_register(host.clone(), HostState::Connect).await {
             if let Err(e) = self.try_register(host.clone(), HostState::Connect).await {
                 debug!(target: "net::hosts::check_addrs", "Skipping addr={}, err={}",
                 debug!(target: "net::hosts::check_addrs", "Skipping addr={}, err={}",
                        host.clone(), e);
                        host.clone(), e);
-
                 continue
                 continue
             }
             }
 
 
@@ -991,6 +1000,13 @@ impl Hosts {
                 continue
                 continue
             }
             }
 
 
+            // Configured seeds should never enter the hostlist.
+            if self.settings.seeds.contains(addr_) {
+                debug!(target: "net::hosts::filter_addresses()",
+                    "[{}] is a configured seed. Skipping", addr_);
+                continue
+            }
+
             // Blacklist peers should never enter the hostlist.
             // Blacklist peers should never enter the hostlist.
             if self.container.contains(HostColor::Black as usize, addr_).await {
             if self.container.contains(HostColor::Black as usize, addr_).await {
                 warn!(target: "net::hosts::filter_addresses()",
                 warn!(target: "net::hosts::filter_addresses()",

+ 9 - 1
src/net/session/manual_session.rs

@@ -32,7 +32,7 @@
 use std::{sync::Arc, time::UNIX_EPOCH};
 use std::{sync::Arc, time::UNIX_EPOCH};
 
 
 use async_trait::async_trait;
 use async_trait::async_trait;
-use log::{debug, info, warn};
+use log::{debug, error, info, warn};
 use smol::lock::Mutex;
 use smol::lock::Mutex;
 use url::Url;
 use url::Url;
 
 
@@ -107,6 +107,14 @@ impl ManualSession {
                 addr, tried_attempts,
                 addr, tried_attempts,
             );
             );
 
 
+            // Do not establish a connection to a host that is also configured as a seed.
+            // This indicates a user misconfiguration.
+            if settings.seeds.contains(&addr) {
+                error!(target: "net::manual_session", 
+                       "[P2P] Suspending manual connection to seed [{}]", addr.clone());
+                return Ok(())
+            }
+
             match self.p2p().hosts().try_register(addr.clone(), HostState::Connect).await {
             match self.p2p().hosts().try_register(addr.clone(), HostState::Connect).await {
                 Ok(_) => {
                 Ok(_) => {
                     match connector.connect(&addr).await {
                     match connector.connect(&addr).await {