Started creating mixnode commands, similarly to client

This commit is contained in:
Jedrzej Stuczynski
2020-02-03 14:15:22 +00:00
parent 1e1e1db4f5
commit de2dbf7156
6 changed files with 69 additions and 58 deletions
+2
View File
@@ -0,0 +1,2 @@
// The file has been placed there by the build script.
include!(concat!(env!("OUT_DIR"), "/built.rs"));
+5
View File
@@ -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")
}
+4
View File
@@ -0,0 +1,4 @@
use clap::ArgMatches;
pub mod init;
pub mod run;
+44
View File
@@ -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),
)
}
+14 -57
View File
@@ -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 {
-1
View File
@@ -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);