Defaults in the config + using said fields when starting mixnode
This commit is contained in:
@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::time;
|
||||
|
||||
pub mod persistance;
|
||||
mod template;
|
||||
@@ -12,6 +13,11 @@ mod template;
|
||||
// 'MIXNODE'
|
||||
const DEFAULT_LISTENING_PORT: u16 = 1789;
|
||||
|
||||
// 'DEBUG'
|
||||
// where applicable, the below are defined in milliseconds
|
||||
const DEFAULT_PRESENCE_SENDING_DELAY: u64 = 3000;
|
||||
const DEFAULT_METRICS_SENDING_DELAY: u64 = 3000;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Config {
|
||||
@@ -179,11 +185,16 @@ impl Config {
|
||||
self.debug.presence_directory_server.clone()
|
||||
}
|
||||
|
||||
pub fn get_presence_sending_delay(&self) -> time::Duration {
|
||||
time::Duration::from_millis(self.debug.presence_sending_delay)
|
||||
}
|
||||
|
||||
pub fn get_metrics_directory_server(&self) -> String {
|
||||
self.debug.metrics_directory_server.clone()
|
||||
}
|
||||
|
||||
pub fn get_metrics_sending_delay(&self) -> time::Duration {
|
||||
time::Duration::from_millis(self.debug.metrics_sending_delay)
|
||||
}
|
||||
|
||||
pub fn get_layer(&self) -> u64 {
|
||||
@@ -274,10 +285,16 @@ pub struct Debug {
|
||||
/// Directory server to which the server will be reporting their presence data.
|
||||
presence_directory_server: String,
|
||||
|
||||
/// Delay between each subsequent presence data being sent.
|
||||
presence_sending_delay: u64,
|
||||
|
||||
/// Directory server to which the server will be reporting their metrics data.
|
||||
metrics_directory_server: String,
|
||||
|
||||
/// Delay between each subsequent metrics data being sent.
|
||||
metrics_sending_delay: u64,
|
||||
}
|
||||
|
||||
impl Debug {
|
||||
fn default_directory_server() -> String {
|
||||
#[cfg(feature = "qa")]
|
||||
@@ -288,11 +305,15 @@ impl Debug {
|
||||
"https://directory.nymtech.net".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Debug {
|
||||
fn default() -> Self {
|
||||
Debug {
|
||||
presence_directory_server: Self::default_directory_server(),
|
||||
presence_sending_delay: DEFAULT_PRESENCE_SENDING_DELAY,
|
||||
metrics_directory_server: Self::default_directory_server(),
|
||||
metrics_sending_delay: DEFAULT_METRICS_SENDING_DELAY,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,6 +248,7 @@ impl MixNode {
|
||||
self.config.get_announce_address(),
|
||||
self.sphinx_keypair.public_key().to_base58_string(),
|
||||
self.config.get_layer(),
|
||||
self.config.get_presence_sending_delay(),
|
||||
);
|
||||
rt.spawn({
|
||||
let presence_notifier = presence::Notifier::new(notifier_config);
|
||||
@@ -272,6 +273,7 @@ impl MixNode {
|
||||
metrics,
|
||||
directory_cfg,
|
||||
self.sphinx_keypair.public_key().to_base58_string(),
|
||||
self.config.get_metrics_sending_delay(),
|
||||
));
|
||||
|
||||
// Spawn the root task
|
||||
|
||||
@@ -3,13 +3,12 @@ use directory_client::presence::mixnodes::MixNodePresence;
|
||||
use directory_client::requests::presence_mixnodes_post::PresenceMixNodesPoster;
|
||||
use directory_client::DirectoryClient;
|
||||
use log::{debug, error};
|
||||
use std::time;
|
||||
use std::time::Duration;
|
||||
|
||||
pub struct Notifier {
|
||||
pub net_client: directory_client::Client,
|
||||
presence: MixNodePresence,
|
||||
sending_delay: time::Duration,
|
||||
sending_delay: Duration,
|
||||
}
|
||||
|
||||
pub struct NotifierConfig {
|
||||
@@ -17,7 +16,7 @@ pub struct NotifierConfig {
|
||||
announce_host: String,
|
||||
pub_key_string: String,
|
||||
layer: u64,
|
||||
sending_delay: time::Duration,
|
||||
sending_delay: Duration,
|
||||
}
|
||||
|
||||
impl NotifierConfig {
|
||||
@@ -26,7 +25,7 @@ impl NotifierConfig {
|
||||
announce_host: String,
|
||||
pub_key_string: String,
|
||||
layer: u64,
|
||||
sending_delay: time::Duration,
|
||||
sending_delay: Duration,
|
||||
) -> Self {
|
||||
NotifierConfig {
|
||||
directory_server,
|
||||
@@ -68,7 +67,7 @@ impl Notifier {
|
||||
pub async fn run(self) {
|
||||
loop {
|
||||
self.notify();
|
||||
tokio::time::delay_for(self.sending_delay).await;
|
||||
tokio::delay_for(self.sending_delay).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user