Explorar el Código

src/net: implement structopt for net::Settings
net::Setting is able now to be inside top level Args struct directly

ghassmo hace 4 años
padre
commit
5611bfa252
Se han modificado 1 ficheros con 16 adiciones y 20 borrados
  1. 16 20
      src/net/settings.rs

+ 16 - 20
src/net/settings.rs

@@ -1,38 +1,34 @@
 use std::{net::SocketAddr, sync::Arc};
 
+use serde::Deserialize;
+use structopt::StructOpt;
+use structopt_toml::StructOptToml;
+
 /// Atomic pointer to network settings.
 pub type SettingsPtr = Arc<Settings>;
 
 /// Defines the network settings.
-#[derive(Clone)]
+#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
+#[structopt()]
 pub struct Settings {
+    #[structopt(short, long)]
     pub inbound: Option<SocketAddr>,
+    #[structopt(long, default_value = "0")]
     pub outbound_connections: u32,
+    #[structopt(long, default_value = "0")]
     pub manual_attempt_limit: u32,
-
+    #[structopt(long, default_value = "8")]
     pub seed_query_timeout_seconds: u32,
+    #[structopt(long, default_value = "10")]
     pub connect_timeout_seconds: u32,
+    #[structopt(long, default_value = "4")]
     pub channel_handshake_seconds: u32,
+    #[structopt(long, default_value = "10")]
     pub channel_heartbeat_seconds: u32,
-
+    #[structopt(short, long)]
     pub external_addr: Option<SocketAddr>,
+    #[structopt(short, long)]
     pub peers: Vec<SocketAddr>,
+    #[structopt(short, long)]
     pub seeds: Vec<SocketAddr>,
 }
-
-impl Default for Settings {
-    fn default() -> Self {
-        Self {
-            inbound: None,
-            outbound_connections: 0,
-            manual_attempt_limit: 0,
-            seed_query_timeout_seconds: 8,
-            connect_timeout_seconds: 10,
-            channel_handshake_seconds: 4,
-            channel_heartbeat_seconds: 10,
-            external_addr: None,
-            peers: Vec::new(),
-            seeds: Vec::new(),
-        }
-    }
-}