diff --git a/Cargo.lock b/Cargo.lock index bf1fe092e54..7339d676170 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6433,7 +6433,7 @@ dependencies = [ [[package]] name = "nym-node-status-api" -version = "4.0.5" +version = "4.0.6" dependencies = [ "ammonia", "anyhow", diff --git a/nym-node-status-api/nym-node-status-api/Cargo.toml b/nym-node-status-api/nym-node-status-api/Cargo.toml index 5637a214a03..77afe6fc10d 100644 --- a/nym-node-status-api/nym-node-status-api/Cargo.toml +++ b/nym-node-status-api/nym-node-status-api/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-node-status-api" -version = "4.0.5" +version = "4.0.6" authors.workspace = true repository.workspace = true homepage.workspace = true diff --git a/nym-node-status-api/nym-node-status-api/src/http/models.rs b/nym-node-status-api/nym-node-status-api/src/http/models.rs index 74d827aa8a8..9bcd01e6103 100644 --- a/nym-node-status-api/nym-node-status-api/src/http/models.rs +++ b/nym-node-status-api/nym-node-status-api/src/http/models.rs @@ -78,6 +78,7 @@ pub struct Location { #[derive(Debug, Clone, Deserialize, Serialize, ToSchema, EnumString)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] +#[derive(PartialEq)] pub enum ScoreValue { Offline, Low, @@ -89,6 +90,7 @@ pub enum ScoreValue { pub struct DVpnGatewayPerformance { last_updated_utc: String, score: ScoreValue, + mixnet_score: ScoreValue, load: ScoreValue, uptime_percentage_last_24_hours: f32, } @@ -293,10 +295,20 @@ impl DVpnGateway { }); tracing::info!("🌈 gateway probe parsed: {:?}", parsed); + let mixnet_score = calculate_mixnet_score(&gateway); + let score = calculate_score(&gateway, &parsed); + let mut load = calculate_load(&parsed); + + // clamp the load value to offline, when the score is offline + if score == ScoreValue::Offline { + load = ScoreValue::Offline; + } + let performance_v2 = DVpnGatewayPerformance { last_updated_utc: last_updated_utc.to_string(), - load: calculate_load(&parsed), - score: calculate_score(&gateway, &parsed), + load, + score, + mixnet_score, // the network monitor's measure is a good proxy for node uptime, it can be improved in the future uptime_percentage_last_24_hours: network_monitor_performance_mixnet_mode, @@ -353,6 +365,21 @@ impl DVpnGateway { } } +/// calculates the gateway probe score for mixnet mode +fn calculate_mixnet_score(gateway: &Gateway) -> ScoreValue { + let mixnet_performance = gateway.performance as f64 / 100.0; + + if mixnet_performance > 0.8 { + ScoreValue::High + } else if mixnet_performance > 0.6 { + ScoreValue::Medium + } else if mixnet_performance > 0.1 { + ScoreValue::Low + } else { + ScoreValue::Offline + } +} + /// calculates a visual score for the gateway fn calculate_score(gateway: &Gateway, probe_outcome: &LastProbeResult) -> ScoreValue { let mixnet_performance = gateway.performance as f64 / 100.0;