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

net: make self_handshake_interval a configurable Setting

draoi 2 лет назад
Родитель
Сommit
7ad0792976
2 измененных файлов с 14 добавлено и 4 удалено
  1. 4 4
      src/net/session/refine_session.rs
  2. 10 0
      src/net/settings.rs

+ 4 - 4
src/net/session/refine_session.rs

@@ -393,7 +393,7 @@ pub async fn whitelist_refinery(network_name: String, p2p: P2pPtr) -> Result<()>
 ///
 ///
 /// On first run, SelfHandshake will immediately conduct a version exchange
 /// On first run, SelfHandshake will immediately conduct a version exchange
 /// with our external addresses, and if successful update the last_seen
 /// with our external addresses, and if successful update the last_seen
-/// field. The process will wait [TODO: self_handshake_interval) before retrying.
+/// field. The process will wait Settings::self_handshake_interval before retrying.
 ///
 ///
 /// There are two situations in which this can fail:
 /// There are two situations in which this can fail:
 ///
 ///
@@ -441,13 +441,13 @@ impl SelfHandshake {
     }
     }
 
 
     async fn run(self: Arc<Self>) {
     async fn run(self: Arc<Self>) {
-        let external_addrs = self.session().p2p().settings().external_addrs.clone();
+        let settings = self.session().p2p().settings();
+        let external_addrs = settings.external_addrs.clone();
         let mut current_attempt = 0;
         let mut current_attempt = 0;
 
 
         loop {
         loop {
             if current_attempt >= 1 {
             if current_attempt >= 1 {
-                // TODO: make this a configurable interval
-                sleep(600).await;
+                sleep(settings.self_handshake_interval).await;
             }
             }
 
 
             // Only proceed if the external address is configured.
             // Only proceed if the external address is configured.

+ 10 - 0
src/net/settings.rs

@@ -70,6 +70,8 @@ pub struct Settings {
     pub hostlist: String,
     pub hostlist: String,
     /// Pause interval within greylist refinery process
     /// Pause interval within greylist refinery process
     pub greylist_refinery_interval: u64,
     pub greylist_refinery_interval: u64,
+    /// Pause interval before redoing a self-handshake
+    pub self_handshake_interval: u64,
     /// Percent of connections to come from the whitelist
     /// Percent of connections to come from the whitelist
     pub white_connect_count: u32,
     pub white_connect_count: u32,
     /// Number of anchorlist connections
     /// Number of anchorlist connections
@@ -107,6 +109,7 @@ impl Default for Settings {
             outbound_peer_discovery_attempt_time: 5,
             outbound_peer_discovery_attempt_time: 5,
             hostlist: "/dev/null".to_string(),
             hostlist: "/dev/null".to_string(),
             greylist_refinery_interval: 15,
             greylist_refinery_interval: 15,
+            self_handshake_interval: 600,
             white_connect_count: 90,
             white_connect_count: 90,
             anchor_connect_count: 2,
             anchor_connect_count: 2,
             time_with_no_connections: 30,
             time_with_no_connections: 30,
@@ -205,6 +208,10 @@ pub struct SettingsOpt {
     #[structopt(skip)]
     #[structopt(skip)]
     pub greylist_refinery_interval: Option<u64>,
     pub greylist_refinery_interval: Option<u64>,
 
 
+    /// Pause interval before redoing a self-handshake
+    #[structopt(skip)]
+    pub self_handshake_interval: Option<u64>,
+
     /// Number of whitelist connections
     /// Number of whitelist connections
     #[structopt(skip)]
     #[structopt(skip)]
     pub white_connect_count: Option<u32>,
     pub white_connect_count: Option<u32>,
@@ -261,6 +268,9 @@ impl From<SettingsOpt> for Settings {
             greylist_refinery_interval: opt
             greylist_refinery_interval: opt
                 .greylist_refinery_interval
                 .greylist_refinery_interval
                 .unwrap_or(def.greylist_refinery_interval),
                 .unwrap_or(def.greylist_refinery_interval),
+            self_handshake_interval: opt
+                .self_handshake_interval
+                .unwrap_or(def.self_handshake_interval),
             white_connect_count: opt.white_connect_count.unwrap_or(def.white_connect_count),
             white_connect_count: opt.white_connect_count.unwrap_or(def.white_connect_count),
             anchor_connect_count: opt.anchor_connect_count.unwrap_or(def.anchor_connect_count),
             anchor_connect_count: opt.anchor_connect_count.unwrap_or(def.anchor_connect_count),
             time_with_no_connections: opt
             time_with_no_connections: opt