Updated configs and args with location

This commit is contained in:
Jedrzej Stuczynski
2020-03-13 16:34:06 +00:00
parent 78e1f916f2
commit ab5656ce94
19 changed files with 140 additions and 1 deletions
+6
View File
@@ -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")
+4
View File
@@ -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
}
+6
View File
@@ -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")
+20
View File
@@ -91,6 +91,11 @@ impl Config {
self
}
pub fn with_location<S: Into<String>>(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<S: Into<String>>(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()
+6
View File
@@ -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 }}
+1
View File
@@ -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(),
+4
View File
@@ -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,
+6
View File
@@ -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")
+4
View File
@@ -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
}
+6
View File
@@ -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")
+20
View File
@@ -108,6 +108,11 @@ impl Config {
self
}
pub fn with_location<S: Into<String>>(mut self, location: S) -> Self {
self.provider.location = location.into();
self
}
pub fn with_mix_listening_host<S: Into<String>>(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(),
+6
View File
@@ -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 }}"
+1
View File
@@ -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(),
+6
View File
@@ -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(),
+6
View File
@@ -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")
+4
View File
@@ -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
}
+6
View File
@@ -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")
+22 -1
View File
@@ -98,11 +98,21 @@ impl Config {
self
}
pub fn with_location<S: Into<String>>(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(),
}
}
+6
View File
@@ -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.