Presence reporter responsible for starting own task
This commit is contained in:
@@ -239,6 +239,7 @@ impl MixNode {
|
||||
let mut rt = Runtime::new()?;
|
||||
|
||||
// Spawn Tokio tasks as necessary for node functionality
|
||||
pub fn start_presence_notifier(&self) {
|
||||
let notifier_config = presence::NotifierConfig::new(
|
||||
self.config.get_presence_directory_server(),
|
||||
self.config.get_announce_address(),
|
||||
@@ -246,10 +247,8 @@ impl MixNode {
|
||||
self.config.get_layer(),
|
||||
self.config.get_presence_sending_delay(),
|
||||
);
|
||||
rt.spawn({
|
||||
let presence_notifier = presence::Notifier::new(notifier_config);
|
||||
presence_notifier.run()
|
||||
});
|
||||
presence::Notifier::new(notifier_config).start(self.runtime.handle())
|
||||
}
|
||||
|
||||
let metrics = MetricsReporter::new().add_arc_mutex();
|
||||
rt.spawn(MetricsReporter::run_received_metrics_control(
|
||||
|
||||
@@ -2,8 +2,10 @@ use crate::built_info;
|
||||
use directory_client::presence::mixnodes::MixNodePresence;
|
||||
use directory_client::requests::presence_mixnodes_post::PresenceMixNodesPoster;
|
||||
use directory_client::DirectoryClient;
|
||||
use futures::task::SpawnExt;
|
||||
use log::{debug, error};
|
||||
use std::time::Duration;
|
||||
use tokio::runtime::Handle;
|
||||
|
||||
pub struct NotifierConfig {
|
||||
directory_server: String,
|
||||
@@ -64,10 +66,14 @@ impl Notifier {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(self) {
|
||||
pub async fn run(&self) {
|
||||
loop {
|
||||
self.notify();
|
||||
tokio::time::delay_for(self.sending_delay).await;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start(self, handle: &Handle) {
|
||||
handle.spawn(async move { self.run() });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user