Additional optional arguments for client init

This commit is contained in:
Jedrzej Stuczynski
2020-01-31 16:32:32 +00:00
parent 9e0735498b
commit a4d500f0f5
2 changed files with 33 additions and 45 deletions
+19
View File
@@ -1,4 +1,5 @@
use crate::config::persistance::pathfinder::ClientPathfinder;
use crate::config::SocketType;
use clap::ArgMatches;
use config::NymConfig;
use crypto::identity::MixIdentityKeyPair;
@@ -10,10 +11,26 @@ pub fn execute(matches: &ArgMatches) {
let id = matches.value_of("id").unwrap(); // required for now
let mut config = crate::config::Config::new(id);
if let Some(directory) = matches.value_of("directory") {
config = config.with_custom_directory(directory);
}
if let Some(provider_id) = matches.value_of("provider") {
config = config.with_provider_id(provider_id);
}
if let Some(socket_type) = matches.value_of("socket-type") {
config = config.with_socket(SocketType::from_string(socket_type));
}
if let Some(port) = matches.value_of("port").map(|port| port.parse::<u16>()) {
if let Err(err) = port {
// if port was overridden, it must be parsable
panic!("Invalid port value provided - {:?}", err);
}
config = config.with_port(port.unwrap());
}
let mix_identity_keys = MixIdentityKeyPair::new();
let pathfinder = ClientPathfinder::new_from_config(&config);
@@ -23,6 +40,8 @@ pub fn execute(matches: &ArgMatches) {
.expect("Failed to save identity keys");
println!("Saved mixnet identity keypair");
// TODO: perform provider registration here
let config_save_location = config.get_config_file_save_location();
config
.save_to_file(None)
+14 -45
View File
@@ -28,52 +28,21 @@ fn main() {
.help("Id of the provider we have preference to connect to. If left empty, a random provider will be chosen.")
.takes_value(true)
)
)
.subcommand(
SubCommand::with_name("tcpsocket")
.about("Run Nym client that listens for bytes on a TCP socket")
.arg(
Arg::with_name("port")
.short("p")
.long("port")
.help("Port for TCP socket to listen on")
.takes_value(true)
.required(true),
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(
Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to run.")
.arg(Arg::with_name("socket-type")
.long("socket-type")
.help("Type of socket to use (TCP, WebSocket or None) in all subsequent runs")
.takes_value(true)
.required(true)
)
)
.subcommand(
SubCommand::with_name("websocket")
.about("Run Nym client that listens on a websocket")
.arg(
Arg::with_name("port")
.short("p")
.long("port")
.help("Port for websocket to listen on")
.takes_value(true)
)
.arg(
Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("id")
.long("id")
.help("Id of the nym-mixnet-client we want to run.")
.arg(Arg::with_name("port")
.short("p")
.long("port")
.help("Port for the socket (if applicable) to listen on in all subsequent runs")
.takes_value(true)
.required(true)
)
)
.subcommand(
@@ -92,9 +61,9 @@ fn main() {
.takes_value(true)
)
.arg(Arg::with_name("directory")
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
.long("directory")
.help("Address of the directory server the client is getting topology from")
.takes_value(true),
)
.arg(Arg::with_name("provider")
.long("provider")