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

manual_session: connection attempt now loops forever

previously we would try to connect Settings::manual_attempt_limit times
and exit if we fail on all attempts.

However, Manual session should instead just loop forever. It's not
intended for general users, but is rather a focused session for spinning
up clusters of nodes for development/ testing purposes.
draoi 2 лет назад
Родитель
Сommit
ec2f74fdaa
2 измененных файлов с 6 добавлено и 33 удалено
  1. 6 25
      src/net/session/manual_session.rs
  2. 0 8
      src/net/settings.rs

+ 6 - 25
src/net/session/manual_session.rs

@@ -20,7 +20,9 @@
 //! Used to create a manual session and to stop and start the session.
 //!
 //! A manual session is a type of outbound session in which we attempt
-//! connection to a predefined set of peers.
+//! connection to a predefined set of peers. Manual sessions loop forever
+//! continually trying to connect to a given peer, and sleep
+//! `outbound_connect_timeout` times between each attempt.
 //!
 //! Class consists of a weak pointer to the p2p interface and a vector of
 //! outbound connection slots. Using a weak pointer to p2p allows us to
@@ -94,17 +96,13 @@ impl ManualSession {
         let settings = self.p2p().settings();
         let connector = Connector::new(settings.clone(), parent);
 
-        let attempts = settings.manual_attempt_limit;
-        let mut remaining = attempts;
-
-        // Loop forever if attempts==0, otherwise loop attempts number of times.
-        let mut tried_attempts = 0;
+        let mut attempts = 0;
         loop {
-            tried_attempts += 1;
+            attempts += 1;
             info!(
                 target: "net::manual_session",
                 "[P2P] Connecting to manual outbound [{}] (attempt #{})",
-                addr, tried_attempts,
+                addr, attempts
             );
 
             // Do not establish a connection to a host that is also configured as a seed.
@@ -164,15 +162,6 @@ impl ManualSession {
                            outbound [{}]: {}", addr.clone(), e);
                 }
             }
-            // Wait and try again.
-            // TODO: Should we notify about the failure now, or after all attempts
-            // have failed?
-            self.p2p().hosts().channel_subscriber.notify(Err(Error::ConnectFailed)).await;
-
-            remaining = if attempts == 0 { 1 } else { remaining - 1 };
-            if remaining == 0 {
-                break
-            }
 
             info!(
                 target: "net::manual_session",
@@ -181,14 +170,6 @@ impl ManualSession {
             );
             sleep(settings.outbound_connect_timeout).await;
         }
-
-        warn!(
-            target: "net::manual_session",
-            "[P2P] Suspending manual connection to {} after {} failed attempts",
-            addr, attempts,
-        );
-
-        Ok(())
     }
 }
 

+ 0 - 8
src/net/settings.rs

@@ -52,8 +52,6 @@ pub struct Settings {
     /// Inbound connection slots number, this many active listening connections
     /// will be allowed. (This does not include manual connections)
     pub inbound_connections: usize,
-    /// Manual connections retry limit, 0 for forever looping
-    pub manual_attempt_limit: usize,
     /// Outbound connection timeout (in seconds)
     pub outbound_connect_timeout: u64,
     /// Exchange versions (handshake) timeout (in seconds)
@@ -100,7 +98,6 @@ impl Default for Settings {
             transport_mixing: true,
             outbound_connections: 0,
             inbound_connections: 10,
-            manual_attempt_limit: 0,
             outbound_connect_timeout: 15,
             channel_handshake_timeout: 10,
             channel_heartbeat_interval: 30,
@@ -156,10 +153,6 @@ pub struct SettingsOpt {
     #[structopt(long)]
     pub seeds: Vec<Url>,
 
-    /// Manual connections retry limit
-    #[structopt(skip)]
-    pub manual_attempt_limit: Option<usize>,
-
     /// Connection establishment timeout in seconds
     #[structopt(skip)]
     pub outbound_connect_timeout: Option<u64>,
@@ -247,7 +240,6 @@ impl From<SettingsOpt> for Settings {
             transport_mixing: opt.transport_mixing.unwrap_or(def.transport_mixing),
             outbound_connections: opt.outbound_connections.unwrap_or(def.outbound_connections),
             inbound_connections: opt.inbound_connections.unwrap_or(def.inbound_connections),
-            manual_attempt_limit: opt.manual_attempt_limit.unwrap_or(def.manual_attempt_limit),
             outbound_connect_timeout: opt
                 .outbound_connect_timeout
                 .unwrap_or(def.outbound_connect_timeout),