Skip to content
Open
Changes from 6 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
107 changes: 98 additions & 9 deletions nym-registration-client/src/builder/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct BuilderConfig {
#[derive(Clone, Default, Debug, Eq, PartialEq)]
pub struct MixnetClientConfig {
/// Disable Poission process rate limiting of outbound traffic.
pub disable_poisson_rate: bool,
pub disable_real_traffic_poisson_process: bool,

/// Disable constant rate background loop cover traffic
pub disable_background_cover_traffic: bool,
Expand All @@ -58,8 +58,16 @@ pub struct MixnetClientConfig {

/// 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>,
}
impl BuilderConfig {
pub fn mixnet_client_debug_config(&self) -> DebugConfig {
if self.two_hops {
Expand Down Expand Up @@ -134,7 +142,6 @@ 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();

Expand All @@ -160,15 +167,10 @@ fn two_hop_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfi
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_poisson_rate;

debug_config.cover_traffic.disable_loop_cover_traffic_stream =
mixnet_client_config.disable_background_cover_traffic;

Expand All @@ -179,6 +181,59 @@ fn mixnet_debug_config(mixnet_client_config: &MixnetClientConfig) -> DebugConfig
if let Some(min_gateway_performance) = mixnet_client_config.min_gateway_performance {
debug_config.topology.minimum_gateway_performance = min_gateway_performance;
}
if let Some(avg_packet_ms) = mixnet_client_config.average_packet_delay {
debug_config.traffic.average_packet_delay = avg_packet_ms;
debug_config.acknowledgements.average_ack_delay = avg_packet_ms;
}
// Decide whether the real-traffic Poisson process should be disabled.
//
// We disable it if:
// 1. The user explicitly requested it via `disable_real_traffic_poisson_process`, OR
// 2. The user set `message_sending_average_delay` to 0ms (special value meaning "disable")
let mut disable_real_traffic_poisson =
mixnet_client_config.disable_real_traffic_poisson_process;

if let Some(delay) = mixnet_client_config.message_sending_average_delay
&& delay.is_zero()
{
disable_real_traffic_poisson = true;
}

debug_config
.traffic
.disable_main_poisson_packet_distribution = disable_real_traffic_poisson;

// Only apply a custom message sending delay if the Poisson process is enabled.
// If Poisson is disabled, any delay value is ignored.
if !disable_real_traffic_poisson
&& let Some(delay) = mixnet_client_config.message_sending_average_delay
{
debug_config.traffic.message_sending_average_delay = delay;
}

// Decide whether the loop cover traffic stream should be disabled.
//
// We disable it if:
// 1. The user explicitly disabled background cover traffic, OR
// 2. The loop cover traffic average delay is set to 0ms (special value meaning "disable")
let mut disable_loop_cover_stream = mixnet_client_config.disable_background_cover_traffic;

if let Some(delay) = mixnet_client_config.loop_cover_traffic_average_delay
&& delay.is_zero()
{
disable_loop_cover_stream = true;
}

debug_config.cover_traffic.disable_loop_cover_traffic_stream = disable_loop_cover_stream;

// Only apply a custom loop cover delay if the stream is enabled.
// If the stream is disabled, the delay value is ignored.
if !disable_loop_cover_stream
&& let Some(delay) = mixnet_client_config.loop_cover_traffic_average_delay
{
debug_config.cover_traffic.loop_cover_traffic_average_delay = delay;
}

log_mixnet_client_config(&debug_config);
debug_config
}
Expand Down Expand Up @@ -207,6 +262,40 @@ fn log_mixnet_client_config(debug_config: &DebugConfig) {
"mixnet client minimum gateway performance: {}",
debug_config.topology.minimum_gateway_performance,
);
if !debug_config.cover_traffic.disable_loop_cover_traffic_stream {
tracing::info!(
"mixnet client loop cover traffic average delay: {} ms",
debug_config
.cover_traffic
.loop_cover_traffic_average_delay
.as_millis()
);
}

tracing::info!(
"mixnet client average packet delay: {} ms",
debug_config.traffic.average_packet_delay.as_millis()
);
if !debug_config
.traffic
.disable_main_poisson_packet_distribution
{
tracing::info!(
"mixnet client message sending average delay: {} ms",
debug_config
.traffic
.message_sending_average_delay
.as_millis()
);
}
tracing::info!(
"mixnet client disable_loop_cover_traffic_average_delay: {}",
true_to_disabled(
debug_config
.traffic
.disable_main_poisson_packet_distribution
)
);
}

fn true_to_disabled(val: bool) -> &'static str {
Expand All @@ -220,7 +309,7 @@ mod tests {
#[test]
fn test_mixnet_client_config_default_values() {
let config = MixnetClientConfig::default();
assert!(!config.disable_poisson_rate);
assert!(!config.disable_real_traffic_poisson_process);
assert!(!config.disable_background_cover_traffic);
assert_eq!(config.min_mixnode_performance, None);
assert_eq!(config.min_gateway_performance, None);
Expand Down
Loading