From 4768e74d2c85061c866a72fb820922c3a39485cd Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Sat, 13 May 2023 08:17:42 +0200 Subject: [PATCH] First, stupid attempt (90% success) --- 03b-multi-node-broadcast/.gitignore | 1 + 03b-multi-node-broadcast/Cargo.lock | 429 +++++++++++++++++++++ 03b-multi-node-broadcast/Cargo.toml | 11 + 03b-multi-node-broadcast/src/connection.rs | 44 +++ 03b-multi-node-broadcast/src/main.rs | 115 ++++++ 03b-multi-node-broadcast/src/message.rs | 62 +++ 03b-multi-node-broadcast/src/node.rs | 28 ++ 03b-multi-node-broadcast/src/storage.rs | 36 ++ 8 files changed, 726 insertions(+) create mode 100644 03b-multi-node-broadcast/.gitignore create mode 100644 03b-multi-node-broadcast/Cargo.lock create mode 100644 03b-multi-node-broadcast/Cargo.toml create mode 100644 03b-multi-node-broadcast/src/connection.rs create mode 100644 03b-multi-node-broadcast/src/main.rs create mode 100644 03b-multi-node-broadcast/src/message.rs create mode 100644 03b-multi-node-broadcast/src/node.rs create mode 100644 03b-multi-node-broadcast/src/storage.rs diff --git a/03b-multi-node-broadcast/.gitignore b/03b-multi-node-broadcast/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/03b-multi-node-broadcast/.gitignore @@ -0,0 +1 @@ +/target diff --git a/03b-multi-node-broadcast/Cargo.lock b/03b-multi-node-broadcast/Cargo.lock new file mode 100644 index 0000000..78a9e6d --- /dev/null +++ b/03b-multi-node-broadcast/Cargo.lock @@ -0,0 +1,429 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ch03b-multi-node-broadcast" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "tokio", +] + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "libc" +version = "0.2.142" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-sys 0.45.0", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "proc-macro2" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.160" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.160" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "socket2" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "2.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tokio" +version = "1.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" +dependencies = [ + "autocfg", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/03b-multi-node-broadcast/Cargo.toml b/03b-multi-node-broadcast/Cargo.toml new file mode 100644 index 0000000..9efaa72 --- /dev/null +++ b/03b-multi-node-broadcast/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "ch03b-multi-node-broadcast" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +tokio = {version = "1", features = ["full"]} +serde = {version = "1", features = ["derive"] } +serde_json = "1" diff --git a/03b-multi-node-broadcast/src/connection.rs b/03b-multi-node-broadcast/src/connection.rs new file mode 100644 index 0000000..983d24c --- /dev/null +++ b/03b-multi-node-broadcast/src/connection.rs @@ -0,0 +1,44 @@ +use crate::message::Message; +use std::io::{BufRead, Write}; + +#[derive(Debug)] +pub struct Connection<'a> { + reader: std::io::BufReader>, + writer: std::io::Stdout, +} + +impl<'a> Connection<'a> { + pub fn new(stdin: std::io::Stdin) -> Self { + Connection { + reader: std::io::BufReader::new(stdin.lock()), + writer: std::io::stdout(), + } + } + + pub fn read_one(&mut self) -> Option { + let mut buf = String::new(); + let _ = self.reader.read_line(&mut buf); + return Some(Message::parse_message(buf)); + } + + pub fn read(&mut self) -> Option { + let mut buffer = String::new(); + + match self.reader.read_line(&mut buffer) { + Ok(bytes_read) => { + if bytes_read > 0 { + serde_json::from_str(&buffer).ok() + } else { + None + } + } + Err(_) => None, + } + } + + pub fn write(&mut self, message: Message) { + let message = Message::format_message(message); + writeln!(self.writer, "{}", message).unwrap(); + self.writer.flush().unwrap(); + } +} diff --git a/03b-multi-node-broadcast/src/main.rs b/03b-multi-node-broadcast/src/main.rs new file mode 100644 index 0000000..e3b662c --- /dev/null +++ b/03b-multi-node-broadcast/src/main.rs @@ -0,0 +1,115 @@ +mod connection; +mod message; +mod node; +mod storage; + +use crate::connection::Connection; +use crate::message::{Body, Message}; +use crate::node::Node; + +fn main() { + let stdin = std::io::stdin(); + let mut connection = Connection::new(stdin); + + let mut node = init_node(&mut connection); + + while let Some(message) = connection.read() { + handle_message(&mut node, &mut connection, message); + } +} + +fn init_node(connection: &mut Connection) -> Node { + let input = connection.read_one().expect("Didn't get input"); + + let node; + match input.body { + Body::Init { msg_id, .. } => { + node = Node::init(input.clone()); + + let response = Message { + src: node.id.clone(), + dest: input.src, + body: Body::InitOk { + in_reply_to: msg_id, + }, + }; + + connection.write(response); + } + _ => panic!("Node is not initalized yet"), + } + + node +} + +fn handle_message(node: &mut Node, connection: &mut Connection, input: Message) { + match input.body { + Body::Broadcast { msg_id, message } => { + node.storage.add_message(message); + + let response = Message { + src: node.id.clone(), + dest: input.src, + body: Body::BroadcastOk { + msg_id, + in_reply_to: msg_id, + }, + }; + + connection.write(response); + + let nodes = node.storage.get_neighbours(node.id.clone()); + + for n in nodes { + let output = Message { + src: node.id.clone(), + dest: n, + body: Body::Broadcast { + msg_id, + message: node.storage.get_messages().last().unwrap().clone(), + }, + }; + + connection.write(output); + } + } + Body::Read { msg_id } => { + let output = Message { + src: node.id.clone(), + dest: input.src, + body: Body::ReadOk { + msg_id, + in_reply_to: msg_id, + messages: node.storage.get_messages(), + }, + }; + + connection.write(output); + } + Body::Topology { msg_id, topology } => { + node.storage.init_topology(topology); + + let output = Message { + src: node.id.clone(), + dest: input.src, + body: Body::TopologyOk { + msg_id, + in_reply_to: msg_id, + }, + }; + + connection.write(output); + } + Body::Error { + in_reply_to, + code, + text, + } => { + eprintln!( + "Error received (in_reply_to: {}, code: {}, text: {})", + in_reply_to, code, text + ); + } + _ => (), + } +} diff --git a/03b-multi-node-broadcast/src/message.rs b/03b-multi-node-broadcast/src/message.rs new file mode 100644 index 0000000..356fa6f --- /dev/null +++ b/03b-multi-node-broadcast/src/message.rs @@ -0,0 +1,62 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct Message { + pub src: String, + pub dest: String, + pub body: Body, +} + +#[derive(Clone, Serialize, Deserialize, Debug)] +#[serde(tag = "type")] +#[serde(rename_all = "snake_case")] +pub enum Body { + Error { + in_reply_to: u64, + code: u64, + text: String, + }, + Init { + msg_id: u64, + node_id: String, + node_ids: Vec, + }, + InitOk { + in_reply_to: u64, + }, + Broadcast { + msg_id: u64, + message: u64, + }, + BroadcastOk { + msg_id: u64, + in_reply_to: u64, + }, + Read { + msg_id: u64, + }, + ReadOk { + msg_id: u64, + in_reply_to: u64, + messages: Vec, + }, + Topology { + msg_id: u64, + topology: HashMap>, + }, + TopologyOk { + msg_id: u64, + in_reply_to: u64, + }, +} + +impl Message { + pub(crate) fn parse_message(message: String) -> Message { + serde_json::from_str(&message).unwrap() + } + + pub(crate) fn format_message(message: Message) -> String { + serde_json::to_string(&message).unwrap() + } +} diff --git a/03b-multi-node-broadcast/src/node.rs b/03b-multi-node-broadcast/src/node.rs new file mode 100644 index 0000000..03ae7c1 --- /dev/null +++ b/03b-multi-node-broadcast/src/node.rs @@ -0,0 +1,28 @@ +use serde::{Deserialize, Serialize}; + +use crate::message::{Body, Message}; +use crate::storage::Storage; + +#[derive(Serialize, Deserialize, Debug, Default)] +pub(crate) struct Node { + pub(crate) id: String, + pub(crate) availble_nodes: Vec, + pub(crate) storage: Storage, +} + +impl Node { + pub(crate) fn init(message: Message) -> Node { + match message.body { + Body::Init { + node_id, node_ids, .. + } => { + return Node { + id: node_id, + availble_nodes: node_ids, + storage: Storage::new(), + } + } + _ => panic!("Invalid message type"), + } + } +} diff --git a/03b-multi-node-broadcast/src/storage.rs b/03b-multi-node-broadcast/src/storage.rs new file mode 100644 index 0000000..8f6ae0c --- /dev/null +++ b/03b-multi-node-broadcast/src/storage.rs @@ -0,0 +1,36 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Serialize, Deserialize, Debug, Default)] +pub(crate) struct Topology(pub(crate) HashMap>); + +#[derive(Serialize, Deserialize, Debug, Default)] +pub(crate) struct Messages(pub(crate) Vec); + +#[derive(Serialize, Deserialize, Debug, Default)] +pub(crate) struct Storage { + pub(crate) messages: Messages, + pub(crate) topology: Topology, +} + +impl Storage { + pub(crate) fn new() -> Storage { + Storage::default() + } + + pub(crate) fn add_message(&mut self, message: u64) { + self.messages.0.push(message); + } + + pub(crate) fn get_messages(&mut self) -> Vec { + self.messages.0.to_owned() + } + + pub(crate) fn init_topology(&mut self, topology: HashMap>) { + self.topology.0 = topology; + } + + pub(crate) fn get_neighbours(&mut self, node_id: String) -> Vec { + self.topology.0.get(&node_id).unwrap().to_owned() + } +}