apply formatting (cargo fmt)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
|
||||
use nym_credential_storage::persistent_storage::PersistentStorage;
|
||||
use nym_registration_common::NymNode;
|
||||
use nym_sdk::{
|
||||
@@ -10,24 +10,24 @@ use nym_sdk::{
|
||||
MixnetClientStorage, OnDiskPersistent, ReplyStorageBackend, StoragePaths, x25519::KeyPair,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
use std::os::fd::RawFd;
|
||||
use std::{path::PathBuf, sync::Arc, time::Duration};
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
|
||||
use crate::error::RegistrationClientError;
|
||||
|
||||
|
||||
const VPN_AVERAGE_PACKET_DELAY: Duration = Duration::from_millis(15);
|
||||
const MIXNET_CLIENT_STARTUP_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NymNodeWithKeys {
|
||||
pub node: NymNode,
|
||||
pub keys: Arc<KeyPair>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(TypedBuilder)]
|
||||
pub struct BuilderConfig {
|
||||
pub entry_node: NymNodeWithKeys,
|
||||
@@ -44,27 +44,27 @@ pub struct BuilderConfig {
|
||||
#[cfg(unix)]
|
||||
pub connection_fd_callback: Arc<dyn Fn(RawFd) + Send + Sync>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Default, Debug, Eq, PartialEq)]
|
||||
pub struct MixnetClientConfig {
|
||||
/// Disable Poission process rate limiting of outbound traffic.
|
||||
pub disable_real_traffic_poisson_process: bool,
|
||||
|
||||
|
||||
/// Disable constant rate background loop cover traffic
|
||||
pub disable_background_cover_traffic: bool,
|
||||
|
||||
|
||||
/// The minimum performance of mixnodes to use.
|
||||
pub min_mixnode_performance: Option<u8>,
|
||||
|
||||
|
||||
/// The minimum performance of gateways to use.
|
||||
pub min_gateway_performance: Option<u8>,
|
||||
|
||||
|
||||
///Setting optionally the poisson rate for cover traffic stream
|
||||
pub loop_cover_traffic_average_delay: Option<Duration>,
|
||||
|
||||
|
||||
/// Average packet delay in milliseconds.
|
||||
pub average_packet_delay: Option<Duration>,
|
||||
|
||||
|
||||
/// Average message sending delay in milliseconds.
|
||||
pub message_sending_average_delay: Option<Duration>,
|
||||
}
|
||||
@@ -76,16 +76,16 @@ impl BuilderConfig {
|
||||
mixnet_debug_config(&self.mixnet_client_config)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn setup_storage(
|
||||
&self,
|
||||
) -> Result<Option<(OnDiskPersistent, PersistentStorage)>, RegistrationClientError> {
|
||||
if let Some(path) = &self.data_path {
|
||||
tracing::debug!("Using custom key storage path: {}", path.display());
|
||||
|
||||
|
||||
let storage_paths = StoragePaths::new_from_dir(path)
|
||||
.map_err(|err| RegistrationClientError::BuildMixnetClient(Box::new(err)))?;
|
||||
|
||||
|
||||
let mixnet_client_storage = storage_paths
|
||||
.initialise_persistent_storage(&self.mixnet_client_debug_config())
|
||||
.await
|
||||
@@ -94,13 +94,13 @@ impl BuilderConfig {
|
||||
.persistent_credential_storage()
|
||||
.await
|
||||
.map_err(|err| RegistrationClientError::BuildMixnetClient(Box::new(err)))?;
|
||||
|
||||
|
||||
Ok(Some((mixnet_client_storage, credential_storage)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn build_and_connect_mixnet_client<S>(
|
||||
self,
|
||||
builder: MixnetClientBuilder<S>,
|
||||
@@ -120,7 +120,7 @@ impl BuilderConfig {
|
||||
} else {
|
||||
RememberMe::new_mixnet()
|
||||
};
|
||||
|
||||
|
||||
let builder = builder
|
||||
.with_user_agent(self.user_agent)
|
||||
.request_gateway(self.entry_node.node.identity.to_string())
|
||||
@@ -130,10 +130,10 @@ impl BuilderConfig {
|
||||
.no_hostname(true)
|
||||
.with_remember_me(remember_me)
|
||||
.custom_topology_provider(self.custom_topology_provider);
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
let builder = builder.with_connection_fd_callback(self.connection_fd_callback);
|
||||
|
||||
|
||||
builder
|
||||
.build()
|
||||
.map_err(|err| RegistrationClientError::BuildMixnetClient(Box::new(err)))?
|
||||
@@ -142,12 +142,12 @@ impl BuilderConfig {
|
||||
.map_err(|err| RegistrationClientError::ConnectToMixnet(Box::new(err)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn two_hop_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfig {
|
||||
let mut debug_config = DebugConfig::default();
|
||||
|
||||
|
||||
debug_config.traffic.average_packet_delay = VPN_AVERAGE_PACKET_DELAY;
|
||||
|
||||
|
||||
// We disable mix hops for the mixnet connection.
|
||||
debug_config.traffic.disable_mix_hops = true;
|
||||
// Always disable poisson process for outbound traffic in wireguard.
|
||||
@@ -156,11 +156,11 @@ fn two_hop_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfi
|
||||
.disable_main_poisson_packet_distribution = true;
|
||||
// Always disable background cover traffic in wireguard.
|
||||
debug_config.cover_traffic.disable_loop_cover_traffic_stream = true;
|
||||
|
||||
|
||||
if let Some(min_mixnode_performance) = mixnet_client_config.min_mixnode_performance {
|
||||
debug_config.topology.minimum_mixnode_performance = min_mixnode_performance;
|
||||
}
|
||||
|
||||
|
||||
if let Some(min_gateway_performance) = mixnet_client_config.min_gateway_performance {
|
||||
debug_config.topology.minimum_gateway_performance = min_gateway_performance;
|
||||
}
|
||||
@@ -168,30 +168,30 @@ fn two_hop_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfi
|
||||
debug_config.traffic.average_packet_delay = avg_packet_ms;
|
||||
debug_config.acknowledgements.average_ack_delay = avg_packet_ms;
|
||||
}
|
||||
|
||||
|
||||
if let Some(msg_delay_ms) = mixnet_client_config.message_sending_average_delay {
|
||||
debug_config.traffic.message_sending_average_delay = msg_delay_ms;
|
||||
}
|
||||
log_mixnet_client_config(&debug_config);
|
||||
debug_config
|
||||
}
|
||||
|
||||
|
||||
fn mixnet_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfig {
|
||||
let mut debug_config = DebugConfig::default();
|
||||
debug_config.traffic.average_packet_delay = VPN_AVERAGE_PACKET_DELAY;
|
||||
|
||||
|
||||
debug_config
|
||||
.traffic
|
||||
.disable_main_poisson_packet_distribution =
|
||||
mixnet_client_config.disable_real_traffic_poisson_process;
|
||||
|
||||
|
||||
debug_config.cover_traffic.disable_loop_cover_traffic_stream =
|
||||
mixnet_client_config.disable_background_cover_traffic;
|
||||
|
||||
|
||||
if let Some(min_mixnode_performance) = mixnet_client_config.min_mixnode_performance {
|
||||
debug_config.topology.minimum_mixnode_performance = min_mixnode_performance;
|
||||
}
|
||||
|
||||
|
||||
if let Some(min_gateway_performance) = mixnet_client_config.min_gateway_performance {
|
||||
debug_config.topology.minimum_gateway_performance = min_gateway_performance;
|
||||
}
|
||||
@@ -199,7 +199,7 @@ fn mixnet_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfig
|
||||
debug_config.traffic.average_packet_delay = avg_packet_ms;
|
||||
debug_config.acknowledgements.average_ack_delay = avg_packet_ms;
|
||||
}
|
||||
|
||||
|
||||
if let Some(msg_delay_ms) = mixnet_client_config.message_sending_average_delay {
|
||||
if msg_delay_ms.is_zero() {
|
||||
debug_config
|
||||
@@ -222,7 +222,7 @@ fn mixnet_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfig
|
||||
log_mixnet_client_config(&debug_config);
|
||||
debug_config
|
||||
}
|
||||
|
||||
|
||||
fn log_mixnet_client_config(debug_config: &DebugConfig) {
|
||||
tracing::info!(
|
||||
"mixnet client poisson rate limiting: {}",
|
||||
@@ -232,22 +232,22 @@ fn log_mixnet_client_config(debug_config: &DebugConfig) {
|
||||
.disable_main_poisson_packet_distribution
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client background loop cover traffic stream: {}",
|
||||
true_to_disabled(debug_config.cover_traffic.disable_loop_cover_traffic_stream)
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client minimum mixnode performance: {}",
|
||||
debug_config.topology.minimum_mixnode_performance,
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client minimum gateway performance: {}",
|
||||
debug_config.topology.minimum_gateway_performance,
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client loop cover traffic average delay: {} ms",
|
||||
debug_config
|
||||
@@ -255,12 +255,12 @@ fn log_mixnet_client_config(debug_config: &DebugConfig) {
|
||||
.loop_cover_traffic_average_delay
|
||||
.as_millis()
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client average packet delay: {} ms",
|
||||
debug_config.traffic.average_packet_delay.as_millis()
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client message sending average delay: {} ms",
|
||||
debug_config
|
||||
@@ -268,7 +268,7 @@ fn log_mixnet_client_config(debug_config: &DebugConfig) {
|
||||
.message_sending_average_delay
|
||||
.as_millis()
|
||||
);
|
||||
|
||||
|
||||
tracing::info!(
|
||||
"mixnet client disable_loop_cover_traffic_average_delay: {}",
|
||||
true_to_disabled(
|
||||
@@ -278,15 +278,15 @@ fn log_mixnet_client_config(debug_config: &DebugConfig) {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
fn true_to_disabled(val: bool) -> &'static str {
|
||||
if val { "disabled" } else { "enabled" }
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_mixnet_client_config_default_values() {
|
||||
let config = MixnetClientConfig::default();
|
||||
|
||||
Reference in New Issue
Block a user