diff --git a/mixnode/src/node/mod.rs b/mixnode/src/node/mod.rs index a2546d279a..f6e151803d 100644 --- a/mixnode/src/node/mod.rs +++ b/mixnode/src/node/mod.rs @@ -1,4 +1,5 @@ use crate::mix_peer::MixPeer; +use crate::node; use crate::node::metrics::MetricsReporter; use curve25519_dalek::montgomery::MontgomeryPoint; use curve25519_dalek::scalar::Scalar; @@ -214,7 +215,7 @@ impl MixNode { } } - pub fn start(&self) -> Result<(), Box> { + pub fn start(&self, config: node::Config) -> Result<(), Box> { // Create the runtime, probably later move it to MixNode itself? let mut rt = Runtime::new()?; @@ -227,6 +228,11 @@ impl MixNode { let pub_key_str = base64::encode_config(&self.public_key.to_bytes().to_vec(), base64::URL_SAFE); + rt.spawn({ + let presence_notifier = presence::Notifier::new(&config); + presence_notifier.run() + }); + let metrics = MetricsReporter::new().add_arc_mutex(); rt.spawn(MetricsReporter::run_received_metrics_control( metrics.clone(), diff --git a/mixnode/src/node/presence.rs b/mixnode/src/node/presence.rs index 18fcd66136..483fee0981 100644 --- a/mixnode/src/node/presence.rs +++ b/mixnode/src/node/presence.rs @@ -36,10 +36,12 @@ impl Notifier { .unwrap(); } - pub fn run(&self) { + pub async fn run(self) { + let delay_duration = Duration::from_secs(5); + loop { self.notify(); - thread::sleep(Duration::from_secs(5)); + tokio::time::delay_for(delay_duration).await; } } } diff --git a/mixnode/src/node/runner.rs b/mixnode/src/node/runner.rs index 93b16381ab..8f120cc0a7 100644 --- a/mixnode/src/node/runner.rs +++ b/mixnode/src/node/runner.rs @@ -1,11 +1,8 @@ use crate::banner; use crate::node; -use crate::node::presence; use crate::node::MixNode; use clap::ArgMatches; - use std::net::ToSocketAddrs; -use std::thread; fn print_binding_warning(address: &str) { println!("\n##### WARNING #####"); @@ -29,11 +26,7 @@ pub fn start(matches: &ArgMatches) { ); let mix = MixNode::new(&config); - thread::spawn(move || { - let notifier = presence::Notifier::new(&config); - notifier.run(); - }); - mix.start().unwrap(); + mix.start(config).unwrap(); } fn new_config(matches: &ArgMatches) -> node::Config {