From de2dbf7156c17d66345a676fb5a62cff748c96c5 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 3 Feb 2020 14:15:22 +0000 Subject: [PATCH] Started creating mixnode commands, similarly to client --- mixnode/src/built_info.rs | 2 + mixnode/src/commands/init.rs | 5 +++ mixnode/src/commands/mod.rs | 4 ++ mixnode/src/commands/run.rs | 44 ++++++++++++++++++++++ mixnode/src/main.rs | 71 +++++++----------------------------- mixnode/src/node/runner.rs | 1 - 6 files changed, 69 insertions(+), 58 deletions(-) create mode 100644 mixnode/src/built_info.rs create mode 100644 mixnode/src/commands/init.rs create mode 100644 mixnode/src/commands/mod.rs create mode 100644 mixnode/src/commands/run.rs diff --git a/mixnode/src/built_info.rs b/mixnode/src/built_info.rs new file mode 100644 index 0000000000..d11fb6389f --- /dev/null +++ b/mixnode/src/built_info.rs @@ -0,0 +1,2 @@ +// The file has been placed there by the build script. +include!(concat!(env!("OUT_DIR"), "/built.rs")); diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs new file mode 100644 index 0000000000..0b06f75d05 --- /dev/null +++ b/mixnode/src/commands/init.rs @@ -0,0 +1,5 @@ +use clap::{App, Arg}; + +pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { + App::new("init").about("Initialise the mixnode") +} diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs new file mode 100644 index 0000000000..7cfd48c75a --- /dev/null +++ b/mixnode/src/commands/mod.rs @@ -0,0 +1,4 @@ +use clap::ArgMatches; + +pub mod init; +pub mod run; diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs new file mode 100644 index 0000000000..ac2a20f99c --- /dev/null +++ b/mixnode/src/commands/run.rs @@ -0,0 +1,44 @@ +use clap::{App, Arg}; + +pub fn command_args<'a, 'b>() -> App<'a, 'b> { + App::new("run") + .about("Starts the mixnode") + .arg( + Arg::with_name("host") + .long("host") + .help("The custom host on which the mixnode will be running") + .takes_value(true) + .required(true), + ) + .arg( + Arg::with_name("port") + .long("port") + .help("The port on which the mixnode will be listening") + .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") + .long("announce-host") + .help("The host that will be reported to the directory server") + .takes_value(true), + ) + .arg( + Arg::with_name("announce_port") + .long("announce-port") + .help("The port that will be reported to the directory server") + .takes_value(true), + ) + .arg( + Arg::with_name("directory") + .long("directory") + .help("Address of the directory server the node is sending presence and metrics to") + .takes_value(true), + ) +} diff --git a/mixnode/src/main.rs b/mixnode/src/main.rs index f16f460dd3..4e80538187 100644 --- a/mixnode/src/main.rs +++ b/mixnode/src/main.rs @@ -1,7 +1,10 @@ -use clap::{App, Arg, ArgMatches, SubCommand}; +use clap::{App, ArgMatches}; use log::*; use std::process; +pub mod built_info; +mod commands; +mod config; mod mix_peer; mod node; @@ -9,74 +12,28 @@ fn main() { dotenv::dotenv().ok(); pretty_env_logger::init(); + println!("{}", banner()); + let arg_matches = App::new("Nym Mixnode") .version(built_info::PKG_VERSION) .author("Nymtech") .about("Implementation of the Loopix-based Mixnode") - .subcommand( - SubCommand::with_name("run") - .about("Starts the mixnode") - .arg( - Arg::with_name("host") - .long("host") - .help("The custom host on which the mixnode will be running") - .takes_value(true) - .required(true), - ) - .arg( - Arg::with_name("port") - .long("port") - .help("The port on which the mixnode will be listening") - .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") - .long("announce-host") - .help("The host that will be reported to the directory server") - .takes_value(true) - ) - .arg( - Arg::with_name("announce_port") - .long("announce-port") - .help("The port that will be reported to the directory server") - .takes_value(true) - ) - .arg( - Arg::with_name("directory") - .long("directory") - .help("Address of the directory server the node is sending presence and metrics to") - .takes_value(true), - ), - ) + .subcommand(commands::init::command_args()) + .subcommand(commands::run::command_args()) .get_matches(); - if let Err(e) = execute(arg_matches) { - error!("{}", e); - process::exit(1); - } + execute(arg_matches); } -pub mod built_info { - // The file has been placed there by the build script. - include!(concat!(env!("OUT_DIR"), "/built.rs")); -} - -fn execute(matches: ArgMatches) -> Result<(), String> { +fn execute(matches: ArgMatches) { match matches.subcommand() { - ("run", Some(m)) => Ok(node::runner::start(m)), - _ => Err(usage()), + ("run", Some(m)) => node::runner::start(m), + _ => println!("{}", usage()), } } -fn usage() -> String { - banner() + "usage: --help to see available options.\n\n" +fn usage() -> &'static str { + "usage: --help to see available options.\n\n" } fn banner() -> String { diff --git a/mixnode/src/node/runner.rs b/mixnode/src/node/runner.rs index a403e02036..669b8d3c58 100644 --- a/mixnode/src/node/runner.rs +++ b/mixnode/src/node/runner.rs @@ -14,7 +14,6 @@ fn print_binding_warning(address: &str) { } pub fn start(matches: &ArgMatches) { - println!("{}", banner()); println!("Starting mixnode..."); let config = new_config(matches);