diff --git a/network-runner/src/bin/app/main.rs b/network-runner/src/bin/app/main.rs index 0983481..cc4eada 100644 --- a/network-runner/src/bin/app/main.rs +++ b/network-runner/src/bin/app/main.rs @@ -9,8 +9,10 @@ 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::mix::{MixMessage, MixNode, MixNodeState}; -use nomos_simulations_network_runner::node::{NodeId, NodeIdExt}; +use nomos_simulations_network_runner::node::mix::{ + MixMessage, MixNode, MixNodeState, MixnodeSettings, +}; +use nomos_simulations_network_runner::node::{Node, NodeId, NodeIdExt}; use nomos_simulations_network_runner::output_processors::{OutData, Record}; use nomos_simulations_network_runner::runner::{BoxedNode, SimulationRunnerHandle}; #[cfg(feature = "polars")] @@ -19,6 +21,7 @@ use nomos_simulations_network_runner::streaming::{ io::IOSubscriber, naive::NaiveSubscriber, StreamType, }; use parking_lot::Mutex; +use rand::prelude::IteratorRandom; use rand::rngs::SmallRng; use rand::seq::SliceRandom; use rand::SeedableRng; @@ -90,10 +93,21 @@ impl SimulationApp { // )?; // } - let nodes: Vec> = node_ids - .par_iter() + let nodes: Vec<_> = node_ids + .iter() .copied() - .map(|node_id| create_boxed_mixnode(node_id)) + .map(|node_id| { + create_boxed_mixnode( + node_id, + MixnodeSettings { + connected_peers: ids + .iter() + .filter(|&id| id != &node_id) + .copied() + .choose_multiple(&mut rng, 3), + }, + ) + }) .collect(); let network = Arc::try_unwrap(network) .expect("network is not used anywhere else") @@ -103,8 +117,11 @@ impl SimulationApp { } } -fn create_boxed_mixnode(node_id: NodeId) -> BoxedNode<(), MixNodeState> { - Box::new(MixNode::new(node_id, ())) +fn create_boxed_mixnode( + node_id: NodeId, + settings: MixnodeSettings, +) -> BoxedNode { + Box::new(MixNode::new(node_id, settings)) } fn run( diff --git a/network-runner/src/node/mix/mod.rs b/network-runner/src/node/mix/mod.rs index fe6a5d4..b11ece2 100644 --- a/network-runner/src/node/mix/mod.rs +++ b/network-runner/src/node/mix/mod.rs @@ -13,16 +13,19 @@ 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, +pub struct MixnodeSettings { + pub connected_peers: Vec, } -impl MixNode { - pub fn new(id: NodeId, settings: S) -> Self { +/// This node implementation only used for testing different streaming implementation purposes. +pub struct MixNode { + id: NodeId, + state: MixNodeState, + settings: MixnodeSettings, +} + +impl MixNode { + pub fn new(id: NodeId, settings: MixnodeSettings) -> Self { Self { id, state: MixNodeState::default(), @@ -31,11 +34,8 @@ impl MixNode { } } -impl Node for MixNode -where - S: Send + Sync, -{ - type Settings = S; +impl Node for MixNode { + type Settings = MixnodeSettings; type State = MixNodeState;