From 960082fe4ead7d93d2f8c5a1f9e463132cc5e778 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Sun, 1 Sep 2019 22:21:46 +1000 Subject: [PATCH] Set all listen addresses to 0.0.0.0 for testnets --- beacon_node/src/config.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index efc0b125c..a3829a33c 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -5,6 +5,7 @@ use lighthouse_bootstrap::Bootstrapper; use rand::{distributions::Alphanumeric, Rng}; use slog::{crit, info, warn, Logger}; use std::fs; +use std::net::Ipv4Addr; use std::path::{Path, PathBuf}; pub const DEFAULT_DATA_DIR: &str = ".lighthouse"; @@ -101,6 +102,10 @@ fn process_testnet_subcommand( "path" => format!("{:?}", builder.client_config.data_dir) ); + // When using the testnet command we listen on all addresses. + builder.set_listen_addresses("0.0.0.0".into())?; + warn!(log, "All services listening on 0.0.0.0"); + // Start matching on the second subcommand (e.g., `testnet bootstrap ...`). match cli_args.subcommand() { ("bootstrap", Some(cli_args)) => { @@ -437,6 +442,19 @@ impl<'a> ConfigBuilder<'a> { Ok(()) } + /// Sets all listening addresses to the given `addr`. + pub fn set_listen_addresses(&mut self, addr: String) -> Result<()> { + let addr = addr + .parse::() + .map_err(|e| format!("Unable to parse default listen address: {:?}", e))?; + + self.client_config.network.listen_address = addr.clone().into(); + self.client_config.rpc.listen_address = addr.clone(); + self.client_config.rest_api.listen_address = addr.clone(); + + Ok(()) + } + /// Consumes self, returning the configs. /// /// The supplied `cli_args` should be the base-level `clap` cli_args (i.e., not a subcommand