From d7b069e0e5b6ba84adc835e08d02fa91578f472f Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 18:06:39 +0000 Subject: [PATCH] validator responsible for running healtchecker loop --- validator/src/validator/mod.rs | 40 +++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/validator/src/validator/mod.rs b/validator/src/validator/mod.rs index 6ed56fa42b..26f031fab5 100644 --- a/validator/src/validator/mod.rs +++ b/validator/src/validator/mod.rs @@ -3,9 +3,12 @@ use crypto::identity::{ DummyMixIdentityKeyPair, DummyMixIdentityPrivateKey, DummyMixIdentityPublicKey, MixnetIdentityKeyPair, MixnetIdentityPrivateKey, MixnetIdentityPublicKey, }; +use directory_client::presence::Topology; use healthcheck::HealthChecker; -use log::debug; +use log::{debug, error, info}; +use std::time::Duration; use tokio::runtime::Runtime; +use topology::NymTopology; pub mod config; @@ -16,6 +19,7 @@ where Priv: MixnetIdentityPrivateKey, Pub: MixnetIdentityPublicKey, { + config: Config, #[allow(dead_code)] identity_keypair: IDPair, heath_check: HealthChecker, @@ -30,7 +34,33 @@ impl Validator(&self) { + let healthcheck_interval = Duration::from_secs_f64(self.config.health_check.interval); + debug!("healthcheck will run every {:?}", healthcheck_interval); + + loop { + let full_topology = T::new(self.config.health_check.directory_server.clone()); + let version_filtered_topology = full_topology.filter_node_versions( + crate::built_info::PKG_VERSION, + crate::built_info::PKG_VERSION, + crate::built_info::PKG_VERSION, + ); + + match self.heath_check.do_check(&version_filtered_topology).await { + Ok(health) => info!("current network health: \n{}", health), + Err(err) => error!("failed to perform healthcheck - {:?}", err), + }; + + tokio::time::delay_for(healthcheck_interval).await; } } @@ -39,9 +69,7 @@ impl Validator(); + rt.block_on(health_check_future); } }