Skip to content

Commit

Permalink
implemented the noise route
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn committed Sep 24, 2024
1 parent f12c80c commit a30e1ee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
11 changes: 10 additions & 1 deletion nym-api/nym-api-requests/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -586,13 +589,19 @@ 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<String>")]
pub x25519_noise: Option<x25519::PublicKey>,
}

impl From<nym_node_requests::api::v1::node::models::HostKeys> for HostKeys {
fn from(value: nym_node_requests::api::v1::node::models::HostKeys) -> Self {
HostKeys {
ed25519: value.ed25519_identity,
x25519: value.x25519_sphinx,
x25519_noise: value.x25519_noise,
}
}
}
Expand Down
21 changes: 1 addition & 20 deletions nym-api/src/nym_contract_cache/cache/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> {
if self.layer1.contains(node_id) {
Some(1)
Expand All @@ -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<NodeId> {
let mut gateways =
HashSet::with_capacity(self.entry_gateways.len() + self.exit_gateways.len());
Expand Down
30 changes: 29 additions & 1 deletion nym-api/src/nym_nodes/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,35 @@ async fn nodes_noise(
) -> AxumResult<Json<PaginatedResponse<NoiseDetails>>> {
// 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::<Vec<_>>();

let total = nodes.len();

Ok(Json(PaginatedResponse {
pagination: Pagination {
total,
page: 0,
size: total,
},
data: nodes,
}))
}

#[utoipa::path(
Expand Down

0 comments on commit a30e1ee

Please sign in to comment.