diff --git a/beacon_node/client/src/client_config.rs b/beacon_node/client/src/client_config.rs index 570bd30e4..4a4774282 100644 --- a/beacon_node/client/src/client_config.rs +++ b/beacon_node/client/src/client_config.rs @@ -4,8 +4,8 @@ use fork_choice::ForkChoiceAlgorithm; use network::NetworkConfig; use slog::error; use std::fs; -use std::net::IpAddr; use std::net::SocketAddr; +use std::net::{IpAddr, Ipv4Addr}; use std::path::PathBuf; use types::multiaddr::Protocol; use types::multiaddr::ToMultiaddr; @@ -58,7 +58,7 @@ impl ClientConfig { pub fn parse_args(args: ArgMatches, log: &slog::Logger) -> Result { let mut config = ClientConfig::default(); - // Network related args + /* Network related arguments */ // Custom p2p listen port if let Some(port_str) = args.value_of("port") { @@ -88,13 +88,33 @@ impl ClientConfig { } } - // filesystem args + /* Filesystem related arguments */ // Custom datadir if let Some(dir) = args.value_of("datadir") { config.data_dir = PathBuf::from(dir.to_string()); }; + /* RPC related arguments */ + + if let Some(rpc_address) = args.value_of("rpc-address") { + if let Ok(listen_address) = rpc_address.parse::() { + config.rpc_conf.listen_address = listen_address; + } else { + error!(log, "Invalid RPC listen address"; "Address" => rpc_address); + return Err("Invalid RPC listen address"); + } + } + + if let Some(rpc_port) = args.value_of("rpc-port") { + if let Ok(port) = rpc_port.parse::() { + config.rpc_conf.port = port; + } else { + error!(log, "Invalid RPC port"; "port" => rpc_port); + return Err("Invalid RPC port"); + } + } + Ok(config) } } diff --git a/beacon_node/rpc/src/config.rs b/beacon_node/rpc/src/config.rs new file mode 100644 index 000000000..e21c2f7a8 --- /dev/null +++ b/beacon_node/rpc/src/config.rs @@ -0,0 +1,22 @@ +use std::net::Ipv4Addr; + +/// RPC Configuration +#[derive(Debug, Clone)] +pub struct Config { + /// Enable the RPC server. + pub enabled: bool, + /// The IPv4 address the RPC will listen on. + pub listen_address: Ipv4Addr, + /// The port the RPC will listen on. + pub port: u16, +} + +impl Default for Config { + fn default() -> Self { + Config { + enabled: false, // rpc disabled by default + listen_address: Ipv4Addr::new(127, 0, 0, 1), + port: 5051, + } + } +} diff --git a/beacon_node/src/main.rs b/beacon_node/src/main.rs index 9be6136c5..130353d77 100644 --- a/beacon_node/src/main.rs +++ b/beacon_node/src/main.rs @@ -37,6 +37,27 @@ fn main() { .help("Network listen port for p2p connections.") .takes_value(true), ) + .arg( + Arg::with_name("rpc") + .long("Enable RPC") + .value_name("RPC") + .help("Enable the RPC server.") + .takes_value(false), + ) + .arg( + Arg::with_name("rpc-address") + .long("rpc address") + .value_name("RPCADDRESS") + .help("Listen address for RPC endpoint.") + .takes_value(true), + ) + .arg( + Arg::with_name("rpc-port") + .long("rpc port") + .value_name("RPCPORT") + .help("Listen port for RPC endpoint.") + .takes_value(true), + ) .get_matches(); // invalid arguments, panic