Skip to content

Commit df5165b

Browse files
authored
adjusted gateway probe to allow testing wireguard nodes that are not entries (#1812)
* adjusted gateway probe to allow testing wireguard nodes that are not entries * updated git ref to make CI pass (hopefully) * post-rebasing fixes
1 parent 3194105 commit df5165b

File tree

18 files changed

+534
-350
lines changed

18 files changed

+534
-350
lines changed

nym-vpn-core/Cargo.lock

Lines changed: 173 additions & 195 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nym-vpn-core/Cargo.toml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,29 @@ windows-sys = "0.52"
168168
x25519-dalek = "2.0"
169169
zeroize = "1.6.0"
170170

171-
nym-authenticator-requests = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
172-
nym-bandwidth-controller = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
173-
nym-bin-common = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
174-
nym-client-core = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
175-
nym-compact-ecash = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
176-
nym-config = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
177-
nym-contracts-common = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
178-
nym-credential-proxy-requests = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
179-
nym-credential-storage = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
180-
nym-credentials = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
181-
nym-credentials-interface = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
182-
nym-crypto = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
183-
nym-ecash-time = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
184-
nym-http-api-client = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
185-
nym-ip-packet-requests = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
186-
nym-node-requests = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
187-
nym-pemstore = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
188-
nym-service-provider-requests-common = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
189-
nym-sdk = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
190-
nym-statistics-common = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
191-
nym-task = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
192-
nym-topology = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
193-
nym-validator-client = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
194-
nym-wireguard-types = { git = "https://github.com/nymtech/nym", branch = "release/2024.15-reeses" }
171+
# 3d2914b3e5d707cd56e45508cfda6b656d483190 points to the current develop (as of 08.01.25) that contains
172+
# needed changes to `NymTopology` that are going to be released in Hu
173+
nym-authenticator-requests = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
174+
nym-bandwidth-controller = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
175+
nym-bin-common = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
176+
nym-client-core = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
177+
nym-compact-ecash = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
178+
nym-config = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
179+
nym-contracts-common = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
180+
nym-credential-proxy-requests = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
181+
nym-credential-storage = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
182+
nym-credentials = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
183+
nym-credentials-interface = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
184+
nym-crypto = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
185+
nym-ecash-time = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
186+
nym-http-api-client = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
187+
nym-ip-packet-requests = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
188+
nym-node-requests = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
189+
nym-pemstore = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
190+
nym-service-provider-requests-common = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
191+
nym-sdk = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
192+
nym-statistics-common = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
193+
nym-task = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
194+
nym-topology = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
195+
nym-validator-client = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }
196+
nym-wireguard-types = { git = "https://github.com/nymtech/nym", rev = "3d2914b3e5d707cd56e45508cfda6b656d483190" }

nym-vpn-core/crates/nym-authenticator-client/src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,22 +735,34 @@ impl From<u8> for AuthenticatorVersion {
735735
}
736736
}
737737

