Generate message with dummy probability (#20)

This commit is contained in:
Youngjoon Lee 2024-11-07 11:50:07 +09:00 committed by GitHub
parent 29f78e026e
commit 9d997e2b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 2 deletions

View File

@ -9,14 +9,16 @@ use futures::Stream;
use multiaddr::Multiaddr; use multiaddr::Multiaddr;
use nomos_mix::{ use nomos_mix::{
membership::Membership, membership::Membership,
message_blend::{MessageBlendExt, MessageBlendSettings, MessageBlendStream}, message_blend::{
crypto::CryptographicProcessor, MessageBlendExt, MessageBlendSettings, MessageBlendStream,
},
persistent_transmission::{ persistent_transmission::{
PersistentTransmissionExt, PersistentTransmissionSettings, PersistentTransmissionStream, PersistentTransmissionExt, PersistentTransmissionSettings, PersistentTransmissionStream,
}, },
MixOutgoingMessage, MixOutgoingMessage,
}; };
use nomos_mix_message::mock::MockMixMessage; use nomos_mix_message::mock::MockMixMessage;
use rand::SeedableRng; use rand::{Rng, RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng; use rand_chacha::ChaCha12Rng;
use scheduler::{Interval, TemporalRelease}; use scheduler::{Interval, TemporalRelease};
use serde::Deserialize; use serde::Deserialize;
@ -53,6 +55,8 @@ pub struct MixNode {
settings: MixnodeSettings, settings: MixnodeSettings,
network_interface: InMemoryNetworkInterface<MixMessage>, network_interface: InMemoryNetworkInterface<MixMessage>,
msg_gen_rng: ChaCha12Rng,
persistent_sender: channel::Sender<Vec<u8>>, persistent_sender: channel::Sender<Vec<u8>>,
persistent_update_time_sender: channel::Sender<Duration>, persistent_update_time_sender: channel::Sender<Duration>,
persistent_transmission_messages: PersistentTransmissionStream< persistent_transmission_messages: PersistentTransmissionStream<
@ -61,6 +65,7 @@ pub struct MixNode {
MockMixMessage, MockMixMessage,
Interval, Interval,
>, >,
crypto_processor: CryptographicProcessor<ChaCha12Rng, MockMixMessage>,
blend_sender: channel::Sender<Vec<u8>>, blend_sender: channel::Sender<Vec<u8>>,
blend_update_time_sender: channel::Sender<Duration>, blend_update_time_sender: channel::Sender<Duration>,
blend_messages: MessageBlendStream< blend_messages: MessageBlendStream<
@ -110,6 +115,11 @@ impl MixNode {
}) })
.collect(); .collect();
let membership = Membership::<MockMixMessage>::new(nodes, id.into()); let membership = Membership::<MockMixMessage>::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( let temporal_release = TemporalRelease::new(
ChaCha12Rng::from_rng(&mut rng_generator).unwrap(), ChaCha12Rng::from_rng(&mut rng_generator).unwrap(),
blend_update_time_receiver, blend_update_time_receiver,
@ -134,9 +144,11 @@ impl MixNode {
mock_counter: 0, mock_counter: 0,
step_id: 0, step_id: 0,
}, },
msg_gen_rng: ChaCha12Rng::from_rng(&mut rng_generator).unwrap(),
persistent_sender, persistent_sender,
persistent_update_time_sender, persistent_update_time_sender,
persistent_transmission_messages, persistent_transmission_messages,
crypto_processor,
blend_sender, blend_sender,
blend_update_time_sender, blend_update_time_sender,
blend_messages, blend_messages,
@ -175,11 +187,21 @@ impl Node for MixNode {
let Self { let Self {
persistent_sender, persistent_sender,
persistent_transmission_messages, persistent_transmission_messages,
crypto_processor,
blend_sender, blend_sender,
blend_messages, blend_messages,
.. ..
} = self; } = 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(); let messages = self.network_interface.receive_messages();
for message in messages { for message in messages {
println!(">>>>> Node {}, message: {message:?}", self.id); println!(">>>>> Node {}, message: {message:?}", self.id);