CLI option and network configuration

This commit is contained in:
Robert Habermeier 2016-06-19 15:59:12 +02:00
parent 08522eec37
commit a4dacca262
3 changed files with 25 additions and 0 deletions

View File

@ -67,6 +67,9 @@ Networking Options:
--no-discovery Disable new peer discovery. --no-discovery Disable new peer discovery.
--node-key KEY Specify node secret key, either as 64-character hex --node-key KEY Specify node secret key, either as 64-character hex
string or input to SHA3 operation. 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: API and Console Options:
--jsonrpc-off Disable the JSON-RPC API server. --jsonrpc-off Disable the JSON-RPC API server.
@ -236,6 +239,7 @@ pub struct Args {
pub flag_no_discovery: bool, pub flag_no_discovery: bool,
pub flag_nat: String, pub flag_nat: String,
pub flag_node_key: Option<String>, pub flag_node_key: Option<String>,
pub flag_reserved_peers: Option<String>,
pub flag_cache_pref_size: usize, pub flag_cache_pref_size: usize,
pub flag_cache_max_size: usize, pub flag_cache_max_size: usize,
pub flag_queue_max_size: usize, pub flag_queue_max_size: usize,

View File

@ -153,6 +153,24 @@ impl Configuration {
} }
} }
pub fn init_reserved_nodes(&self) -> Vec<String> {
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<SocketAddr>, Option<SocketAddr>) { pub fn net_addresses(&self) -> (Option<SocketAddr>, Option<SocketAddr>) {
let port = self.net_port(); let port = self.net_port();
let listen_address = Some(SocketAddr::new(IpAddr::from_str("0.0.0.0").unwrap(), 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()); let mut net_path = PathBuf::from(&self.path());
net_path.push("network"); net_path.push("network");
ret.config_path = Some(net_path.to_str().unwrap().to_owned()); ret.config_path = Some(net_path.to_str().unwrap().to_owned());
ret.reserved_nodes = self.init_reserved_nodes();
ret ret
} }

View File

@ -73,6 +73,8 @@ pub struct NetworkConfiguration {
pub use_secret: Option<Secret>, pub use_secret: Option<Secret>,
/// Number of connected peers to maintain /// Number of connected peers to maintain
pub ideal_peers: u32, pub ideal_peers: u32,
/// List of reserved node addresses.
pub reserved_nodes: Vec<String>,
} }
impl Default for NetworkConfiguration { impl Default for NetworkConfiguration {