From ab5656ce94cf1ee769ad45fe4737f6f32abda4e8 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Fri, 13 Mar 2020 16:34:06 +0000 Subject: [PATCH] Updated configs and args with location --- mixnode/src/commands/init.rs | 6 ++++++ mixnode/src/commands/mod.rs | 4 ++++ mixnode/src/commands/run.rs | 6 ++++++ mixnode/src/config/mod.rs | 20 ++++++++++++++++++++ mixnode/src/config/template.rs | 6 ++++++ mixnode/src/node/mod.rs | 1 + mixnode/src/node/presence.rs | 4 ++++ sfw-provider/src/commands/init.rs | 6 ++++++ sfw-provider/src/commands/mod.rs | 4 ++++ sfw-provider/src/commands/run.rs | 6 ++++++ sfw-provider/src/config/mod.rs | 20 ++++++++++++++++++++ sfw-provider/src/config/template.rs | 6 ++++++ sfw-provider/src/provider/mod.rs | 1 + sfw-provider/src/provider/presence.rs | 6 ++++++ validator/src/commands/init.rs | 6 ++++++ validator/src/commands/mod.rs | 4 ++++ validator/src/commands/run.rs | 6 ++++++ validator/src/config/mod.rs | 23 ++++++++++++++++++++++- validator/src/config/template.rs | 6 ++++++ 19 files changed, 140 insertions(+), 1 deletion(-) diff --git a/mixnode/src/commands/init.rs b/mixnode/src/commands/init.rs index b23b631e94..52400d206d 100644 --- a/mixnode/src/commands/init.rs +++ b/mixnode/src/commands/init.rs @@ -15,6 +15,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .takes_value(true) .required(true), ) + .arg( + Arg::with_name("location") + .long("location") + .help("Optional geographical location of this node") + .takes_value(true), + ) .arg( Arg::with_name("layer") .long("layer") diff --git a/mixnode/src/commands/mod.rs b/mixnode/src/commands/mod.rs index 0363dcbd57..630390f19b 100644 --- a/mixnode/src/commands/mod.rs +++ b/mixnode/src/commands/mod.rs @@ -41,5 +41,9 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi config = config.with_announce_port(announce_port.unwrap()); } + if let Some(location) = matches.value_of("location") { + config = config.with_location(location); + } + config } diff --git a/mixnode/src/commands/run.rs b/mixnode/src/commands/run.rs index 42baaffe01..30830a23cd 100644 --- a/mixnode/src/commands/run.rs +++ b/mixnode/src/commands/run.rs @@ -15,6 +15,12 @@ pub fn command_args<'a, 'b>() -> App<'a, 'b> { .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") diff --git a/mixnode/src/config/mod.rs b/mixnode/src/config/mod.rs index 8fc051917b..e69c7a3431 100644 --- a/mixnode/src/config/mod.rs +++ b/mixnode/src/config/mod.rs @@ -91,6 +91,11 @@ impl Config { self } + pub fn with_location>(mut self, location: S) -> Self { + self.mixnode.location = location.into(); + self + } + // if you want to use distinct servers for metrics and presence // you need to do so in the config.toml file. pub fn with_custom_directory>(mut self, directory_server: S) -> Self { @@ -180,6 +185,10 @@ impl Config { self.config_directory().join(Self::config_file_name()) } + pub fn get_location(&self) -> String { + self.mixnode.location.clone() + } + pub fn get_private_sphinx_key_file(&self) -> PathBuf { self.mixnode.private_sphinx_key_file.clone() } @@ -231,6 +240,12 @@ pub struct MixNode { /// ID specifies the human readable ID of this particular mixnode. id: String, + /// Completely optional value specifying geographical location of this particular node. + /// Currently it's used entirely for debug purposes, as there are no mechanisms implemented + /// to verify correctness of the information provided. However, feel free to fill in + /// this field with as much accuracy as you wish to share. + location: String, + /// Layer of this particular mixnode determining its position in the network. layer: u64, @@ -264,12 +279,17 @@ impl MixNode { fn default_public_sphinx_key_file(id: &str) -> PathBuf { Config::default_data_directory(Some(id)).join("public_sphinx.pem") } + + fn default_location() -> String { + "unknown".into() + } } impl Default for MixNode { fn default() -> Self { MixNode { id: "".to_string(), + location: Self::default_location(), layer: 0, listening_address: format!("0.0.0.0:{}", DEFAULT_LISTENING_PORT) .parse() diff --git a/mixnode/src/config/template.rs b/mixnode/src/config/template.rs index 78ec91fa02..00af93298e 100644 --- a/mixnode/src/config/template.rs +++ b/mixnode/src/config/template.rs @@ -13,6 +13,12 @@ pub(crate) fn config_template() -> &'static str { # Human readable ID of this particular mixnode. id = "{{ mixnode.id }}" +# Completely optional value specifying geographical location of this particular node. +# Currently it's used entirely for debug purposes, as there are no mechanisms implemented +# to verify correctness of the information provided. However, feel free to fill in +# this field with as much accuracy as you wish to share. +location = "{{ mixnode.location }}" + # Layer of this particular mixnode determining its position in the network. layer = {{ mixnode.layer }} diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index c73aade059..4ba30307da 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -46,6 +46,7 @@ impl MixNode { fn start_presence_notifier(&self) { info!("Starting presence notifier..."); let notifier_config = presence::NotifierConfig::new( + self.config.get_location(), self.config.get_presence_directory_server(), self.config.get_announce_address(), self.sphinx_keypair.public_key().to_base58_string(), diff --git a/mixnode/src/node/presence.rs b/mixnode/src/node/presence.rs index 0a4f209d16..f5f650cdf9 100644 --- a/mixnode/src/node/presence.rs +++ b/mixnode/src/node/presence.rs @@ -8,6 +8,7 @@ use tokio::runtime::Handle; use tokio::task::JoinHandle; pub struct NotifierConfig { + location: String, directory_server: String, announce_host: String, pub_key_string: String, @@ -17,6 +18,7 @@ pub struct NotifierConfig { impl NotifierConfig { pub fn new( + location: String, directory_server: String, announce_host: String, pub_key_string: String, @@ -24,6 +26,7 @@ impl NotifierConfig { sending_delay: Duration, ) -> Self { NotifierConfig { + location, directory_server, announce_host, pub_key_string, @@ -46,6 +49,7 @@ impl Notifier { }; let net_client = directory_client::Client::new(directory_client_cfg); let presence = MixNodePresence { + location: config.location, host: config.announce_host, pub_key: config.pub_key_string, layer: config.layer, diff --git a/sfw-provider/src/commands/init.rs b/sfw-provider/src/commands/init.rs index f87e189c51..1d9ecf9bfa 100644 --- a/sfw-provider/src/commands/init.rs +++ b/sfw-provider/src/commands/init.rs @@ -15,6 +15,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .takes_value(true) .required(true), ) + .arg( + Arg::with_name("location") + .long("location") + .help("Optional geographical location of this provider") + .takes_value(true), + ) .arg( Arg::with_name("mix-host") .long("mix-host") diff --git a/sfw-provider/src/commands/mod.rs b/sfw-provider/src/commands/mod.rs index a9ae6e848b..6d4c4b1481 100644 --- a/sfw-provider/src/commands/mod.rs +++ b/sfw-provider/src/commands/mod.rs @@ -83,5 +83,9 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi config = config.with_custom_clients_ledger(clients_ledger); } + if let Some(location) = matches.value_of("location") { + config = config.with_location(location); + } + config } diff --git a/sfw-provider/src/commands/run.rs b/sfw-provider/src/commands/run.rs index 123398e6db..090ca3a00c 100644 --- a/sfw-provider/src/commands/run.rs +++ b/sfw-provider/src/commands/run.rs @@ -15,6 +15,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .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") diff --git a/sfw-provider/src/config/mod.rs b/sfw-provider/src/config/mod.rs index 5be3ac631f..96ba4d8baa 100644 --- a/sfw-provider/src/config/mod.rs +++ b/sfw-provider/src/config/mod.rs @@ -108,6 +108,11 @@ impl Config { self } + pub fn with_location>(mut self, location: S) -> Self { + self.provider.location = location.into(); + self + } + pub fn with_mix_listening_host>(mut self, host: S) -> Self { // see if the provided `host` is just an ip address or ip:port let host = host.into(); @@ -277,6 +282,10 @@ impl Config { self.config_directory().join(Self::config_file_name()) } + pub fn get_location(&self) -> String { + self.provider.location.clone() + } + pub fn get_private_sphinx_key_file(&self) -> PathBuf { self.provider.private_sphinx_key_file.clone() } @@ -332,6 +341,12 @@ pub struct Provider { /// ID specifies the human readable ID of this particular provider. id: String, + /// Completely optional value specifying geographical location of this particular provider. + /// Currently it's used entirely for debug purposes, as there are no mechanisms implemented + /// to verify correctness of the information provided. However, feel free to fill in + /// this field with as much accuracy as you wish to share. + location: String, + /// Path to file containing private sphinx key. private_sphinx_key_file: PathBuf, @@ -351,12 +366,17 @@ impl Provider { fn default_public_sphinx_key_file(id: &str) -> PathBuf { Config::default_data_directory(Some(id)).join("public_sphinx.pem") } + + fn default_location() -> String { + "unknown".into() + } } impl Default for Provider { fn default() -> Self { Provider { id: "".to_string(), + location: Self::default_location(), private_sphinx_key_file: Default::default(), public_sphinx_key_file: Default::default(), nym_root_directory: Config::default_root_directory(), diff --git a/sfw-provider/src/config/template.rs b/sfw-provider/src/config/template.rs index 64208c8ab7..b313cd09fc 100644 --- a/sfw-provider/src/config/template.rs +++ b/sfw-provider/src/config/template.rs @@ -13,6 +13,12 @@ pub(crate) fn config_template() -> &'static str { # Human readable ID of this particular service provider. id = "{{ provider.id }}" +# Completely optional value specifying geographical location of this particular node. +# Currently it's used entirely for debug purposes, as there are no mechanisms implemented +# to verify correctness of the information provided. However, feel free to fill in +# this field with as much accuracy as you wish to share. +location = "{{ provider.location }}" + # Path to file containing private sphinx key. private_sphinx_key_file = "{{ provider.private_sphinx_key_file }}" diff --git a/sfw-provider/src/provider/mod.rs b/sfw-provider/src/provider/mod.rs index e107150908..8c78dee584 100644 --- a/sfw-provider/src/provider/mod.rs +++ b/sfw-provider/src/provider/mod.rs @@ -45,6 +45,7 @@ impl ServiceProvider { fn start_presence_notifier(&self) { info!("Starting presence notifier..."); let notifier_config = presence::NotifierConfig::new( + self.config.get_location(), self.config.get_presence_directory_server(), self.config.get_mix_announce_address(), self.config.get_clients_announce_address(), diff --git a/sfw-provider/src/provider/presence.rs b/sfw-provider/src/provider/presence.rs index c8ff6dcb3a..b67020a1e5 100644 --- a/sfw-provider/src/provider/presence.rs +++ b/sfw-provider/src/provider/presence.rs @@ -9,6 +9,7 @@ use tokio::runtime::Handle; use tokio::task::JoinHandle; pub struct NotifierConfig { + location: String, directory_server: String, mix_announce_host: String, clients_announce_host: String, @@ -18,6 +19,7 @@ pub struct NotifierConfig { impl NotifierConfig { pub fn new( + location: String, directory_server: String, mix_announce_host: String, clients_announce_host: String, @@ -25,6 +27,7 @@ impl NotifierConfig { sending_delay: Duration, ) -> Self { NotifierConfig { + location, directory_server, mix_announce_host, clients_announce_host, @@ -35,6 +38,7 @@ impl NotifierConfig { } pub struct Notifier { + location: String, net_client: directory_client::Client, client_ledger: ClientLedger, sending_delay: Duration, @@ -53,6 +57,7 @@ impl Notifier { Notifier { client_ledger, net_client, + location: config.location, client_listener: config.clients_announce_host, mixnet_listener: config.mix_announce_host, pub_key_string: config.pub_key_string, @@ -62,6 +67,7 @@ impl Notifier { async fn make_presence(&self) -> MixProviderPresence { MixProviderPresence { + location: self.location.clone(), client_listener: self.client_listener.clone(), mixnet_listener: self.mixnet_listener.clone(), pub_key: self.pub_key_string.clone(), diff --git a/validator/src/commands/init.rs b/validator/src/commands/init.rs index c741dca5ee..4cce4199ea 100644 --- a/validator/src/commands/init.rs +++ b/validator/src/commands/init.rs @@ -12,6 +12,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .takes_value(true) .required(true), ) + .arg( + Arg::with_name("location") + .long("location") + .help("Optional geographical location of this node") + .takes_value(true), + ) .arg( Arg::with_name("directory") .long("directory") diff --git a/validator/src/commands/mod.rs b/validator/src/commands/mod.rs index 60ec03984d..0533e08998 100644 --- a/validator/src/commands/mod.rs +++ b/validator/src/commands/mod.rs @@ -9,5 +9,9 @@ pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Confi config = config.with_custom_directory(directory); } + if let Some(location) = matches.value_of("location") { + config = config.with_location(location); + } + config } diff --git a/validator/src/commands/run.rs b/validator/src/commands/run.rs index 8f06e0e2d9..d47c59e0b1 100644 --- a/validator/src/commands/run.rs +++ b/validator/src/commands/run.rs @@ -15,6 +15,12 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> { .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") diff --git a/validator/src/config/mod.rs b/validator/src/config/mod.rs index e23c6f86c0..5ee4f3e2c4 100644 --- a/validator/src/config/mod.rs +++ b/validator/src/config/mod.rs @@ -98,11 +98,21 @@ impl Config { self } + pub fn with_location>(mut self, location: S) -> Self { + self.validator.location = location.into(); + self + } + // getters pub fn get_config_file_save_location(&self) -> PathBuf { self.config_directory().join(Self::config_file_name()) } + #[allow(dead_code)] + pub fn get_location(&self) -> String { + self.validator.location.clone() + } + pub fn get_mix_mining_directory_server(&self) -> String { self.mix_mining.directory_server.clone() } @@ -137,17 +147,28 @@ pub struct Validator { /// ID specifies the human readable ID of this particular validator. id: String, + /// Completely optional value specifying geographical location of this particular node. + /// Currently it's used entirely for debug purposes, as there are no mechanisms implemented + /// to verify correctness of the information provided. However, feel free to fill in + /// this field with as much accuracy as you wish to share. + location: String, + /// nym_home_directory specifies absolute path to the home nym MixNodes directory. /// It is expected to use default value and hence .toml file should not redefine this field. nym_root_directory: PathBuf, } -impl Validator {} +impl Validator { + fn default_location() -> String { + "unknown".into() + } +} impl Default for Validator { fn default() -> Self { Validator { id: "".to_string(), + location: Self::default_location(), nym_root_directory: Config::default_root_directory(), } } diff --git a/validator/src/config/template.rs b/validator/src/config/template.rs index 3e8b0c1f82..ad2c0b9904 100644 --- a/validator/src/config/template.rs +++ b/validator/src/config/template.rs @@ -13,6 +13,12 @@ pub(crate) fn config_template() -> &'static str { # Human readable ID of this particular validator. id = "{{ validator.id }}" +# Completely optional value specifying geographical location of this particular node. +# Currently it's used entirely for debug purposes, as there are no mechanisms implemented +# to verify correctness of the information provided. However, feel free to fill in +# this field with as much accuracy as you wish to share. +location = "{{ validator.location }}" + ##### advanced configuration options ##### # nym_home_directory specifies absolute path to the home nym validators directory.