瀏覽代碼

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 年之前
父節點
當前提交
1d6f1175be
共有 2 個文件被更改,包括 26 次插入2 次删除
  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 {
             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 {
                 debug!(target: "net::hosts::check_addrs", "Skipping addr={}, err={}",
                        host.clone(), e);
-
                 continue
             }
 
@@ -991,6 +1000,13 @@ impl Hosts {
                 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.
             if self.container.contains(HostColor::Black as usize, addr_).await {
                 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 async_trait::async_trait;
-use log::{debug, info, warn};
+use log::{debug, error, info, warn};
 use smol::lock::Mutex;
 use url::Url;
 
@@ -107,6 +107,14 @@ impl ManualSession {
                 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 {
                 Ok(_) => {
                     match connector.connect(&addr).await {