|
|
@@ -2,33 +2,23 @@ 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, Debug, Deserialize, StructOpt)]
|
|
|
-#[structopt()]
|
|
|
+#[derive(Clone, Debug)]
|
|
|
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>,
|
|
|
}
|
|
|
|
|
|
@@ -48,3 +38,57 @@ impl Default for Settings {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/// Defines the network settings.
|
|
|
+#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
|
|
|
+#[serde(default)]
|
|
|
+#[structopt()]
|
|
|
+pub struct SettingsOpt {
|
|
|
+ /// P2P accept address
|
|
|
+ #[structopt(long = "accept")]
|
|
|
+ pub inbound: Option<SocketAddr>,
|
|
|
+
|
|
|
+ /// Connection slots
|
|
|
+ #[structopt(long = "slots", default_value = "0")]
|
|
|
+ pub outbound_connections: u32,
|
|
|
+
|
|
|
+ /// P2P external address
|
|
|
+ #[structopt(long)]
|
|
|
+ pub external_addr: Option<SocketAddr>,
|
|
|
+
|
|
|
+ /// Peer nodes to connect to
|
|
|
+ #[structopt(long)]
|
|
|
+ pub peers: Vec<SocketAddr>,
|
|
|
+
|
|
|
+ /// Seed nodes to connect to
|
|
|
+ #[structopt(long)]
|
|
|
+ pub seeds: Vec<SocketAddr>,
|
|
|
+
|
|
|
+ #[structopt(skip = 0 as u32)]
|
|
|
+ pub manual_attempt_limit: u32,
|
|
|
+ #[structopt(skip = 8 as u32)]
|
|
|
+ pub seed_query_timeout_seconds: u32,
|
|
|
+ #[structopt(skip = 10 as u32)]
|
|
|
+ pub connect_timeout_seconds: u32,
|
|
|
+ #[structopt(skip = 4 as u32)]
|
|
|
+ pub channel_handshake_seconds: u32,
|
|
|
+ #[structopt(skip = 10 as u32)]
|
|
|
+ pub channel_heartbeat_seconds: u32,
|
|
|
+}
|
|
|
+
|
|
|
+impl Into<Settings> for SettingsOpt {
|
|
|
+ fn into(self) -> Settings {
|
|
|
+ Settings {
|
|
|
+ inbound: self.inbound,
|
|
|
+ outbound_connections: self.outbound_connections,
|
|
|
+ manual_attempt_limit: self.manual_attempt_limit,
|
|
|
+ seed_query_timeout_seconds: self.seed_query_timeout_seconds,
|
|
|
+ connect_timeout_seconds: self.connect_timeout_seconds,
|
|
|
+ channel_handshake_seconds: self.channel_handshake_seconds,
|
|
|
+ channel_heartbeat_seconds: self.channel_heartbeat_seconds,
|
|
|
+ external_addr: self.external_addr,
|
|
|
+ peers: self.peers,
|
|
|
+ seeds: self.seeds,
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|