From 9358a1f30197b92833c6d38d73f70ef5cc9da0a8 Mon Sep 17 00:00:00 2001 From: pierre-l Date: Fri, 6 Jul 2018 16:50:30 +0200 Subject: [PATCH 1/2] Listening address is hardcoded to 127 0 0 1 #495 Add a host ("h") cli parameter --- pbtc/cli.yml | 6 ++++++ pbtc/commands/start.rs | 2 +- pbtc/config.rs | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pbtc/cli.yml b/pbtc/cli.yml index c3bd031c..82e6f35e 100644 --- a/pbtc/cli.yml +++ b/pbtc/cli.yml @@ -21,6 +21,12 @@ args: value_name: IP help: Connect only to the specified node. takes_value: true + - host: + short: h + long: host + value_name: HOST + help: Listen for connections on HOST. + takes_value: true - seednode: short: s long: seednode diff --git a/pbtc/commands/start.rs b/pbtc/commands/start.rs index 25bfd1f7..d0a06534 100644 --- a/pbtc/commands/start.rs +++ b/pbtc/commands/start.rs @@ -96,7 +96,7 @@ pub fn start(cfg: config::Config) -> Result<(), String> { protocol_version: PROTOCOL_VERSION, protocol_minimum: PROTOCOL_MINIMUM, magic: cfg.consensus.magic(), - local_address: SocketAddr::new("127.0.0.1".parse().unwrap(), cfg.port), + local_address: SocketAddr::new(cfg.host, cfg.port), services: cfg.services, user_agent: cfg.user_agent, start_height: 0, diff --git a/pbtc/config.rs b/pbtc/config.rs index 5c17ff60..4c636898 100644 --- a/pbtc/config.rs +++ b/pbtc/config.rs @@ -19,6 +19,7 @@ pub struct Config { pub services: Services, pub port: u16, pub connect: Option, + pub host: net::IpAddr, pub seednodes: Vec, pub quiet: bool, pub inbound_connections: u32, @@ -111,6 +112,21 @@ pub fn parse(matches: &clap::ArgMatches) -> Result { None => InternetProtocol::default(), }; + let host = match matches.value_of("host") { + Some(s) => Some(match s.parse::() { + Err(_) => s.parse::() + .map_err(|_| "Invalid host".to_owned()), + Ok(a) => Ok(a), + }?), + None => None, + }.unwrap_or( + match only_net { + InternetProtocol::IpV6 => "::".parse().unwrap(), + InternetProtocol::IpV4 => "0.0.0.0".parse().unwrap(), + InternetProtocol::Any => "0.0.0.0".parse().unwrap(), + } + ); + let rpc_config = parse_rpc_config(network, matches)?; let block_notify_command = match matches.value_of("blocknotify") { @@ -147,6 +163,7 @@ pub fn parse(matches: &clap::ArgMatches) -> Result { services: services, port: port, connect: connect, + host: host, seednodes: seednodes, inbound_connections: in_connections, outbound_connections: out_connections, From 2d12af3a08475256ca0d1994f6cb6c8f3cfef7fa Mon Sep 17 00:00:00 2001 From: pierre-l Date: Wed, 11 Jul 2018 01:47:29 +0200 Subject: [PATCH 2/2] Listening address is hardcoded to 127 0 0 1 #495 Use a more idiomatic way --- pbtc/config.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/pbtc/config.rs b/pbtc/config.rs index 4c636898..99462dcb 100644 --- a/pbtc/config.rs +++ b/pbtc/config.rs @@ -113,19 +113,12 @@ pub fn parse(matches: &clap::ArgMatches) -> Result { }; let host = match matches.value_of("host") { - Some(s) => Some(match s.parse::() { - Err(_) => s.parse::() - .map_err(|_| "Invalid host".to_owned()), - Ok(a) => Ok(a), - }?), - None => None, - }.unwrap_or( - match only_net { + Some(s) => s.parse::().map_err(|_| "Invalid host".to_owned())?, + None => match only_net { InternetProtocol::IpV6 => "::".parse().unwrap(), - InternetProtocol::IpV4 => "0.0.0.0".parse().unwrap(), - InternetProtocol::Any => "0.0.0.0".parse().unwrap(), + _ => "0.0.0.0".parse().unwrap(), } - ); + }; let rpc_config = parse_rpc_config(network, matches)?;