From eb3aa0baf18eb380f41b9025f207d7e35bd867f4 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Tue, 28 Jan 2020 18:06:59 +0000 Subject: [PATCH] healthchecker no longer pulling entire topology itself --- common/healthcheck/src/lib.rs | 51 ++++++++------------------------ common/healthcheck/src/result.rs | 4 +-- 2 files changed, 14 insertions(+), 41 deletions(-) diff --git a/common/healthcheck/src/lib.rs b/common/healthcheck/src/lib.rs index b95eefd454..7cd97692db 100644 --- a/common/healthcheck/src/lib.rs +++ b/common/healthcheck/src/lib.rs @@ -6,7 +6,7 @@ use log::{debug, error, info, trace}; use std::fmt::{Error, Formatter}; use std::marker::PhantomData; use std::time::Duration; -use topology::NymTopologyError; +use topology::{NymTopology, NymTopologyError}; pub mod config; mod path_check; @@ -42,8 +42,6 @@ where Priv: MixnetIdentityPrivateKey, Pub: MixnetIdentityPublicKey, { - directory_client: directory_client::Client, - interval: Duration, num_test_packets: usize, resolution_timeout: Duration, identity_keypair: IDPair, @@ -58,17 +56,14 @@ where Priv: crypto::identity::MixnetIdentityPrivateKey, Pub: crypto::identity::MixnetIdentityPublicKey, { - pub fn new(config: config::HealthCheck, identity_keypair: IDPair) -> Self { - debug!( - "healthcheck will be using the following directory server: {:?}", - config.directory_server - ); - let directory_client_config = directory_client::Config::new(config.directory_server); + pub fn new( + resolution_timeout_f64: f64, + num_test_packets: usize, + identity_keypair: IDPair, + ) -> Self { HealthChecker { - directory_client: directory_client::Client::new(directory_client_config), - interval: Duration::from_secs_f64(config.interval), - resolution_timeout: Duration::from_secs_f64(config.resolution_timeout), - num_test_packets: config.num_test_packets, + resolution_timeout: Duration::from_secs_f64(resolution_timeout_f64), + num_test_packets, identity_keypair, _phantom_private: PhantomData, @@ -76,18 +71,12 @@ where } } - pub async fn do_check(&self) -> Result { + pub async fn do_check( + &self, + current_topology: &T, + ) -> Result { trace!("going to perform a healthcheck!"); - let current_topology = match self.directory_client.presence_topology.get() { - Ok(topology) => topology, - Err(err) => { - error!("failed to obtain topology - {:?}", err); - return Err(HealthCheckerError::FailedToObtainTopologyError); - } - }; - trace!("current topology: {:?}", current_topology); - let mut healthcheck_result = HealthCheckResult::calculate( current_topology, self.num_test_packets, @@ -98,20 +87,4 @@ where healthcheck_result.sort_scores(); Ok(healthcheck_result) } - - pub async fn run(self) -> Result<(), HealthCheckerError> { - debug!( - "healthcheck will run every {:?} and will send {} packets to each node", - self.interval, self.num_test_packets - ); - - loop { - match self.do_check().await { - Ok(health) => info!("current network health: \n{}", health), - Err(err) => error!("failed to perform healthcheck - {:?}", err), - }; - - tokio::time::delay_for(self.interval).await; - } - } } diff --git a/common/healthcheck/src/result.rs b/common/healthcheck/src/result.rs index 83d1f8778c..9eda0885f5 100644 --- a/common/healthcheck/src/result.rs +++ b/common/healthcheck/src/result.rs @@ -27,7 +27,7 @@ impl HealthCheckResult { self.0.sort(); } - fn zero_score(topology: T) -> Self { + fn zero_score(topology: &T) -> Self { warn!("The network is unhealthy, could not send any packets - returning zero score!"); let mixes = topology.mix_nodes(); let providers = topology.providers(); @@ -103,7 +103,7 @@ impl HealthCheckResult { } pub async fn calculate( - topology: T, + topology: &T, iterations: usize, resolution_timeout: Duration, identity_keys: &IDPair,