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

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 лет назад
Родитель
Сommit
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 {