Loop cover messages having parameterized delays
This commit is contained in:
@@ -3,10 +3,10 @@ use addressing::AddressTypeError;
|
||||
use sphinx::route::{Destination, DestinationAddressBytes, SURBIdentifier};
|
||||
use sphinx::SphinxPacket;
|
||||
use std::net::SocketAddr;
|
||||
use std::time;
|
||||
use topology::{NymTopology, NymTopologyError};
|
||||
|
||||
pub const LOOP_COVER_MESSAGE_PAYLOAD: &[u8] = b"The cake is a lie!";
|
||||
pub const LOOP_COVER_MESSAGE_AVERAGE_DELAY: f64 = 2.0;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum SphinxPacketEncapsulationError {
|
||||
@@ -43,6 +43,7 @@ pub fn loop_cover_message<T: NymTopology>(
|
||||
our_address: DestinationAddressBytes,
|
||||
surb_id: SURBIdentifier,
|
||||
topology: &T,
|
||||
average_delay_duration: time::Duration,
|
||||
) -> Result<(SocketAddr, SphinxPacket), SphinxPacketEncapsulationError> {
|
||||
let destination = Destination::new(our_address, surb_id);
|
||||
|
||||
@@ -50,7 +51,7 @@ pub fn loop_cover_message<T: NymTopology>(
|
||||
destination,
|
||||
LOOP_COVER_MESSAGE_PAYLOAD.to_vec(),
|
||||
topology,
|
||||
LOOP_COVER_MESSAGE_AVERAGE_DELAY,
|
||||
average_delay_duration,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -58,7 +59,7 @@ pub fn encapsulate_message<T: NymTopology>(
|
||||
recipient: Destination,
|
||||
message: Vec<u8>,
|
||||
topology: &T,
|
||||
average_delay: f64,
|
||||
average_delay_duration: time::Duration,
|
||||
) -> Result<(SocketAddr, SphinxPacket), SphinxPacketEncapsulationError> {
|
||||
let mut providers = topology.providers();
|
||||
if providers.len() == 0 {
|
||||
@@ -69,7 +70,8 @@ pub fn encapsulate_message<T: NymTopology>(
|
||||
|
||||
let route = topology.route_to(provider)?;
|
||||
|
||||
let delays = sphinx::header::delays::generate(route.len(), average_delay);
|
||||
let delays =
|
||||
sphinx::header::delays::generate_from_average_duration(route.len(), average_delay_duration);
|
||||
|
||||
// build the packet
|
||||
let packet = sphinx::SphinxPacket::new(message, &route[..], &recipient, &delays)?;
|
||||
|
||||
@@ -10,12 +10,14 @@ pub(crate) async fn start_loop_cover_traffic_stream<T: NymTopology>(
|
||||
tx: mpsc::UnboundedSender<MixMessage>,
|
||||
our_info: Destination,
|
||||
topology_ctrl_ref: TopologyInnerRef<T>,
|
||||
average_delay_duration: time::Duration,
|
||||
average_cover_message_delay_duration: time::Duration,
|
||||
average_packet_delay_duration: time::Duration,
|
||||
) {
|
||||
info!("Starting loop cover traffic stream");
|
||||
loop {
|
||||
trace!("next cover message!");
|
||||
let delay_duration = mix_client::poisson::sample_from_duration(average_delay_duration);
|
||||
let delay_duration =
|
||||
mix_client::poisson::sample_from_duration(average_cover_message_delay_duration);
|
||||
tokio::time::delay_for(delay_duration).await;
|
||||
|
||||
let read_lock = topology_ctrl_ref.read().await;
|
||||
@@ -31,6 +33,7 @@ pub(crate) async fn start_loop_cover_traffic_stream<T: NymTopology>(
|
||||
our_info.address,
|
||||
our_info.identifier,
|
||||
topology,
|
||||
average_packet_delay_duration,
|
||||
) {
|
||||
Ok(message) => message,
|
||||
Err(err) => {
|
||||
|
||||
@@ -145,6 +145,7 @@ impl NymClient {
|
||||
Destination::new(self_address, Default::default()),
|
||||
topology_controller.get_inner_ref(),
|
||||
self.config.get_loop_cover_traffic_average_delay(),
|
||||
self.config.get_average_packet_delay(),
|
||||
));
|
||||
|
||||
// cloning arguments required by OutQueueControl; required due to move
|
||||
|
||||
@@ -106,6 +106,7 @@ impl<T: NymTopology> OutQueueControl<T> {
|
||||
self.our_info.address,
|
||||
self.our_info.identifier,
|
||||
topology,
|
||||
self.average_packet_delay,
|
||||
),
|
||||
StreamMessage::Real(real_message) => mix_client::packet::encapsulate_message(
|
||||
real_message.0,
|
||||
|
||||
Reference in New Issue
Block a user