From 9d997e2b5415052a6fcf29935f5cc19873e10a87 Mon Sep 17 00:00:00 2001 From: Youngjoon Lee <5462944+youngjoon-lee@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:50:07 +0900 Subject: [PATCH] Generate message with dummy probability (#20) --- network-runner/src/node/mix/mod.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/network-runner/src/node/mix/mod.rs b/network-runner/src/node/mix/mod.rs index 9e70381..44dc5d4 100644 --- a/network-runner/src/node/mix/mod.rs +++ b/network-runner/src/node/mix/mod.rs @@ -9,14 +9,16 @@ use futures::Stream; use multiaddr::Multiaddr; use nomos_mix::{ membership::Membership, - message_blend::{MessageBlendExt, MessageBlendSettings, MessageBlendStream}, + message_blend::{ + crypto::CryptographicProcessor, MessageBlendExt, MessageBlendSettings, MessageBlendStream, + }, persistent_transmission::{ PersistentTransmissionExt, PersistentTransmissionSettings, PersistentTransmissionStream, }, MixOutgoingMessage, }; use nomos_mix_message::mock::MockMixMessage; -use rand::SeedableRng; +use rand::{Rng, RngCore, SeedableRng}; use rand_chacha::ChaCha12Rng; use scheduler::{Interval, TemporalRelease}; use serde::Deserialize; @@ -53,6 +55,8 @@ pub struct MixNode { settings: MixnodeSettings, network_interface: InMemoryNetworkInterface, + msg_gen_rng: ChaCha12Rng, + persistent_sender: channel::Sender>, persistent_update_time_sender: channel::Sender, persistent_transmission_messages: PersistentTransmissionStream< @@ -61,6 +65,7 @@ pub struct MixNode { MockMixMessage, Interval, >, + crypto_processor: CryptographicProcessor, blend_sender: channel::Sender>, blend_update_time_sender: channel::Sender, blend_messages: MessageBlendStream< @@ -110,6 +115,11 @@ impl MixNode { }) .collect(); let membership = Membership::::new(nodes, id.into()); + let crypto_processor = CryptographicProcessor::new( + settings.message_blend.cryptographic_processor.clone(), + membership.clone(), + ChaCha12Rng::from_rng(&mut rng_generator).unwrap(), + ); let temporal_release = TemporalRelease::new( ChaCha12Rng::from_rng(&mut rng_generator).unwrap(), blend_update_time_receiver, @@ -134,9 +144,11 @@ impl MixNode { mock_counter: 0, step_id: 0, }, + msg_gen_rng: ChaCha12Rng::from_rng(&mut rng_generator).unwrap(), persistent_sender, persistent_update_time_sender, persistent_transmission_messages, + crypto_processor, blend_sender, blend_update_time_sender, blend_messages, @@ -175,11 +187,21 @@ impl Node for MixNode { let Self { persistent_sender, persistent_transmission_messages, + crypto_processor, blend_sender, blend_messages, .. } = self; + // Generate a message probabilistically (1 % chance) + // TODO: Replace this with the actual cover message generation + if self.msg_gen_rng.gen_range(0..100) == 0 { + let mut payload = [0u8; 1024]; + self.msg_gen_rng.fill_bytes(&mut payload); + let message = crypto_processor.wrap_message(&payload).unwrap(); + persistent_sender.send(message).unwrap(); + } + let messages = self.network_interface.receive_messages(); for message in messages { println!(">>>>> Node {}, message: {message:?}", self.id);