119 lines
3.7 KiB
Rust
119 lines
3.7 KiB
Rust
use crate::commands::override_config;
|
|
use crate::config::Config;
|
|
use crate::node::MixNode;
|
|
use clap::{App, Arg, ArgMatches};
|
|
use config::NymConfig;
|
|
|
|
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 run")
|
|
.takes_value(true)
|
|
.required(true),
|
|
)
|
|
// the rest of arguments are optional, they are used to override settings in config file
|
|
.arg(
|
|
Arg::with_name("location")
|
|
.long("location")
|
|
.help("Optional geographical location of this node")
|
|
.takes_value(true),
|
|
)
|
|
.arg(
|
|
Arg::with_name("config")
|
|
.long("config")
|
|
.help("Custom path to the nym-mixnode 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),
|
|
)
|
|
.arg(
|
|
Arg::with_name("port")
|
|
.long("port")
|
|
.help("The port on which the mixnode will be listening")
|
|
.takes_value(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),
|
|
)
|
|
}
|
|
|
|
fn show_binding_warning(address: String) {
|
|
println!("\n##### NOTE #####");
|
|
println!(
|
|
"\nYou are trying to bind to {} - you might not be accessible to other nodes\n\
|
|
You can ignore this note if you're running setup on a local network \n\
|
|
or have set a custom 'announce-host'",
|
|
address
|
|
);
|
|
println!("\n\n");
|
|
}
|
|
|
|
fn special_addresses() -> Vec<&'static str> {
|
|
vec!["localhost", "127.0.0.1", "0.0.0.0", "::1", "[::1]"]
|
|
}
|
|
|
|
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 special_addresses().contains(&listening_ip_string.as_ref()) {
|
|
show_binding_warning(listening_ip_string);
|
|
}
|
|
|
|
println!(
|
|
"Directory server [presence]: {}",
|
|
config.get_presence_directory_server()
|
|
);
|
|
println!(
|
|
"Directory server [metrics]: {}",
|
|
config.get_metrics_directory_server()
|
|
);
|
|
|
|
println!(
|
|
"Listening for incoming packets on {}",
|
|
config.get_listening_address()
|
|
);
|
|
println!(
|
|
"Announcing the following socket address: {}",
|
|
config.get_announce_address()
|
|
);
|
|
|
|
MixNode::new(config).run();
|
|
}
|