From f858d407ca56738848f3f37e49877df622b0508e Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 4 Feb 2020 12:48:40 +0000 Subject: [PATCH] Starting the mixnode with commands::run::execute --- mixnode/src/commands/run.rs | 105 +++++++++++++++++++++++++++++++----- mixnode/src/config/mod.rs | 4 ++ mixnode/src/main.rs | 2 +- mixnode/src/node/mod.rs | 12 ++--- 4 files changed, 104 insertions(+), 19 deletions(-) diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index ac2a20f99c..666e4f0c49 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -1,14 +1,40 @@ -use clap::{App, Arg}; +use crate::commands::override_config; +use crate::config::persistance::pathfinder::MixNodePathfinder; +use crate::config::Config; +use crate::node; +use crate::node::MixNode; +use clap::{App, Arg, ArgMatches}; +use config::NymConfig; +use pemstore::pemstore::PemStore; pub fn command_args<'a, 'b>() -> App<'a, 'b> { App::new("run") .about("Starts the mixnode") + .arg( + Arg::with_name("id") + .long("id") + .help("Id of the nym-mixnode we want to create config for.") + .takes_value(true) + .required(true), + ) + // the rest of arguments are optional, they are used to override settings in config file + .arg( + Arg::with_name("config") + .long("config") + .help("Custom path to the nym-mixnet-client configuration file") + .takes_value(true), + ) + .arg( + Arg::with_name("layer") + .long("layer") + .help("The mixnet layer of this particular node") + .takes_value(true), + ) .arg( Arg::with_name("host") .long("host") .help("The custom host on which the mixnode will be running") - .takes_value(true) - .required(true), + .takes_value(true), ) .arg( Arg::with_name("port") @@ -17,20 +43,13 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .takes_value(true), ) .arg( - Arg::with_name("layer") - .long("layer") - .help("The mixnet layer of this particular node") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("announce_host") + Arg::with_name("announce-host") .long("announce-host") .help("The host that will be reported to the directory server") .takes_value(true), ) .arg( - Arg::with_name("announce_port") + Arg::with_name("announce-port") .long("announce-port") .help("The port that will be reported to the directory server") .takes_value(true), @@ -42,3 +61,65 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .takes_value(true), ) } + +fn show_binding_warning(address: String) { + println!("\n##### WARNING #####"); + println!( + "\nYou are trying to bind to {} - you might not be accessible to other nodes\n\ + You can ignore this warning if you're running setup on a local network \n\ + or have set a custom 'announce-host'", + address + ); + println!("\n##### WARNING #####\n"); +} + +pub fn execute(matches: &ArgMatches) { + let id = matches.value_of("id").unwrap(); + + println!("Starting mixnode {}...", id); + + let mut config = + Config::load_from_file(matches.value_of("config").map(|path| path.into()), Some(id)) + .expect("Failed to load config file"); + + config = override_config(config, matches); + + let listening_ip_string = config.get_listening_address().ip().to_string(); + if listening_ip_string == "localhost" + || listening_ip_string == "127.0.0.1" + || listening_ip_string == "0.0.0.0" + { + show_binding_warning(listening_ip_string); + } + + let sphinx_keypair = PemStore::new(MixNodePathfinder::new_from_config(&config)) + .read_encryption() + .expect("Failed to read stored identity key files"); + + println!( + "Public encryption key: {}\nFor time being, it is identical to identity keys", + sphinx_keypair.public_key().to_base58_string() + ); + + println!("Directory server: {}", config.get_directory_server()); + println!( + "Listening for incoming packets on {}", + config.get_listening_address() + ); + println!( + "Announcing the following socket address: {}", + config.get_announce_address() + ); + + let old_dummy_config = node::Config { + announce_address: config.get_announce_address(), + directory_server: config.get_directory_server(), + layer: config.get_layer(), + public_key: sphinx_keypair.public_key().0, + secret_key: sphinx_keypair.private_key().0, + socket_address: config.get_listening_address(), + }; + + let mix = MixNode::new(&old_dummy_config); + mix.start(old_dummy_config).unwrap(); +} diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index ca534b9965..f1d9dfbd21 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -172,6 +172,10 @@ impl Config { self.mixnode.directory_server.clone() } + pub fn get_layer(&self) -> usize { + self.mixnode.layer + } + pub fn get_listening_address(&self) -> SocketAddr { self.mixnode.listening_address } diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index 4541f60850..212d2d6c3c 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -28,7 +28,7 @@ fn main() { fn execute(matches: ArgMatches) { match matches.subcommand() { ("init", Some(m)) => commands::init::execute(m), - ("run", Some(m)) => node::runner::start(m), + ("run", Some(m)) => commands::run::execute(m), _ => println!("{}", usage()), } } diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index 502ff77843..b9085f4c48 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -20,12 +20,12 @@ mod presence; pub mod runner; pub struct Config { - announce_address: String, - directory_server: String, - layer: usize, - public_key: MontgomeryPoint, - secret_key: Scalar, - socket_address: SocketAddr, + pub announce_address: String, + pub directory_server: String, + pub layer: usize, + pub public_key: MontgomeryPoint, + pub secret_key: Scalar, + pub socket_address: SocketAddr, } impl Config {