diff --git a/CHANGELOG.md b/CHANGELOG.md index d7df31305a..0d60efba80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// - common/ledger: new library for communicating with a Ledger device ([#1640]) - native-client/socks5-client: `disable_loop_cover_traffic_stream` Debug config option to disable the separate loop cover traffic stream ([#1666]) - native-client/socks5-client: `disable_main_poisson_packet_distribution` Debug config option to make the client ignore poisson distribution in the main packet stream and ONLY send real message (and as fast as they come) ([#1664]) +- native-client/socks5-client: `use_extended_packet_size` Debug config option to make the client use 'ExtendedPacketSize' for its traffic (32kB as opposed to 2kB in 1.0.2) ([#1671]) ### Fixed @@ -34,6 +35,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// [#1664]: https://github.com/nymtech/nym/pull/1664 [#1666]: https://github.com/nymtech/nym/pull/1645 [#1669]: https://github.com/nymtech/nym/pull/1669 +[#1671]: https://github.com/nymtech/nym/pull/1671 ## [nym-binaries-1.0.2](https://github.com/nymtech/nym/tree/nym-binaries-1.0.2) diff --git a/clients/client-core/src/client/cover_traffic_stream.rs b/clients/client-core/src/client/cover_traffic_stream.rs index 0223635b81..6f5ac433e7 100644 --- a/clients/client-core/src/client/cover_traffic_stream.rs +++ b/clients/client-core/src/client/cover_traffic_stream.rs @@ -9,6 +9,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; @@ -50,6 +51,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, + /// Listen to shutdown signals. shutdown: ShutdownListener, } @@ -111,10 +115,15 @@ impl LoopCoverTrafficStream { our_full_destination, rng, topology_access, + packet_size: Default::default(), shutdown, } } + 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!"); @@ -140,6 +149,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 9314519a8a..2d8cfea156 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::client::{inbound_messages::InputMessageReceiver, topology_control::To use futures::channel::mpsc; use gateway_client::AcknowledgementReceiver; use log::*; +use nymsphinx::params::PacketSize; use nymsphinx::{ acknowledgements::AckKey, addressing::clients::Recipient, @@ -120,6 +121,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 { @@ -134,8 +138,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 eb9c839f51..9b2c0e120f 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; @@ -54,6 +55,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 { @@ -78,8 +82,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 28dc8b4287..8195108a27 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 @@ -13,6 +13,7 @@ use nymsphinx::addressing::clients::Recipient; use nymsphinx::chunking::fragment::FragmentIdentifier; use nymsphinx::cover::generate_loop_cover_packet; use nymsphinx::forwarding::packet::MixPacket; +use nymsphinx::params::PacketSize; use nymsphinx::utils::sample_poisson_duration; use rand::{CryptoRng, Rng}; use std::collections::VecDeque; @@ -36,6 +37,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 { @@ -50,8 +54,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 @@ -189,6 +199,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 b03e56b1ea..0d4196f246 100644 --- a/clients/client-core/src/config/mod.rs +++ b/clients/client-core/src/config/mod.rs @@ -244,6 +244,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 } @@ -461,6 +465,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 { @@ -477,6 +484,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 dab2723817..38238c3fd5 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(), @@ -101,8 +102,13 @@ impl NymClient { self.as_mix_recipient(), topology_accessor, shutdown, - ) - .start(); + ); + + if self.config.get_base().get_use_extended_packet_size() { + stream.set_custom_packet_size(PacketSize::ExtendedPacket) + } + + stream.start(); } fn start_real_traffic_controller( @@ -114,7 +120,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(), @@ -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/clients/socks5/src/client/mod.rs b/clients/socks5/src/client/mod.rs index 3bf1eaf4f8..5fdf9826d8 100644 --- a/clients/socks5/src/client/mod.rs +++ b/clients/socks5/src/client/mod.rs @@ -3,6 +3,11 @@ use std::sync::atomic::Ordering; +use crate::client::config::Config; +use crate::socks::{ + authentication::{AuthenticationMethods, Authenticator, User}, + server::SphinxSocksServer, +}; use client_core::client::cover_traffic_stream::LoopCoverTrafficStream; use client_core::client::inbound_messages::{ InputMessage, InputMessageReceiver, InputMessageSender, @@ -31,14 +36,9 @@ 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; -use crate::socks::{ - authentication::{AuthenticationMethods, Authenticator, User}, - server::SphinxSocksServer, -}; - pub mod config; // Channels used to control the main task from outside @@ -91,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(), @@ -102,8 +102,13 @@ impl NymClient { self.as_mix_recipient(), topology_accessor, shutdown, - ) - .start(); + ); + + if self.config.get_base().get_use_extended_packet_size() { + stream.set_custom_packet_size(PacketSize::ExtendedPacket) + } + + stream.start(); } fn start_real_traffic_controller( @@ -115,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(), @@ -128,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/client-libs/gateway-client/src/packet_router.rs b/common/client-libs/gateway-client/src/packet_router.rs index 13977efdc7..ed39c36984 100644 --- a/common/client-libs/gateway-client/src/packet_router.rs +++ b/common/client-libs/gateway-client/src/packet_router.rs @@ -59,11 +59,12 @@ impl PacketRouter { } else if received_packet.len() == PacketSize::RegularPacket.plaintext_size() - ack_overhead { + trace!("routing regular packet"); received_messages.push(received_packet); } else if received_packet.len() == PacketSize::ExtendedPacket.plaintext_size() - ack_overhead { - warn!("received extended packet? Did not expect this..."); + trace!("routing extended packet"); received_messages.push(received_packet); } else { // this can happen if other clients are not padding their messages diff --git a/common/nymsphinx/cover/src/lib.rs b/common/nymsphinx/cover/src/lib.rs index 3a545dbaa0..aaaff5a9b5 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, @@ -95,8 +96,7 @@ where >(rng, full_address.encryption_key()); let public_key_bytes = ephemeral_keypair.public_key().to_bytes(); - let cover_size = - PacketSize::default().plaintext_size() - public_key_bytes.len() - ack_bytes.len(); + let cover_size = packet_size.plaintext_size() - public_key_bytes.len() - ack_bytes.len(); let mut cover_content: Vec<_> = LOOP_COVER_MESSAGE_PAYLOAD .iter() @@ -129,7 +129,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 a51075290e..aeff800095 100644 --- a/common/nymsphinx/src/preparer/mod.rs +++ b/common/nymsphinx/src/preparer/mod.rs @@ -104,7 +104,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 }