diff --git a/clients/client-core/src/client/cover_traffic_stream.rs b/clients/client-core/src/client/cover_traffic_stream.rs index 3883f63b33..f13cbde3fa 100644 --- a/clients/client-core/src/client/cover_traffic_stream.rs +++ b/clients/client-core/src/client/cover_traffic_stream.rs @@ -10,6 +10,7 @@ use log::*; use nymsphinx::acknowledgements::AckKey; use nymsphinx::addressing::clients::Recipient; use nymsphinx::cover::generate_loop_cover_packet; +use nymsphinx::params::PacketSize; use nymsphinx::utils::sample_poisson_duration; use rand::{rngs::OsRng, CryptoRng, Rng}; use std::pin::Pin; @@ -58,6 +59,9 @@ where /// Accessor to the common instance of network topology. topology_access: TopologyAccessor, + + /// Predefined packet size used for the loop cover messages. + packet_size: PacketSize, } impl Stream for LoopCoverTrafficStream @@ -130,9 +134,14 @@ impl LoopCoverTrafficStream { our_full_destination, rng, topology_access, + packet_size: Default::default(), } } + pub fn set_custom_packet_size(&mut self, packet_size: PacketSize) { + self.packet_size = packet_size; + } + async fn on_new_message(&mut self) { trace!("next cover message!"); @@ -158,6 +167,7 @@ impl LoopCoverTrafficStream { &self.our_full_destination, self.average_ack_delay, self.average_packet_delay, + self.packet_size, ) .expect("Somehow failed to generate a loop cover message with a valid topology"); diff --git a/clients/client-core/src/client/real_messages_control/acknowledgement_control/mod.rs b/clients/client-core/src/client/real_messages_control/acknowledgement_control/mod.rs index c875ffbfce..c946716091 100644 --- a/clients/client-core/src/client/real_messages_control/acknowledgement_control/mod.rs +++ b/clients/client-core/src/client/real_messages_control/acknowledgement_control/mod.rs @@ -13,6 +13,7 @@ use crate::spawn_future; use futures::channel::mpsc; use gateway_client::AcknowledgementReceiver; use log::*; +use nymsphinx::params::PacketSize; use nymsphinx::{ acknowledgements::AckKey, addressing::clients::Recipient, @@ -121,6 +122,9 @@ pub(super) struct Config { /// Average delay a data packet is going to get delayed at a single mixnode. average_packet_delay: Duration, + + /// Predefined packet size used for the encapsulated messages. + packet_size: PacketSize, } impl Config { @@ -135,8 +139,14 @@ impl Config { ack_wait_multiplier, average_ack_delay, average_packet_delay, + packet_size: Default::default(), } } + + pub fn with_custom_packet_size(mut self, packet_size: PacketSize) -> Self { + self.packet_size = packet_size; + self + } } pub(super) struct AcknowledgementController @@ -176,7 +186,8 @@ where ack_recipient, config.average_packet_delay, config.average_ack_delay, - ); + ) + .with_custom_real_message_packet_size(config.packet_size); // will listen for any acks coming from the network let acknowledgement_listener = AcknowledgementListener::new( diff --git a/clients/client-core/src/client/real_messages_control/mod.rs b/clients/client-core/src/client/real_messages_control/mod.rs index 129176528d..d97e27bdc3 100644 --- a/clients/client-core/src/client/real_messages_control/mod.rs +++ b/clients/client-core/src/client/real_messages_control/mod.rs @@ -19,6 +19,7 @@ use gateway_client::AcknowledgementReceiver; use log::*; use nymsphinx::acknowledgements::AckKey; use nymsphinx::addressing::clients::Recipient; +use nymsphinx::params::PacketSize; use rand::{rngs::OsRng, CryptoRng, Rng}; use std::sync::Arc; use std::time::Duration; @@ -55,6 +56,9 @@ pub struct Config { /// Controls whether the main packet stream constantly produces packets according to the predefined /// poisson distribution. disable_main_poisson_packet_distribution: bool, + + /// Predefined packet size used for the encapsulated messages. + packet_size: PacketSize, } impl Config { @@ -79,8 +83,13 @@ impl Config { average_packet_delay_duration, average_ack_delay_duration, disable_main_poisson_packet_distribution, + packet_size: Default::default(), } } + + pub fn set_custom_packet_size(&mut self, packet_size: PacketSize) { + self.packet_size = packet_size; + } } pub struct RealMessagesController @@ -119,7 +128,8 @@ impl RealMessagesController { config.ack_wait_multiplier, config.average_ack_delay_duration, config.average_packet_delay_duration, - ); + ) + .with_custom_packet_size(config.packet_size); let ack_control = AcknowledgementController::new( ack_control_config, @@ -137,7 +147,8 @@ impl RealMessagesController { config.average_packet_delay_duration, config.average_message_sending_delay, config.disable_main_poisson_packet_distribution, - ); + ) + .with_custom_cover_packet_size(config.packet_size); let out_queue_control = OutQueueControl::new( out_queue_config, diff --git a/clients/client-core/src/client/real_messages_control/real_traffic_stream.rs b/clients/client-core/src/client/real_messages_control/real_traffic_stream.rs index 2a72173846..2041d0169c 100644 --- a/clients/client-core/src/client/real_messages_control/real_traffic_stream.rs +++ b/clients/client-core/src/client/real_messages_control/real_traffic_stream.rs @@ -22,6 +22,7 @@ use std::time::Duration; #[cfg(not(target_arch = "wasm32"))] use tokio::time; +use nymsphinx::params::PacketSize; #[cfg(target_arch = "wasm32")] use wasm_timer; @@ -40,6 +41,9 @@ pub(crate) struct Config { /// Controls whether the stream constantly produces packets according to the predefined /// poisson distribution. disable_poisson_packet_distribution: bool, + + /// Predefined packet size used for the loop cover messages. + cover_packet_size: PacketSize, } impl Config { @@ -54,8 +58,14 @@ impl Config { average_packet_delay, average_message_sending_delay, disable_poisson_packet_distribution, + cover_packet_size: Default::default() } } + + pub fn with_custom_cover_packet_size(mut self, packet_size: PacketSize) -> Self { + self.cover_packet_size = packet_size; + self + } } pub(crate) struct OutQueueControl @@ -192,6 +202,7 @@ where &self.our_full_destination, self.config.average_ack_delay, self.config.average_packet_delay, + self.config.cover_packet_size, ) .expect("Somehow failed to generate a loop cover message with a valid topology") } diff --git a/clients/client-core/src/config/mod.rs b/clients/client-core/src/config/mod.rs index 4aca05ba6f..f25da56604 100644 --- a/clients/client-core/src/config/mod.rs +++ b/clients/client-core/src/config/mod.rs @@ -247,6 +247,10 @@ impl Config { self.debug.disable_main_poisson_packet_distribution } + pub fn get_use_extended_packet_size(&self) -> bool { + self.debug.use_extended_packet_size + } + pub fn get_version(&self) -> &str { &self.client.version } @@ -465,6 +469,9 @@ pub struct Debug { /// Controls whether the main packet stream constantly produces packets according to the predefined /// poisson distribution. pub disable_main_poisson_packet_distribution: bool, + + /// Controls whether the sent sphinx packet use the NON-DEFAULT bigger size. + pub use_extended_packet_size: bool, } impl Default for Debug { @@ -481,6 +488,7 @@ impl Default for Debug { topology_resolution_timeout: DEFAULT_TOPOLOGY_RESOLUTION_TIMEOUT, disable_loop_cover_traffic_stream: false, disable_main_poisson_packet_distribution: false, + use_extended_packet_size: false } } } diff --git a/clients/native/src/client/mod.rs b/clients/native/src/client/mod.rs index c994b9c3c0..38f3d083a0 100644 --- a/clients/native/src/client/mod.rs +++ b/clients/native/src/client/mod.rs @@ -31,6 +31,7 @@ use log::*; use nymsphinx::addressing::clients::Recipient; use nymsphinx::addressing::nodes::NodeIdentity; use nymsphinx::anonymous_replies::ReplySurb; +use nymsphinx::params::PacketSize; use nymsphinx::receiver::ReconstructedMessage; use task::{wait_for_signal, ShutdownListener, ShutdownNotifier}; @@ -90,7 +91,7 @@ impl NymClient { ) { info!("Starting loop cover traffic stream..."); - LoopCoverTrafficStream::new( + let mut stream = LoopCoverTrafficStream::new( self.key_manager.ack_key(), self.config.get_base().get_average_ack_delay(), self.config.get_base().get_average_packet_delay(), @@ -100,8 +101,13 @@ impl NymClient { mix_tx, self.as_mix_recipient(), topology_accessor, - ) - .start_with_shutdown(shutdown); + ); + + if self.config.get_base().get_use_extended_packet_size() { + stream.set_custom_packet_size(PacketSize::ExtendedPacket) + } + + stream.start_with_shutdown(shutdown); } fn start_real_traffic_controller( @@ -113,7 +119,7 @@ impl NymClient { mix_sender: BatchMixMessageSender, shutdown: ShutdownListener, ) { - let controller_config = real_messages_control::Config::new( + let mut controller_config = real_messages_control::Config::new( self.key_manager.ack_key(), self.config.get_base().get_ack_wait_multiplier(), self.config.get_base().get_ack_wait_addition(), @@ -126,6 +132,10 @@ impl NymClient { self.as_mix_recipient(), ); + if self.config.get_base().get_use_extended_packet_size() { + controller_config.set_custom_packet_size(PacketSize::ExtendedPacket) + } + info!("Starting real traffic stream..."); RealMessagesController::new( diff --git a/clients/socks5/src/client/mod.rs b/clients/socks5/src/client/mod.rs index 43ed57b141..1110f88536 100644 --- a/clients/socks5/src/client/mod.rs +++ b/clients/socks5/src/client/mod.rs @@ -31,6 +31,7 @@ use gateway_client::{ use log::*; use nymsphinx::addressing::clients::Recipient; use nymsphinx::addressing::nodes::NodeIdentity; +use nymsphinx::params::PacketSize; use task::{wait_for_signal, ShutdownListener, ShutdownNotifier}; use crate::client::config::Config; @@ -91,7 +92,7 @@ impl NymClient { ) { info!("Starting loop cover traffic stream..."); - LoopCoverTrafficStream::new( + let mut stream = LoopCoverTrafficStream::new( self.key_manager.ack_key(), self.config.get_base().get_average_ack_delay(), self.config.get_base().get_average_packet_delay(), @@ -101,8 +102,13 @@ impl NymClient { mix_tx, self.as_mix_recipient(), topology_accessor, - ) - .start_with_shutdown(shutdown); + ); + + if self.config.get_base().get_use_extended_packet_size() { + stream.set_custom_packet_size(PacketSize::ExtendedPacket) + } + + stream.start_with_shutdown(shutdown); } fn start_real_traffic_controller( @@ -114,7 +120,7 @@ impl NymClient { mix_sender: BatchMixMessageSender, shutdown: ShutdownListener, ) { - let controller_config = client_core::client::real_messages_control::Config::new( + let mut controller_config = client_core::client::real_messages_control::Config::new( self.key_manager.ack_key(), self.config.get_base().get_ack_wait_multiplier(), self.config.get_base().get_ack_wait_addition(), @@ -127,6 +133,10 @@ impl NymClient { self.as_mix_recipient(), ); + if self.config.get_base().get_use_extended_packet_size() { + controller_config.set_custom_packet_size(PacketSize::ExtendedPacket) + } + info!("Starting real traffic stream..."); RealMessagesController::new( diff --git a/common/nymsphinx/cover/src/lib.rs b/common/nymsphinx/cover/src/lib.rs index 3a545dbaa0..c7ab32d8c1 100644 --- a/common/nymsphinx/cover/src/lib.rs +++ b/common/nymsphinx/cover/src/lib.rs @@ -76,6 +76,7 @@ pub fn generate_loop_cover_packet( full_address: &Recipient, average_ack_delay: time::Duration, average_packet_delay: time::Duration, + packet_size: PacketSize, ) -> Result where R: RngCore + CryptoRng, @@ -96,7 +97,7 @@ where let public_key_bytes = ephemeral_keypair.public_key().to_bytes(); let cover_size = - PacketSize::default().plaintext_size() - public_key_bytes.len() - ack_bytes.len(); + packet_size.plaintext_size() - public_key_bytes.len() - ack_bytes.len(); let mut cover_content: Vec<_> = LOOP_COVER_MESSAGE_PAYLOAD .iter() @@ -129,7 +130,7 @@ where // once merged, that's an easy rng injection point for sphinx packets : ) let packet = SphinxPacketBuilder::new() - .with_payload_size(PacketSize::default().payload_size()) + .with_payload_size(packet_size.payload_size()) .build_packet(packet_payload, &route, &destination, &delays) .unwrap(); diff --git a/common/nymsphinx/src/preparer/mod.rs b/common/nymsphinx/src/preparer/mod.rs index 79fc778da0..d91a7c85a5 100644 --- a/common/nymsphinx/src/preparer/mod.rs +++ b/common/nymsphinx/src/preparer/mod.rs @@ -105,7 +105,7 @@ where } /// Allows setting non-default size of the sphinx packets sent out. - pub fn with_packet_size(mut self, packet_size: PacketSize) -> Self { + pub fn with_custom_real_message_packet_size(mut self, packet_size: PacketSize) -> Self { self.packet_size = packet_size; self }