Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ use tracing::error;

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

// Decimal between 0 and 1 representing the performance of a gateway, measured over 24h.
type Perfomance = f64;

#[derive(Clone, Debug)]
pub struct Gateway {
pub identity: NodeIdentity,
pub location: Option<Location>,
pub ipr_address: Option<IpPacketRouterAddress>,
pub authenticator_address: Option<AuthAddress>,
pub last_probe: Option<Probe>,
pub performance: Option<Perfomance>,
}

impl Gateway {
Expand Down Expand Up @@ -139,6 +143,7 @@ impl TryFrom<nym_vpn_api_client::Gateway> for Gateway {
ipr_address: None,
authenticator_address: None,
last_probe: gateway.last_probe.map(Probe::from),
performance: None,
})
}
}
Expand Down Expand Up @@ -185,6 +190,7 @@ impl TryFrom<nym_validator_client::models::DescribedGateway> for Gateway {
ipr_address,
authenticator_address,
last_probe: None,
performance: None,
})
}
}
Expand Down
32 changes: 32 additions & 0 deletions nym-vpn-core/crates/nym-gateway-directory/src/gateway_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ impl GatewayClient {
// Lookup the IPR and authenticator addresses from the nym-api as a temporary hack until
// the nymvpn.com endpoints are updated to also include these fields.
let described_gateways = self.lookup_described_gateways().await?;
let basic_gw = self.api_client.get_basic_gateways(None).await.unwrap();
append_ipr_and_authenticator_addresses(&mut gateways, described_gateways);
append_performance(&mut gateways, basic_gw);
Ok(GatewayList::new(gateways))
} else {
self.lookup_all_gateways_from_nym_api().await
Expand All @@ -256,7 +258,9 @@ impl GatewayClient {
// Lookup the IPR and authenticator addresses from the nym-api as a temporary hack until
// the nymvpn.com endpoints are updated to also include these fields.
let described_gateways = self.lookup_described_gateways().await?;
let basic_gw = self.api_client.get_basic_gateways(None).await.unwrap();
append_ipr_and_authenticator_addresses(&mut entry_gateways, described_gateways);
append_performance(&mut entry_gateways, basic_gw);
Ok(GatewayList::new(entry_gateways))
} else {
self.lookup_entry_gateways_from_nym_api().await
Expand All @@ -280,7 +284,9 @@ impl GatewayClient {
// Lookup the IPR and authenticator addresses from the nym-api as a temporary hack until
// the nymvpn.com endpoints are updated to also include these fields.
let described_gateways = self.lookup_described_gateways().await?;
let basic_gw = self.api_client.get_basic_gateways(None).await.unwrap();
append_ipr_and_authenticator_addresses(&mut exit_gateways, described_gateways);
append_performance(&mut exit_gateways, basic_gw);
Ok(GatewayList::new(exit_gateways))
} else {
self.lookup_exit_gateways_from_nym_api().await
Expand Down Expand Up @@ -344,6 +350,32 @@ fn append_ipr_and_authenticator_addresses(
.map(|auth| auth.address)
.and_then(|address| Recipient::try_from_base58_string(address).ok())
.map(|r| AuthAddress(Some(r)))
} else {
error!(
"Failed to find described gateway for gateway with identity {}",
gateway.identity()
);
}
}
}

// Append the performance to the gateways. This is a temporary hack until the nymvpn.com endpoints
// are updated to also include this field.
fn append_performance(
gateways: &mut [Gateway],
basic_gw: Vec<nym_validator_client::nym_nodes::SkimmedNode>,
) {
for gateway in gateways.iter_mut() {
if let Some(basic_gw) = basic_gw
.iter()
.find(|bgw| bgw.ed25519_identity_pubkey == gateway.identity().to_base58_string())
{
gateway.performance = Some(basic_gw.performance.round_to_integer() as f64 / 100.0);
} else {
error!(
"Failed to find skimmed node for gateway with identity {}",
gateway.identity()
);
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions nym-vpn-core/nym-vpn-lib/src/tunnel_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,18 +460,24 @@ async fn select_gateways(
info!("Found {} entry gateways", entry_gateways.len());
info!("Found {} exit gateways", exit_gateways.len());
info!(
"Using entry gateway: {}, location: {}",
"Using entry gateway: {}, location: {}, performane: {}",
*entry_gateway.identity(),
entry_gateway
.two_letter_iso_country_code()
.map_or_else(|| "unknown".to_string(), |code| code.to_string())
.map_or_else(|| "unknown".to_string(), |code| code.to_string()),
entry_gateway
.performance
.map_or_else(|| "unknown".to_string(), |perf| perf.to_string()),
);
info!(
"Using exit gateway: {}, location: {}",
"Using exit gateway: {}, location: {}, performance: {}",
*exit_gateway.identity(),
exit_gateway
.two_letter_iso_country_code()
.map_or_else(|| "unknown".to_string(), |code| code.to_string())
.map_or_else(|| "unknown".to_string(), |code| code.to_string()),
entry_gateway
.performance
.map_or_else(|| "unknown".to_string(), |perf| perf.to_string()),
);
info!(
"Using exit router address {}",
Expand Down