healthchecker no longer pulling entire topology itself
This commit is contained in:
@@ -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<HealthCheckResult, HealthCheckerError> {
|
||||
pub async fn do_check<T: NymTopology>(
|
||||
&self,
|
||||
current_topology: &T,
|
||||
) -> Result<HealthCheckResult, HealthCheckerError> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ impl HealthCheckResult {
|
||||
self.0.sort();
|
||||
}
|
||||
|
||||
fn zero_score<T: NymTopology>(topology: T) -> Self {
|
||||
fn zero_score<T: NymTopology>(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<T, IDPair, Priv, Pub>(
|
||||
topology: T,
|
||||
topology: &T,
|
||||
iterations: usize,
|
||||
resolution_timeout: Duration,
|
||||
identity_keys: &IDPair,
|
||||
|
||||
Reference in New Issue
Block a user