From a4dacca262f289a6e5f73f471452f3fb8c7f77a0 Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Sun, 19 Jun 2016 15:59:12 +0200 Subject: [PATCH] CLI option and network configuration --- parity/cli.rs | 4 ++++ parity/configuration.rs | 19 +++++++++++++++++++ util/src/network/host.rs | 2 ++ 3 files changed, 25 insertions(+) diff --git a/parity/cli.rs b/parity/cli.rs index 38af6af4c..8c6f2d72d 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -67,6 +67,9 @@ Networking Options: --no-discovery Disable new peer discovery. --node-key KEY Specify node secret key, either as 64-character hex string or input to SHA3 operation. + --reserved-peers FILE Provide a file containing enodes, one per line. + These nodes will always have a reserved slot on top + of the normal maximum peers. API and Console Options: --jsonrpc-off Disable the JSON-RPC API server. @@ -236,6 +239,7 @@ pub struct Args { pub flag_no_discovery: bool, pub flag_nat: String, pub flag_node_key: Option, + pub flag_reserved_peers: Option, pub flag_cache_pref_size: usize, pub flag_cache_max_size: usize, pub flag_queue_max_size: usize, diff --git a/parity/configuration.rs b/parity/configuration.rs index 3aff2ee27..666eabdda 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -153,6 +153,24 @@ impl Configuration { } } + pub fn init_reserved_nodes(&self) -> Vec { + use std::fs::File; + use std::io::BufRead; + + if let Some(ref path) = self.args.reserved_nodes { + let node_file = File::open(path).unwrap_or_else(|e| { + die!("Error opening reserved nodes file: {}", e); + }); + node_file.lines().map(|s| { + Self::normalize_enode(s).unwrap_or_else(|| { + die!("{}: Invalid node address format given for a reserved node.", s); + }) + }).collect() + } else { + Vec::new() + } + } + pub fn net_addresses(&self) -> (Option, Option) { let port = self.net_port(); let listen_address = Some(SocketAddr::new(IpAddr::from_str("0.0.0.0").unwrap(), port)); @@ -179,6 +197,7 @@ impl Configuration { let mut net_path = PathBuf::from(&self.path()); net_path.push("network"); ret.config_path = Some(net_path.to_str().unwrap().to_owned()); + ret.reserved_nodes = self.init_reserved_nodes(); ret } diff --git a/util/src/network/host.rs b/util/src/network/host.rs index aef56fc09..c6810abb7 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -73,6 +73,8 @@ pub struct NetworkConfiguration { pub use_secret: Option, /// Number of connected peers to maintain pub ideal_peers: u32, + /// List of reserved node addresses. + pub reserved_nodes: Vec, } impl Default for NetworkConfiguration {