node: adding a config struct and using it to pass args around
This commit is contained in:
+29
-22
@@ -1,9 +1,9 @@
|
||||
use crate::banner;
|
||||
use crate::node;
|
||||
use crate::node::presence;
|
||||
use crate::node::MixNode;
|
||||
use clap::ArgMatches;
|
||||
|
||||
use curve25519_dalek::scalar::Scalar;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::thread;
|
||||
|
||||
@@ -11,6 +11,20 @@ pub fn start(matches: &ArgMatches) {
|
||||
println!("{}", banner());
|
||||
println!("Starting mixnode...");
|
||||
|
||||
let config = new_config(matches);
|
||||
|
||||
// println!("Startup on: {}", config.socket_address);
|
||||
println!("Listening for incoming packets...");
|
||||
|
||||
let mix = MixNode::new(&config);
|
||||
thread::spawn(move || {
|
||||
let notifier = presence::Notifier::new(&config);
|
||||
notifier.run();
|
||||
});
|
||||
mix.start_listening().unwrap();
|
||||
}
|
||||
|
||||
fn new_config(matches: &ArgMatches) -> node::Config {
|
||||
let host = matches.value_of("host").unwrap_or("0.0.0.0");
|
||||
|
||||
let port = match matches.value_of("port").unwrap().parse::<u16>() {
|
||||
@@ -23,17 +37,6 @@ pub fn start(matches: &ArgMatches) {
|
||||
Err(err) => panic!("Invalid layer value provided - {:?}", err),
|
||||
};
|
||||
|
||||
let secret_key: Scalar = match matches.value_of("keyfile") {
|
||||
Some(keyfile) => {
|
||||
// println!("TODO: load keyfile from <{:?}>", keyfile);
|
||||
Default::default()
|
||||
}
|
||||
None => {
|
||||
// println!("TODO: generate fresh sphinx keypair");
|
||||
Default::default()
|
||||
}
|
||||
};
|
||||
|
||||
let is_local = matches.is_present("local");
|
||||
|
||||
let socket_address = (host, port)
|
||||
@@ -42,15 +45,19 @@ pub fn start(matches: &ArgMatches) {
|
||||
.next()
|
||||
.expect("Failed to extract the socket address from the iterator");
|
||||
|
||||
thread::spawn(move || {
|
||||
let notifier = presence::Notifier::new(is_local.clone());
|
||||
notifier.run();
|
||||
});
|
||||
let (secret_key, public_key) = sphinx::crypto::keygen();
|
||||
|
||||
println!("Startup complete on: {}", socket_address);
|
||||
println!("Listening for incoming packets...");
|
||||
// make sure our socket_address is equal to our predefined-hardcoded value
|
||||
// assert_eq!("127.0.0.1:8080", socket_address.to_string());
|
||||
let mix = MixNode::new(socket_address, secret_key, layer);
|
||||
mix.start_listening().unwrap();
|
||||
let directory_server = if is_local {
|
||||
"http://localhost:8080".to_string()
|
||||
} else {
|
||||
"https://directory.nymtech.net".to_string()
|
||||
};
|
||||
|
||||
node::Config {
|
||||
directory_server,
|
||||
layer,
|
||||
public_key,
|
||||
socket_address,
|
||||
secret_key,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user