From 05ca3e147fb449e8e4f727a07e665bba951d46b9 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Mon, 13 Jan 2020 15:26:12 +0000 Subject: [PATCH] Using the new updated healthchecker --- Cargo.lock | 2 + validator/Cargo.toml | 1 + .../src/validator/health_check/result.rs | 39 ++++++++++++------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f59444f0b0..6fb52a71bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1397,12 +1397,14 @@ dependencies = [ "directory-client", "dotenv", "futures 0.3.1", + "itertools", "log", "mix-client", "pretty_env_logger", "provider-client", "serde", "serde_derive", + "sfw-provider-requests", "sphinx", "tokio 0.2.9", "toml", diff --git a/validator/Cargo.toml b/validator/Cargo.toml index cf265f2bb1..f036be7f8b 100644 --- a/validator/Cargo.toml +++ b/validator/Cargo.toml @@ -26,6 +26,7 @@ crypto = { path = "../common/crypto" } directory-client = { path = "../clients/directory-client" } mix-client = { path = "../clients/mix-client" } provider-client = { path = "../clients/provider-client" } +sfw-provider-requests = { path = "../sfw-provider/sfw-provider-requests" } topology = {path = "../common/topology" } ## will be moved to proper dependencies once released diff --git a/validator/src/validator/health_check/result.rs b/validator/src/validator/health_check/result.rs index e850c093e0..6460f68027 100644 --- a/validator/src/validator/health_check/result.rs +++ b/validator/src/validator/health_check/result.rs @@ -1,9 +1,10 @@ -use crate::validator::health_check::path_check::PathChecker; +use crate::validator::health_check::path_check::{PathChecker, PathStatus}; use crate::validator::health_check::score::NodeScore; use crypto::identity::{DummyMixIdentityKeyPair, MixnetIdentityKeyPair}; -use log::{debug, warn}; +use log::{debug, info, warn}; use std::collections::HashMap; use std::fmt::{Error, Formatter}; +use std::time::Duration; use topology::NymTopology; #[derive(Debug)] @@ -69,24 +70,36 @@ impl HealthCheckResult { let providers = topology.get_mix_provider_nodes(); let mut path_checker = PathChecker::new(providers, ephemeral_keys).await; - - // do it as many times is specified in config for i in 0..iterations { debug!("running healthcheck iteration {} / {}", i + 1, iterations); for path in &all_paths { - let path_status = path_checker.check_path(&path).await; + path_checker.send_test_packet(&path, i as u8).await; + // increase sent count for each node for node in path { - // if value doesn't exist, something extremely weird must have happened - let current_score = score_map.get_mut(&node.pub_key.0); - if current_score.is_none() { - return Self::zero_score(topology); - } - let current_score = current_score.unwrap(); - current_score.increase_packet_count(path_status); + let current_node_score = score_map.get_mut(&node.pub_key.0).unwrap(); + current_node_score.increase_sent_packet_count(); } } } - HealthCheckResult(score_map.drain().map(|(_, v)| v).collect()) + info!( + "waiting {:?} for pending requests to resolve", + resolution_timeout + ); + tokio::time::delay_for(resolution_timeout).await; + path_checker.resolve_pending_checks().await; + + let all_statuses = path_checker.get_all_statuses(); + for (path_key, status) in all_statuses.into_iter() { + let node_keys = PathChecker::path_key_to_node_keys(path_key); + for node in node_keys { + if status == PathStatus::Healthy { + let current_node_score = score_map.get_mut(&node).unwrap(); + current_node_score.increase_received_packet_count(); + } + } + } + + HealthCheckResult(score_map.into_iter().map(|(_, v)| v).collect()) } }