From 2e365026b742e298718804bce75b97e154a29d34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Tue, 24 Sep 2024 18:29:00 +0100 Subject: [PATCH] implemented the noise route --- nym-api/nym-api-requests/src/models.rs | 11 ++++++- nym-api/src/nym_contract_cache/cache/data.rs | 21 +------------- nym-api/src/nym_nodes/handlers/mod.rs | 30 +++++++++++++++++++- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/nym-api/nym-api-requests/src/models.rs b/nym-api/nym-api-requests/src/models.rs index be88d48087..aaec49854e 100644 --- a/nym-api/nym-api-requests/src/models.rs +++ b/nym-api/nym-api-requests/src/models.rs @@ -9,7 +9,10 @@ use crate::nym_nodes::{BasicEntryInformation, NodeRole, SkimmedNode}; use crate::pagination::PaginatedResponse; use cosmwasm_std::{Addr, Coin, Decimal, Uint128}; use nym_crypto::asymmetric::ed25519::{self, serde_helpers::bs58_ed25519_pubkey}; -use nym_crypto::asymmetric::x25519::{self, serde_helpers::bs58_x25519_pubkey}; +use nym_crypto::asymmetric::x25519::{ + self, + serde_helpers::{bs58_x25519_pubkey, option_bs58_x25519_pubkey}, +}; use nym_mixnet_contract_common::nym_node::Role; use nym_mixnet_contract_common::reward_params::{Performance, RewardingParams}; use nym_mixnet_contract_common::rewarding::RewardEstimate; @@ -586,6 +589,11 @@ pub struct HostKeys { #[serde(with = "bs58_x25519_pubkey")] #[schemars(with = "String")] pub x25519: x25519::PublicKey, + + #[serde(default)] + #[serde(with = "option_bs58_x25519_pubkey")] + #[schemars(with = "Option")] + pub x25519_noise: Option, } impl From for HostKeys { @@ -593,6 +601,7 @@ impl From for HostKeys { HostKeys { ed25519: value.ed25519_identity, x25519: value.x25519_sphinx, + x25519_noise: value.x25519_noise, } } } diff --git a/nym-api/src/nym_contract_cache/cache/data.rs b/nym-api/src/nym_contract_cache/cache/data.rs index 622286be24..f32c19c9cd 100644 --- a/nym-api/src/nym_contract_cache/cache/data.rs +++ b/nym-api/src/nym_contract_cache/cache/data.rs @@ -69,18 +69,6 @@ impl CachedRewardedSet { } } - pub fn active_set_size(&self) -> usize { - self.entry_gateways.len() - + self.exit_gateways.len() - + self.layer1.len() - + self.layer2.len() - + self.layer3.len() - } - - pub fn rewarded_set_size(&self) -> usize { - self.active_set_size() + self.standby.len() - } - pub fn try_get_mix_layer(&self, node_id: &NodeId) -> Option { if self.layer1.contains(node_id) { Some(1) @@ -97,20 +85,13 @@ impl CachedRewardedSet { self.standby.contains(node_id) } - pub fn is_entry(&self, node_id: &NodeId) -> bool { - self.entry_gateways.contains(node_id) - } - - pub fn is_exit(&self, node_id: &NodeId) -> bool { - self.exit_gateways.contains(node_id) - } - pub fn is_active_mixnode(&self, node_id: &NodeId) -> bool { self.layer1.contains(node_id) || self.layer2.contains(node_id) || self.layer3.contains(node_id) } + #[allow(dead_code)] pub(crate) fn gateways(&self) -> HashSet { let mut gateways = HashSet::with_capacity(self.entry_gateways.len() + self.exit_gateways.len()); diff --git a/nym-api/src/nym_nodes/handlers/mod.rs b/nym-api/src/nym_nodes/handlers/mod.rs index 46e4b38d73..ad92a689c0 100644 --- a/nym-api/src/nym_nodes/handlers/mod.rs +++ b/nym-api/src/nym_nodes/handlers/mod.rs @@ -58,7 +58,35 @@ async fn nodes_noise( ) -> AxumResult>> { // TODO: implement it let _ = pagination; - todo!() + + let describe_cache = state.describe_nodes_cache_data().await?; + + let nodes = describe_cache + .all_nodes() + .filter_map(|n| { + n.description + .host_information + .keys + .x25519_noise + .map(|noise_key| (noise_key, n)) + }) + .map(|(noise_key, node)| NoiseDetails { + x25119_pubkey: noise_key, + mixnet_port: node.description.mix_port(), + ip_addresses: node.description.host_information.ip_address.clone(), + }) + .collect::>(); + + let total = nodes.len(); + + Ok(Json(PaginatedResponse { + pagination: Pagination { + total, + page: 0, + size: total, + }, + data: nodes, + })) } #[utoipa::path(