ソースを参照

net/settings: Convert hostlist into an Option<String>

parazyd 2 年 前
コミット
ba62cdf6e5
3 ファイル変更23 行追加18 行削除
  1. 1 1
      bin/lilith/src/main.rs
  2. 19 14
      src/net/session/refine_session.rs
  3. 3 3
      src/net/settings.rs

+ 1 - 1
bin/lilith/src/main.rs

@@ -351,7 +351,7 @@ async fn spawn_net(name: String, info: &NetInfo, ex: Arc<Executor<'static>>) ->
         inbound_connections: 512,
         app_version: info.version.clone(),
         localnet: info.localnet,
-        hostlist: info.hostlist.clone(),
+        hostlist: Some(info.hostlist.clone()),
         allowed_transports: vec![
             "tcp".to_string(),
             "tcp+tls".to_string(),

+ 19 - 14
src/net/session/refine_session.rs

@@ -71,20 +71,23 @@ impl RefineSession {
 
     /// Start the refinery and self handshake processes.
     pub(crate) async fn start(self: Arc<Self>) {
-        match self.p2p().hosts().container.load_all(&self.p2p().settings().hostlist) {
-            Ok(()) => {
-                debug!(target: "net::refine_session::start()", "Load hosts successful!");
-            }
-            Err(e) => {
-                warn!(target: "net::refine_session::start()", "Error loading hosts {}", e);
+        if let Some(ref hostlist) = self.p2p().settings().hostlist {
+            match self.p2p().hosts().container.load_all(hostlist) {
+                Ok(()) => {
+                    debug!(target: "net::refine_session::start", "Load hosts successful!");
+                }
+                Err(e) => {
+                    warn!(target: "net::refine_session::start", "Error loading hosts {}", e);
+                }
             }
         }
+
         match self.p2p().hosts().import_blacklist() {
             Ok(()) => {
-                debug!(target: "net::refine_session::start()", "Import blacklist successful!");
+                debug!(target: "net::refine_session::start", "Import blacklist successful!");
             }
             Err(e) => {
-                warn!(target: "net::refine_session::start()",
+                warn!(target: "net::refine_session::start",
                     "Error importing blacklist from config file {}", e);
             }
         }
@@ -98,12 +101,14 @@ impl RefineSession {
         debug!(target: "net::refine_session", "Stopping refinery process");
         self.refinery.clone().stop().await;
 
-        match self.p2p().hosts().container.save_all(&self.p2p().settings().hostlist) {
-            Ok(()) => {
-                debug!(target: "net::refine_session::stop()", "Save hosts successful!");
-            }
-            Err(e) => {
-                warn!(target: "net::refine_session::stop()", "Error saving hosts {}", e);
+        if let Some(ref hostlist) = self.p2p().settings().hostlist {
+            match self.p2p().hosts().container.save_all(hostlist) {
+                Ok(()) => {
+                    debug!(target: "net::refine_session::stop()", "Save hosts successful!");
+                }
+                Err(e) => {
+                    warn!(target: "net::refine_session::stop()", "Error saving hosts {}", e);
+                }
             }
         }
     }

+ 3 - 3
src/net/settings.rs

@@ -65,7 +65,7 @@ pub struct Settings {
     /// Time between peer discovery attempts
     pub outbound_peer_discovery_attempt_time: u64,
     /// Hostlist storage path
-    pub hostlist: String,
+    pub hostlist: Option<String>,
     /// Pause interval within greylist refinery process
     pub greylist_refinery_interval: u64,
     /// Percent of connections to come from the whitelist
@@ -106,7 +106,7 @@ impl Default for Settings {
             localnet: false,
             outbound_peer_discovery_cooloff_time: 30,
             outbound_peer_discovery_attempt_time: 5,
-            hostlist: "/dev/null".to_string(),
+            hostlist: None,
             greylist_refinery_interval: 15,
             white_connect_percent: 70,
             gold_connect_count: 2,
@@ -261,7 +261,7 @@ impl From<SettingsOpt> for Settings {
             outbound_peer_discovery_attempt_time: opt
                 .outbound_peer_discovery_attempt_time
                 .unwrap_or(def.outbound_peer_discovery_attempt_time),
-            hostlist: opt.hostlist.unwrap_or(def.hostlist),
+            hostlist: opt.hostlist,
             greylist_refinery_interval: opt
                 .greylist_refinery_interval
                 .unwrap_or(def.greylist_refinery_interval),