From 0ac1b663febf0111365a209f1a27e8ad0d203321 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Fri, 25 Oct 2019 23:54:44 -0400 Subject: [PATCH] Keep sets of initial peers as Strings in config file --- zebra-network/src/config.rs | 31 +++++++++++++++++++++---------- zebrad/src/commands.rs | 2 ++ zebrad/src/commands/config.rs | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/zebra-network/src/config.rs b/zebra-network/src/config.rs index eed42b60..587dd085 100644 --- a/zebra-network/src/config.rs +++ b/zebra-network/src/config.rs @@ -1,5 +1,6 @@ use std::{ net::{SocketAddr, ToSocketAddrs}, + string::String, time::Duration, }; @@ -22,11 +23,11 @@ pub struct Config { /// mainnet. /// /// XXX this should be replaced with DNS names, not SocketAddrs - pub initial_mainnet_peers: Vec, + pub initial_mainnet_peers: Vec, /// A list of initial peers for the peerset when operating on /// testnet. - pub initial_testnet_peers: Vec, + pub initial_testnet_peers: Vec, /// The outgoing request buffer size for the peer set. pub peerset_request_buffer_size: usize, @@ -58,26 +59,36 @@ impl Config { /// Get the initial seed peers based on the configured network. pub fn initial_peers(&self) -> Vec { match self.network { - Network::Mainnet => self.initial_mainnet_peers.clone(), - Network::Testnet => self.initial_testnet_peers.clone(), + Network::Mainnet => Config::parse_peers(self.initial_mainnet_peers.clone()), + Network::Testnet => Config::parse_peers(self.initial_testnet_peers.clone()), } } } impl Default for Config { fn default() -> Config { + let mainnet_peers = [ + "dnsseed.z.cash:8233", + "dnsseed.str4d.xyz:8233", + "dnsseed.znodes.org:8233", + ] + .iter() + .map(|&s| String::from(s)) + .collect(); + + let testnet_peers = ["dnsseed.testnet.z.cash:18233"] + .iter() + .map(|&s| String::from(s)) + .collect(); + Config { listen_addr: "127.0.0.1:28233" .parse() .expect("Hardcoded address should be parseable"), user_agent: crate::constants::USER_AGENT.to_owned(), network: Network::Mainnet, - initial_mainnet_peers: Config::parse_peers(vec![ - "dnsseed.z.cash:8233", - "dnsseed.str4d.xyz:8233", - "dnsseed.znodes.org:8233", - ]), - initial_testnet_peers: Config::parse_peers(vec!["dnsseed.testnet.z.cash:18233"]), + initial_mainnet_peers: mainnet_peers, + initial_testnet_peers: testnet_peers, ewma_default_rtt: Duration::from_secs(1), ewma_decay_time: Duration::from_secs(60), peerset_request_buffer_size: 1, diff --git a/zebrad/src/commands.rs b/zebrad/src/commands.rs index 79d8e80b..09f7592e 100644 --- a/zebrad/src/commands.rs +++ b/zebrad/src/commands.rs @@ -9,6 +9,8 @@ //! //! See the `impl Configurable` below for how to specify the path to the //! application's configuration file. +// TODO: update the list of commands above or find a way to keep it +// automatically up to date. mod config; mod connect; diff --git a/zebrad/src/commands/config.rs b/zebrad/src/commands/config.rs index ab3ae8ba..730af4d0 100644 --- a/zebrad/src/commands/config.rs +++ b/zebrad/src/commands/config.rs @@ -27,7 +27,7 @@ impl Runnable for ConfigCmd { # can be found in Rustdoc. XXX add link to rendered docs. " - .to_owned(); + .to_owned(); // The default name and location of the config file is defined in ../commands.rs output += &toml::to_string_pretty(&default_config) .expect("default config should be serializable"); match self.output_file {