Moved mix presence reporting from std::thread to tokio task
This commit is contained in:
@@ -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<dyn std::error::Error>> {
|
||||
pub fn start(&self, config: node::Config) -> Result<(), Box<dyn std::error::Error>> {
|
||||
// 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(),
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user