Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b6570b435 | |||
| 80cbe8bff9 | |||
| 216fd8617f | |||
| 6440cf29a6 |
@@ -97,9 +97,11 @@ impl NymApiTopologyProvider {
|
||||
}
|
||||
|
||||
async fn get_current_compatible_topology(&mut self) -> Option<NymTopology> {
|
||||
#[allow(deprecated)]
|
||||
let mixnodes = match self
|
||||
.validator_client
|
||||
.get_all_basic_active_mixing_assigned_nodes(Some(self.client_version.clone()))
|
||||
// .get_all_basic_active_mixing_assigned_nodes(Some(self.client_version.clone()))
|
||||
.get_basic_mixnodes(Some(self.client_version.clone()))
|
||||
.await
|
||||
{
|
||||
Err(err) => {
|
||||
@@ -109,9 +111,11 @@ impl NymApiTopologyProvider {
|
||||
Ok(mixes) => mixes,
|
||||
};
|
||||
|
||||
#[allow(deprecated)]
|
||||
let gateways = match self
|
||||
.validator_client
|
||||
.get_all_basic_entry_assigned_nodes(Some(self.client_version.clone()))
|
||||
// .get_all_basic_entry_assigned_nodes(Some(self.client_version.clone()))
|
||||
.get_basic_gateways(Some(self.client_version.clone()))
|
||||
.await
|
||||
{
|
||||
Err(err) => {
|
||||
|
||||
@@ -7,7 +7,7 @@ use futures::{SinkExt, StreamExt};
|
||||
use log::{debug, info, trace, warn};
|
||||
use nym_crypto::asymmetric::identity;
|
||||
use nym_gateway_client::GatewayClient;
|
||||
use nym_topology::{gateway, mix};
|
||||
use nym_topology::gateway;
|
||||
use nym_validator_client::client::IdentityKeyRef;
|
||||
use nym_validator_client::UserAgent;
|
||||
use rand::{seq::SliceRandom, Rng};
|
||||
@@ -94,7 +94,9 @@ pub async fn current_gateways<R: Rng>(
|
||||
|
||||
log::debug!("Fetching list of gateways from: {nym_api}");
|
||||
|
||||
let gateways = client.get_all_basic_entry_assigned_nodes(None).await?;
|
||||
// let gateways = client.get_all_basic_entry_assigned_nodes(None).await?;
|
||||
#[allow(deprecated)]
|
||||
let gateways = client.get_cached_described_gateways().await?;
|
||||
log::debug!("Found {} gateways", gateways.len());
|
||||
log::trace!("Gateways: {:#?}", gateways);
|
||||
|
||||
@@ -110,27 +112,28 @@ pub async fn current_gateways<R: Rng>(
|
||||
Ok(valid_gateways)
|
||||
}
|
||||
|
||||
pub async fn current_mixnodes<R: Rng>(
|
||||
rng: &mut R,
|
||||
nym_apis: &[Url],
|
||||
) -> Result<Vec<mix::LegacyNode>, ClientCoreError> {
|
||||
let nym_api = nym_apis
|
||||
.choose(rng)
|
||||
.ok_or(ClientCoreError::ListOfNymApisIsEmpty)?;
|
||||
let client = nym_validator_client::client::NymApiClient::new(nym_api.clone());
|
||||
|
||||
log::trace!("Fetching list of mixnodes from: {nym_api}");
|
||||
|
||||
let mixnodes = client
|
||||
.get_all_basic_active_mixing_assigned_nodes(None)
|
||||
.await?;
|
||||
let valid_mixnodes = mixnodes
|
||||
.iter()
|
||||
.filter_map(|mixnode| mixnode.try_into().ok())
|
||||
.collect::<Vec<mix::LegacyNode>>();
|
||||
|
||||
Ok(valid_mixnodes)
|
||||
}
|
||||
//pub async fn current_mixnodes<R: Rng>(
|
||||
// rng: &mut R,
|
||||
// nym_apis: &[Url],
|
||||
//) -> Result<Vec<mix::LegacyNode>, ClientCoreError> {
|
||||
// let nym_api = nym_apis
|
||||
// .choose(rng)
|
||||
// .ok_or(ClientCoreError::ListOfNymApisIsEmpty)?;
|
||||
// let client = nym_validator_client::client::NymApiClient::new(nym_api.clone());
|
||||
//
|
||||
// log::trace!("Fetching list of mixnodes from: {nym_api}");
|
||||
//
|
||||
// //let mixnodes = client
|
||||
// // .get_all_basic_active_mixing_assigned_nodes(None)
|
||||
// // .await?;
|
||||
// let mixnodes = client.get_cached_mixnodes().await?;
|
||||
// let valid_mixnodes = mixnodes
|
||||
// .iter()
|
||||
// .filter_map(|mixnode| (&mixnode.bond_information).try_into().ok())
|
||||
// .collect::<Vec<mix::LegacyNode>>();
|
||||
//
|
||||
// Ok(valid_mixnodes)
|
||||
//}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
async fn connect(endpoint: &str) -> Result<WsConn, ClientCoreError> {
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::{filter, NetworkAddress, NodeVersion};
|
||||
use nym_api_requests::models::LegacyDescribedGateway;
|
||||
use nym_api_requests::nym_nodes::SkimmedNode;
|
||||
use nym_crypto::asymmetric::{encryption, identity};
|
||||
use nym_mixnet_contract_common::GatewayBond;
|
||||
use nym_mixnet_contract_common::NodeId;
|
||||
use nym_sphinx_addressing::nodes::{NodeIdentity, NymNodeRoutingAddress};
|
||||
use nym_sphinx_types::Node as SphinxNode;
|
||||
@@ -179,3 +181,83 @@ impl<'a> TryFrom<&'a SkimmedNode> for LegacyNode {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a GatewayBond> for LegacyNode {
|
||||
type Error = GatewayConversionError;
|
||||
|
||||
fn try_from(bond: &'a GatewayBond) -> Result<Self, Self::Error> {
|
||||
let host = Self::parse_host(&bond.gateway.host)?;
|
||||
|
||||
// try to completely resolve the host in the mix situation to avoid doing it every
|
||||
// single time we want to construct a path
|
||||
let mix_host = Self::extract_mix_host(&host, bond.gateway.mix_port)?;
|
||||
|
||||
Ok(LegacyNode {
|
||||
// owner: Some(bond.owner.as_str().to_owned()),
|
||||
node_id: 0,
|
||||
host,
|
||||
mix_host,
|
||||
clients_ws_port: bond.gateway.clients_port,
|
||||
clients_wss_port: None,
|
||||
identity_key: identity::PublicKey::from_base58_string(&bond.gateway.identity_key)?,
|
||||
sphinx_key: encryption::PublicKey::from_base58_string(&bond.gateway.sphinx_key)?,
|
||||
version: bond.gateway.version.as_str().into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<GatewayBond> for LegacyNode {
|
||||
type Error = GatewayConversionError;
|
||||
|
||||
fn try_from(bond: GatewayBond) -> Result<Self, Self::Error> {
|
||||
LegacyNode::try_from(&bond)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<&'a LegacyDescribedGateway> for LegacyNode {
|
||||
type Error = GatewayConversionError;
|
||||
|
||||
fn try_from(value: &'a LegacyDescribedGateway) -> Result<Self, Self::Error> {
|
||||
let Some(ref self_described) = value.self_described else {
|
||||
return (&value.bond).try_into();
|
||||
};
|
||||
|
||||
let ips = &self_described.host_information.ip_address;
|
||||
if ips.is_empty() {
|
||||
return Err(GatewayConversionError::NoIpAddressesProvided {
|
||||
gateway: value.bond.gateway.identity_key.clone(),
|
||||
});
|
||||
}
|
||||
|
||||
let host = match &self_described.host_information.hostname {
|
||||
None => NetworkAddress::IpAddr(ips[0]),
|
||||
Some(hostname) => NetworkAddress::Hostname(hostname.clone()),
|
||||
};
|
||||
|
||||
// get ip from the self-reported values so we wouldn't need to do any hostname resolution
|
||||
// (which doesn't really work in wasm)
|
||||
let mix_host = SocketAddr::new(ips[0], value.bond.gateway.mix_port);
|
||||
|
||||
Ok(LegacyNode {
|
||||
// owner: Some(value.bond.owner.as_str().to_owned()),
|
||||
node_id: 0,
|
||||
host,
|
||||
mix_host,
|
||||
clients_ws_port: self_described.mixnet_websockets.ws_port,
|
||||
clients_wss_port: self_described.mixnet_websockets.wss_port,
|
||||
//identity_key: identity::PublicKey::from_base58_string(
|
||||
// &self_described.host_information.keys.ed25519,
|
||||
//)?,
|
||||
identity_key: self_described.host_information.keys.ed25519,
|
||||
//sphinx_key: encryption::PublicKey::from_base58_string(
|
||||
// &self_described.host_information.keys.x25519,
|
||||
//)?,
|
||||
sphinx_key: self_described.host_information.keys.x25519,
|
||||
version: self_described
|
||||
.build_information
|
||||
.build_version
|
||||
.as_str()
|
||||
.into(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user