augment topology with described nodes

This commit is contained in:
Simon Wicky
2024-01-30 09:48:32 +01:00
committed by Simon Wicky
parent 7363cdab68
commit d4a2be8a9e
2 changed files with 33 additions and 4 deletions
@@ -77,13 +77,23 @@ impl NymApiTopologyProvider {
Ok(gateways) => gateways,
};
let nodes_described = match self.validator_client.get_cached_described_nodes().await {
Err(err) => {
error!("failed to get described nodes - {err}");
return None;
}
Ok(epoch) => epoch,
};
let topology = nym_topology_from_detailed(mixnodes, gateways)
.with_described_nodes(nodes_described.clone())
.filter_system_version(&self.client_version);
if let Err(err) = self.check_layer_distribution(&topology) {
warn!("The current filtered active topology has extremely skewed layer distribution. It cannot be used: {err}");
self.use_next_nym_api();
None
let empty_topology = NymTopology::empty().with_described_nodes(nodes_described);
Some(empty_topology)
} else {
Some(topology)
}
+22 -3
View File
@@ -19,7 +19,7 @@ use std::str::FromStr;
#[cfg(feature = "serializable")]
use ::serde::{Deserialize, Deserializer, Serialize, Serializer};
use nym_api_requests::models::DescribedGateway;
use nym_api_requests::models::{DescribedGateway, DescribedNymNode};
pub mod error;
pub mod filter;
@@ -115,11 +115,29 @@ pub type MixLayer = u8;
pub struct NymTopology {
mixes: BTreeMap<MixLayer, Vec<mix::Node>>,
gateways: Vec<gateway::Node>,
described_nodes: Vec<DescribedNymNode>,
}
impl NymTopology {
pub fn new(mixes: BTreeMap<MixLayer, Vec<mix::Node>>, gateways: Vec<gateway::Node>) -> Self {
NymTopology { mixes, gateways }
NymTopology {
mixes: mixes.clone(),
gateways: gateways.clone(),
described_nodes: Vec::new(),
}
}
pub fn empty() -> Self {
NymTopology {
mixes: BTreeMap::new(),
gateways: Vec::new(),
described_nodes: Vec::new(),
}
}
pub fn with_described_nodes(mut self, described_nodes: Vec<DescribedNymNode>) -> Self {
self.described_nodes = described_nodes;
self
}
pub fn new_unordered(unordered_mixes: Vec<mix::Node>, gateways: Vec<gateway::Node>) -> Self {
@@ -130,7 +148,7 @@ impl NymTopology {
layer_entry.push(node)
}
NymTopology { mixes, gateways }
NymTopology::new(mixes, gateways)
}
#[cfg(feature = "serializable")]
@@ -379,6 +397,7 @@ impl NymTopology {
NymTopology {
mixes: self.mixes.filter_by_version(expected_mix_version),
gateways: self.gateways.clone(),
described_nodes: self.described_nodes.clone(),
}
}
}