Add mixnode settings
This commit is contained in:
parent
7fb52dec17
commit
92a77fdff7
|
@ -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<BoxedNode<(), MixNodeState>> = 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<MixnodeSettings, MixNodeState> {
|
||||
Box::new(MixNode::new(node_id, settings))
|
||||
}
|
||||
|
||||
fn run<M: std::fmt::Debug, S, T>(
|
||||
|
|
|
@ -13,16 +13,19 @@ pub enum MixMessage {
|
|||
Dummy(String),
|
||||
}
|
||||
|
||||
/// This node implementation only used for testing different streaming implementation purposes.
|
||||
pub struct MixNode<S> {
|
||||
id: NodeId,
|
||||
state: MixNodeState,
|
||||
#[allow(dead_code)]
|
||||
settings: S,
|
||||
pub struct MixnodeSettings {
|
||||
pub connected_peers: Vec<NodeId>,
|
||||
}
|
||||
|
||||
impl<S: Send + Sync> MixNode<S> {
|
||||
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<S: Send + Sync> MixNode<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S> Node for MixNode<S>
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Settings = S;
|
||||
impl Node for MixNode {
|
||||
type Settings = MixnodeSettings;
|
||||
|
||||
type State = MixNodeState;
|
||||
|
||||
|
|
Loading…
Reference in New Issue