Skip to content

Commit f88609f

Browse files
mmsinclairjstuczyn
authored andcommitted
NS API: clamp load to offline when score is offline and add mixnet_score field to preformance_v2 (#6076)
* ns-api: when `score` is `Offline`, clamp `load` to `Offline` * ns-api: bump version * ns-api: add mixnet score field to performance_v2 struct --------- Co-authored-by: Mark Sinclair <[email protected]>
1 parent 2f1b30c commit f88609f

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nym-node-status-api/nym-node-status-api/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[package]
55
name = "nym-node-status-api"
6-
version = "4.0.5"
6+
version = "4.0.6"
77
authors.workspace = true
88
repository.workspace = true
99
homepage.workspace = true

nym-node-status-api/nym-node-status-api/src/http/models.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub struct Location {
7878
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema, EnumString)]
7979
#[serde(rename_all = "snake_case")]
8080
#[strum(serialize_all = "snake_case")]
81+
#[derive(PartialEq)]
8182
pub enum ScoreValue {
8283
Offline,
8384
Low,
@@ -89,6 +90,7 @@ pub enum ScoreValue {
8990
pub struct DVpnGatewayPerformance {
9091
last_updated_utc: String,
9192
score: ScoreValue,
93+
mixnet_score: ScoreValue,
9294
load: ScoreValue,
9395
uptime_percentage_last_24_hours: f32,
9496
}
@@ -293,10 +295,20 @@ impl DVpnGateway {
293295
});
294296

295297
tracing::info!("🌈 gateway probe parsed: {:?}", parsed);
298+
let mixnet_score = calculate_mixnet_score(&gateway);
299+
let score = calculate_score(&gateway, &parsed);
300+
let mut load = calculate_load(&parsed);
301+
302+
// clamp the load value to offline, when the score is offline
303+
if score == ScoreValue::Offline {
304+
load = ScoreValue::Offline;
305+
}
306+
296307
let performance_v2 = DVpnGatewayPerformance {
297308
last_updated_utc: last_updated_utc.to_string(),
298-
load: calculate_load(&parsed),
299-
score: calculate_score(&gateway, &parsed),
309+
load,
310+
score,
311+
mixnet_score,
300312

301313
// the network monitor's measure is a good proxy for node uptime, it can be improved in the future
302314
uptime_percentage_last_24_hours: network_monitor_performance_mixnet_mode,
@@ -353,6 +365,21 @@ impl DVpnGateway {
353365
}
354366
}
355367

368+
/// calculates the gateway probe score for mixnet mode
369+
fn calculate_mixnet_score(gateway: &Gateway) -> ScoreValue {
370+
let mixnet_performance = gateway.performance as f64 / 100.0;
371+
372+
if mixnet_performance > 0.8 {
373+
ScoreValue::High
374+
} else if mixnet_performance > 0.6 {
375+
ScoreValue::Medium
376+
} else if mixnet_performance > 0.1 {
377+
ScoreValue::Low
378+
} else {
379+
ScoreValue::Offline
380+
}
381+
}
382+
356383
/// calculates a visual score for the gateway
357384
fn calculate_score(gateway: &Gateway, probe_outcome: &LastProbeResult) -> ScoreValue {
358385
let mixnet_performance = gateway.performance as f64 / 100.0;

0 commit comments

Comments
 (0)