738-
impl From<Option<String>> for AuthenticatorVersion {
739-
fn from(value: Option<String>) -> Self {
738+
impl From<&str> for AuthenticatorVersion {
739+
fn from(value: &str) -> Self {
740+
let Ok(semver) = semver::Version::parse(value) else {
741+
return Self::UNKNOWN;
742+
};
743+
744+
semver.into()
745+
}
746+
}
747+
748+
impl From<Option<&String>> for AuthenticatorVersion {
749+
fn from(value: Option<&String>) -> Self {
740750
match value {
741751
None => Self::UNKNOWN,
742-
Some(value) => value.into(),
752+
Some(value) => value.as_str().into(),
743753
}
744754
}
745755
}
746756

747757
impl From<String> for AuthenticatorVersion {
748758
fn from(value: String) -> Self {
749-
let Ok(semver) = semver::Version::parse(value.as_str()) else {
750-
return Self::UNKNOWN;
751-
};
759+
Self::from(value.as_str())
760+
}
761+
}
752762

753-
semver.into()
763+
impl From<Option<String>> for AuthenticatorVersion {
764+
fn from(value: Option<String>) -> Self {
765+
value.as_ref().into()
754766
}
755767
}
756768

nym-vpn-core/crates/nym-gateway-directory/src/entries/exit_point.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ impl ExitPoint {
5353
let ipr_address = IpPacketRouterAddress(*address);
5454
let gateway_address = ipr_address.gateway();
5555

56-
// Now fetch the gateway that the IPR is connected to, and override it's IPR address
56+
// Now fetch the gateway that the IPR is connected to, and override its IPR address
5757
let mut gateway = gateways
58-
.gateway_with_identity(gateway_address)
58+
.gateway_with_identity(&gateway_address)
5959
.ok_or_else(|| Error::NoMatchingGateway {
6060
requested_identity: gateway_address.to_string(),
6161
})

nym-vpn-core/crates/nym-gateway-directory/src/entries/gateway.rs

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
11
// Copyright 2024 - Nym Technologies SA <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only
33

4-
use std::{fmt, net::IpAddr, str::FromStr};
5-
64
use itertools::Itertools;
75
use nym_sdk::mixnet::NodeIdentity;
6+
use nym_topology::{NodeId, RoutingNode};
87
use nym_vpn_api_client::types::Percent;
98
use rand::seq::IteratorRandom;
9+
use std::{fmt, net::IpAddr};
1010
use tracing::error;
1111

1212
use crate::{error::Result, AuthAddress, Country, Error, IpPacketRouterAddress};
1313

14+
pub type NymNode = Gateway;
15+
1416
#[derive(Clone)]
1517
pub struct Gateway {
18+
pub node_id: NodeId,
1619
pub identity: NodeIdentity,
1720
pub location: Option<Location>,
1821
pub ipr_address: Option<IpPacketRouterAddress>,
1922
pub authenticator_address: Option<AuthAddress>,
2023
pub last_probe: Option<Probe>,
21-
pub host: Option<nym_topology::NetworkAddress>,
24+
pub ips: Vec<IpAddr>,
25+
pub host: Option<String>,
2226
pub clients_ws_port: Option<u16>,
2327
pub clients_wss_port: Option<u16>,
2428
pub mixnet_performance: Option<Percent>,
@@ -28,6 +32,7 @@ pub struct Gateway {
2832
impl fmt::Debug for Gateway {
2933
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3034
f.debug_struct("Gateway")
35+
.field("node_id", &self.node_id)
3136
.field("identity", &self.identity.to_base58_string())
3237
.field("location", &self.location)
3338
.field("ipr_address", &self.ipr_address)
@@ -42,8 +47,12 @@ impl fmt::Debug for Gateway {
4247
}
4348

4449
impl Gateway {
45-
pub fn identity(&self) -> &NodeIdentity {
46-
&self.identity
50+
pub fn node_id(&self) -> NodeId {
51+
self.node_id
52+
}
53+
54+
pub fn identity(&self) -> NodeIdentity {
55+
self.identity
4756
}
4857

4958
pub fn two_letter_iso_country_code(&self) -> Option<&str> {
@@ -64,17 +73,12 @@ impl Gateway {
6473
self.authenticator_address.is_some()
6574
}
6675

67-
pub fn host(&self) -> Option<&nym_topology::NetworkAddress> {
76+
pub fn host(&self) -> Option<&String> {
6877
self.host.as_ref()
6978
}
7079

71-
pub async fn lookup_ip(&self) -> Option<IpAddr> {
72-
match self.host.clone()? {
73-
nym_topology::NetworkAddress::IpAddr(ip) => Some(ip),
74-
nym_topology::NetworkAddress::Hostname(hostname) => {
75-
crate::helpers::try_resolve_hostname(&hostname).await.ok()
76-
}
77-
}
80+
pub fn lookup_ip(&self) -> Option<IpAddr> {
81+
self.ips.first().copied()
7882
}
7983

8084
pub fn clients_address_no_tls(&self) -> Option<String> {
@@ -218,23 +222,22 @@ impl TryFrom<nym_vpn_api_client::response::NymDirectoryGateway> for Gateway {
218222
.authenticator
219223
.and_then(|auth| AuthAddress::try_from_base58_string(&auth.address).ok());
220224

221-
let hostname = gateway
222-
.entry
223-
.hostname
224-
.map(nym_topology::NetworkAddress::Hostname);
225-
let first_ip_address = gateway.ip_addresses.first().cloned().and_then(|ip| {
226-
IpAddr::from_str(&ip)
227-
.ok()
228-
.map(nym_topology::NetworkAddress::IpAddr)
229-
});
225+
let hostname = gateway.entry.hostname;
226+
let first_ip_address = gateway
227+
.ip_addresses
228+
.first()
229+
.cloned()
230+
.map(|ip| ip.to_string());
230231
let host = hostname.or(first_ip_address);
231232

232233
Ok(Gateway {
234+
node_id: gateway.node_id,
233235
identity,
234236
location: Some(gateway.location.into()),
235237
ipr_address,
236238
authenticator_address,
237239
last_probe: gateway.last_probe.map(Probe::from),
240+
ips: gateway.ip_addresses,
238241
host,
239242
clients_ws_port: Some(gateway.entry.ws_port),
240243
clients_wss_port: gateway.entry.wss_port,
@@ -287,19 +290,24 @@ impl TryFrom<nym_validator_client::models::NymNodeDescription> for Gateway {
287290
} else {
288291
nym_validator_client::nym_nodes::NodeRole::Inactive
289292
};
290-
let gateway = nym_topology::gateway::LegacyNode::try_from(
291-
&node_description.to_skimmed_node(role, Default::default()),
292-
)
293-
.ok();
294-
let host = gateway.clone().map(|g| g.host);
295-
let clients_ws_port = gateway.as_ref().map(|g| g.clients_ws_port);
296-
let clients_wss_port = gateway.and_then(|g| g.clients_wss_port);
293+
294+
let gateway =
295+
RoutingNode::try_from(&node_description.to_skimmed_node(role, Default::default()))
296+
.map_err(|_| Error::MalformedGateway)?;
297+
298+
let host = gateway.ws_entry_address(false);
299+
let entry_info = &gateway.entry;
300+
let clients_ws_port = entry_info.as_ref().map(|g| g.clients_ws_port);
301+
let clients_wss_port = entry_info.as_ref().and_then(|g| g.clients_wss_port);
302+
let ips = node_description.description.host_information.ip_address;
297303
Ok(Gateway {
304+
node_id: gateway.node_id,
298305
identity,
299306
location,
300307
ipr_address,
301308
authenticator_address,
302309
last_probe: None,
310+
ips,
303311
host,
304312
clients_ws_port,
305313
clients_wss_port,
@@ -309,6 +317,8 @@ impl TryFrom<nym_validator_client::models::NymNodeDescription> for Gateway {
309317
}
310318
}
311319

320+
pub type NymNodeList = GatewayList;
321+
312322
#[derive(Debug, Clone)]
313323
pub struct GatewayList {
314324
gateways: Vec<Gateway>,
@@ -341,10 +351,14 @@ impl GatewayList {
341351
.collect()
342352
}
343353

344-
pub fn gateway_with_identity(&self, identity: &NodeIdentity) -> Option<&Gateway> {
354+
pub fn node_with_identity(&self, identity: &NodeIdentity) -> Option<&NymNode> {
345355
self.gateways
346356
.iter()
347-
.find(|gateway| gateway.identity() == identity)
357+
.find(|node| &node.identity() == identity)
358+
}
359+
360+
pub fn gateway_with_identity(&self, identity: &NodeIdentity) -> Option<&Gateway> {
361+
self.node_with_identity(identity)
348362
}
349363

350364
pub fn gateways_located_at(&self, code: String) -> impl Iterator<Item = &Gateway> {
@@ -425,16 +439,22 @@ impl IntoIterator for GatewayList {
425439
}
426440

427441
impl nym_client_core::init::helpers::ConnectableGateway for Gateway {
428-
fn identity(&self) -> &nym_sdk::mixnet::NodeIdentity {
442+
fn node_id(&self) -> NodeId {
443+
self.node_id()
444+
}
445+
446+
fn identity(&self) -> nym_sdk::mixnet::NodeIdentity {
429447
self.identity()
430448
}
431449

432-
fn clients_address(&self) -> String {
450+
fn clients_address(&self, _prefer_ipv6: bool) -> Option<String> {
433451
// This is a bit of a sharp edge, but temporary until we can remove Option from host
434452
// and tls port when we add these to the vpn API endpoints.
435-
self.clients_address_tls()
436-
.or(self.clients_address_no_tls())
437-
.unwrap_or("ws://".to_string())
453+
Some(
454+
self.clients_address_tls()
455+
.or(self.clients_address_no_tls())
456+
.unwrap_or("ws://".to_string()),
457+
)
438458
}
439459

440460
fn is_wss(&self) -> bool {

nym-vpn-core/crates/nym-gateway-directory/src/entries/ipr_addresses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl IpPacketRouterAddress {
3232
)?))
3333
}
3434

35-
pub fn gateway(&self) -> &NodeIdentity {
35+
pub fn gateway(&self) -> NodeIdentity {
3636
self.0.gateway()
3737
}
3838
}

nym-vpn-core/crates/nym-gateway-directory/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pub enum Error {
3636
#[error("failed to lookup skimmed gateways: {0}")]
3737
FailedToLookupSkimmedGateways(#[source] nym_validator_client::ValidatorClientError),
3838

39+
#[error("failed to lookup skimmed nodes: {0}")]
40+
FailedToLookupSkimmedNodes(#[source] nym_validator_client::ValidatorClientError),
41+
3942
#[error("requested gateway not found in the remote list: {0}")]
4043
RequestedGatewayIdNotFound(String),
4144

@@ -76,6 +79,9 @@ pub enum Error {
7679

7780
#[error("failed to lookup gateway ip for gateway {0}")]
7881
FailedToLookupIp(String),
82+
83+
#[error("the provided gateway information is malformed")]
84+
MalformedGateway,
7985
}
8086

8187
// Result type based on our error type

0 commit comments

Comments
 (0)