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