Skip to content

Introduced a client-configurable option to force it to use extended packet size #1671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions clients/client-core/src/client/cover_traffic_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;
use task::ShutdownListener;
use tokio::task::JoinHandle;
use tokio::time;
use nymsphinx::params::PacketSize;

pub struct LoopCoverTrafficStream<R>
where
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -111,10 +115,15 @@ impl LoopCoverTrafficStream<OsRng> {
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!");

Expand All @@ -140,6 +149,7 @@ impl LoopCoverTrafficStream<OsRng> {
&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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use std::{
};
use task::ShutdownListener;
use tokio::task::JoinHandle;
use nymsphinx::params::PacketSize;

mod acknowledgement_listener;
mod action_controller;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<R>
Expand Down Expand Up @@ -176,7 +186,7 @@ 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(
Expand Down
13 changes: 11 additions & 2 deletions clients/client-core/src/client/real_messages_control/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::sync::Arc;
use std::time::Duration;
use task::ShutdownListener;
use tokio::task::JoinHandle;
use nymsphinx::params::PacketSize;

mod acknowledgement_control;
mod real_traffic_stream;
Expand Down Expand Up @@ -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 {
Expand All @@ -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<R>
Expand Down Expand Up @@ -119,7 +128,7 @@ impl RealMessagesController<OsRng> {
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,
Expand All @@ -137,7 +146,7 @@ impl RealMessagesController<OsRng> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::sync::Arc;
use std::time::Duration;
use task::ShutdownListener;
use tokio::time;
use nymsphinx::params::PacketSize;

/// Configurable parameters of the `OutQueueControl`
pub(crate) struct Config {
Expand All @@ -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 {
Expand All @@ -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<R>
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 8 additions & 0 deletions clients/client-core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ impl<T: NymConfig> Config<T> {
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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
}
}
18 changes: 14 additions & 4 deletions clients/native/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(),
Expand All @@ -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(
Expand All @@ -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(),
Expand All @@ -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(
Expand Down
18 changes: 14 additions & 4 deletions clients/socks5/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -102,8 +103,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(
Expand All @@ -115,7 +121,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(),
Expand All @@ -128,6 +134,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(
Expand Down
5 changes: 3 additions & 2 deletions common/nymsphinx/cover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub fn generate_loop_cover_packet<R>(
full_address: &Recipient,
average_ack_delay: time::Duration,
average_packet_delay: time::Duration,
packet_size: PacketSize,
) -> Result<MixPacket, CoverMessageError>
where
R: RngCore + CryptoRng,
Expand All @@ -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()
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion common/nymsphinx/src/preparer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down