From c8563474b8a7e31fb8d107da2bb5824bd7e879a4 Mon Sep 17 00:00:00 2001 From: Denis Varlakov Date: Wed, 3 Aug 2022 18:11:40 +0200 Subject: [PATCH] Add useful methods to RoundInput --- round-based/src/rounds/store.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/round-based/src/rounds/store.rs b/round-based/src/rounds/store.rs index 007806c..8cfac3f 100644 --- a/round-based/src/rounds/store.rs +++ b/round-based/src/rounds/store.rs @@ -233,6 +233,20 @@ impl RoundInput { expected_msg_type: msg_type, } } + + /// Construct a new store for broadcast messages + /// + /// The same as `RoundInput::new(i, n, MessageType::Broadcast)` + pub fn broadcast(i: u16, n: u16) -> Self { + Self::new(i, n, MessageType::Broadcast) + } + + /// Construct a new store for p2p messages + /// + /// The same as `RoundInput::new(i, n, MessageType::P2P)` + pub fn p2p(i: u16, n: u16) -> Self { + Self::new(i, n, MessageType::P2P) + } } impl MessagesStore for RoundInput @@ -300,6 +314,14 @@ impl RoundMsgs { self.messages } + /// Iterator over received messages + /// + /// Iterator yields `(sender_index, message)` + pub fn enumerated(self) -> impl Iterator { + let indexes = (0..self.i).chain(self.i + 1..); + indexes.zip(self.messages) + } + pub fn into_vec_including_me(mut self, my_msg: M) -> Vec { self.messages.insert(usize::from(self.i), my_msg); self.messages