From 6e18bc80d24910f30d1e648a81c47ecb09659af2 Mon Sep 17 00:00:00 2001 From: Gusto Date: Wed, 6 Nov 2024 04:20:39 +0200 Subject: [PATCH] Use network interface and add readme --- network-runner/README.md | 8 ++++++++ network-runner/config/mixnode.json | 15 +------------- network-runner/src/node/mix/mod.rs | 32 ++++++++++++++++-------------- 3 files changed, 26 insertions(+), 29 deletions(-) create mode 100644 network-runner/README.md diff --git a/network-runner/README.md b/network-runner/README.md new file mode 100644 index 0000000..41c0a90 --- /dev/null +++ b/network-runner/README.md @@ -0,0 +1,8 @@ +# Network Simulator + +## Running simulations + +To run the simulation use this command line: +```bash +cargo run -- --input-settings config/mixnode.json +``` diff --git a/network-runner/config/mixnode.json b/network-runner/config/mixnode.json index 5f32b3d..b2b494a 100644 --- a/network-runner/config/mixnode.json +++ b/network-runner/config/mixnode.json @@ -27,18 +27,5 @@ }, "node_count": 3, "seed": 0, - "record_settings": { - "node_id": true, - "current_view": true, - "highest_voted_view": true, - "local_high_qc": true, - "safe_blocks": true, - "last_view_timeout_qc": true, - "latest_committed_block": true, - "latest_committed_view": true, - "root_committee": true, - "parent_committee": true, - "child_committees": true, - "committed_blocks": true - } + "record_settings": {} } diff --git a/network-runner/src/node/mix/mod.rs b/network-runner/src/node/mix/mod.rs index 17fc021..21330cf 100644 --- a/network-runner/src/node/mix/mod.rs +++ b/network-runner/src/node/mix/mod.rs @@ -1,10 +1,8 @@ +use super::{Node, NodeId}; +use crate::network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize}; use serde::{Deserialize, Serialize}; use std::time::Duration; -use crate::network::{InMemoryNetworkInterface, NetworkInterface, PayloadSize}; - -use super::{Node, NodeId}; - #[derive(Debug, Default, Copy, Clone, Serialize, Deserialize)] pub struct MixNodeState { pub mock_counter: usize, @@ -17,7 +15,7 @@ pub enum MixMessage { impl PayloadSize for MixMessage { fn size_bytes(&self) -> u32 { - todo!() + 2208 } } @@ -29,7 +27,7 @@ pub struct MixnodeSettings { pub struct MixNode { id: NodeId, state: MixNodeState, - _settings: MixnodeSettings, + settings: MixnodeSettings, network_interface: InMemoryNetworkInterface, } @@ -42,7 +40,7 @@ impl MixNode { Self { id, network_interface, - _settings: settings, + settings, state: MixNodeState::default(), } } @@ -62,14 +60,18 @@ impl Node for MixNode { } fn step(&mut self, _: Duration) { - let _messages = self.network_interface.receive_messages(); - self.state.mock_counter += 1; - println!(">>>>> Node {}, Step: {}", self.id, self.state.mock_counter); + let messages = self.network_interface.receive_messages(); + for message in messages { + println!(">>>>> Node {}, message: {message:?}", self.id); + } - // Do stuff on the messages; - // Network interface can be passed into the functions for outputting the messages: - // ```rust - // self.network_interface.send_message(receiving_node_id, payload); - // ``` + self.state.mock_counter += 1; + + for node_id in self.settings.connected_peers.iter() { + self.network_interface.send_message( + *node_id, + MixMessage::Dummy(format!("Hello from node: {}", self.id)), + ) + } } }