diff --git a/network-runner/src/bin/app/main.rs b/network-runner/src/bin/app/main.rs index 5c07488..0983481 100644 --- a/network-runner/src/bin/app/main.rs +++ b/network-runner/src/bin/app/main.rs @@ -9,7 +9,8 @@ use clap::Parser; use nomos_simulations_network_runner::network::behaviour::create_behaviours; use nomos_simulations_network_runner::network::regions::{create_regions, RegionsData}; use nomos_simulations_network_runner::network::Network; -use nomos_simulations_network_runner::node::NodeId; +use nomos_simulations_network_runner::node::mix::{MixMessage, MixNode, MixNodeState}; +use nomos_simulations_network_runner::node::{NodeId, NodeIdExt}; use nomos_simulations_network_runner::output_processors::{OutData, Record}; use nomos_simulations_network_runner::runner::{BoxedNode, SimulationRunnerHandle}; #[cfg(feature = "polars")] @@ -67,7 +68,7 @@ impl SimulationApp { }); let mut rng = SmallRng::seed_from_u64(seed); let mut node_ids: Vec = (0..simulation_settings.node_count) - .map(|_| todo!()) + .map(NodeId::from_index) .collect(); node_ids.shuffle(&mut rng); @@ -76,7 +77,7 @@ impl SimulationApp { let regions_data = RegionsData::new(regions, behaviours); let ids = node_ids.clone(); - let network = Arc::new(Mutex::new(Network::<()>::new(regions_data, seed))); + let network = Arc::new(Mutex::new(Network::::new(regions_data, seed))); // if dump_overlay_info { // dump_json_to_file( @@ -89,19 +90,23 @@ impl SimulationApp { // )?; // } - // let nodes: Vec> = node_ids - // .par_iter() - // .copied() - // .map(|node_id| todo!()) - // .collect(); - // let network = Arc::try_unwrap(network) - // .expect("network is not used anywhere else") - // .into_inner(); - // run::<_, _, _>(network, nodes, simulation_settings, stream_type)?; + let nodes: Vec> = node_ids + .par_iter() + .copied() + .map(|node_id| create_boxed_mixnode(node_id)) + .collect(); + let network = Arc::try_unwrap(network) + .expect("network is not used anywhere else") + .into_inner(); + run::<_, _, _>(network, nodes, simulation_settings, stream_type)?; Ok(()) } } +fn create_boxed_mixnode(node_id: NodeId) -> BoxedNode<(), MixNodeState> { + Box::new(MixNode::new(node_id, ())) +} + fn run( network: Network, nodes: Vec>, diff --git a/network-runner/src/node/mix/mod.rs b/network-runner/src/node/mix/mod.rs new file mode 100644 index 0000000..fe6a5d4 --- /dev/null +++ b/network-runner/src/node/mix/mod.rs @@ -0,0 +1,53 @@ +use serde::{Deserialize, Serialize}; +use std::time::Duration; + +use super::{Node, NodeId}; + +#[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)] +pub struct MixNodeState { + pub mock_counter: usize, +} + +#[derive(Debug, Clone)] +pub enum MixMessage { + Dummy(String), +} + +/// This node implementation only used for testing different streaming implementation purposes. +pub struct MixNode { + id: NodeId, + state: MixNodeState, + #[allow(dead_code)] + settings: S, +} + +impl MixNode { + pub fn new(id: NodeId, settings: S) -> Self { + Self { + id, + state: MixNodeState::default(), + settings, + } + } +} + +impl Node for MixNode +where + S: Send + Sync, +{ + type Settings = S; + + type State = MixNodeState; + + fn id(&self) -> NodeId { + self.id + } + + fn state(&self) -> &Self::State { + &self.state + } + + fn step(&mut self, _: Duration) { + todo!() + } +} diff --git a/network-runner/src/node/mod.rs b/network-runner/src/node/mod.rs index eaa7cb2..5c85f15 100644 --- a/network-runner/src/node/mod.rs +++ b/network-runner/src/node/mod.rs @@ -1,5 +1,6 @@ #[cfg(test)] pub mod dummy_streaming; +pub mod mix; // std use std::{