diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 08418ea..e6c1ecd 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -1,7 +1,7 @@ name: Security audit on: pull_request: - branches: [ "*" ] + branches: [ "**" ] paths: - '**/Cargo.toml' - '**/Cargo.lock' @@ -12,4 +12,4 @@ jobs: - uses: actions/checkout@v3 - uses: rustsec/audit-check@v1.4.1 with: - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index 4907af8..f7c07ef 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -2,7 +2,7 @@ name: Check README on: pull_request: - branches: [ "*" ] + branches: [ "**" ] env: CARGO_TERM_COLOR: always @@ -21,4 +21,4 @@ jobs: run: | cp README.md README-copy.md make readme - diff README.md README-copy.md \ No newline at end of file + diff README.md README-copy.md diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 66ed82f..f87894d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,7 +2,7 @@ name: Rust on: pull_request: - branches: [ "*" ] + branches: [ "**" ] env: CARGO_TERM_COLOR: always diff --git a/Cargo.lock b/Cargo.lock index a86357a..84e8fc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -463,7 +463,7 @@ dependencies = [ [[package]] name = "round-based" -version = "0.4.0" +version = "0.4.2" dependencies = [ "anyhow", "futures", diff --git a/round-based/CHANGELOG.md b/round-based/CHANGELOG.md index 1d9cb1c..35643a0 100644 --- a/round-based/CHANGELOG.md +++ b/round-based/CHANGELOG.md @@ -1,6 +1,13 @@ +## v0.4.2 +* Add `RoundInput::received_msg_from` method [#19] + +[#19]: https://github.com/LFDT-Lockness/round-based/pull/19 + ## v0.4.1 * Add methods to MpcParty to change its components [#15] +[#15]: https://github.com/LFDT-Lockness/round-based/pull/15 + ## v0.4.0 * BREAKING: Improve ergonomics of protocol simulation, which is used for writing tests [#14] * Remove `dev` feature, it's replaced with `sim` and `sim-async` diff --git a/round-based/Cargo.toml b/round-based/Cargo.toml index 3cea8fe..2055025 100644 --- a/round-based/Cargo.toml +++ b/round-based/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "round-based" -version = "0.4.1" +version = "0.4.2" edition = "2021" license = "MIT OR Apache-2.0" description = "Driver for MPC protocols" diff --git a/round-based/src/rounds_router/simple_store.rs b/round-based/src/rounds_router/simple_store.rs index 265dd80..e88969d 100644 --- a/round-based/src/rounds_router/simple_store.rs +++ b/round-based/src/rounds_router/simple_store.rs @@ -97,6 +97,45 @@ impl RoundInput { Self::new(i, n, MessageType::P2P) } + /// Checks if message from party `j` has already been received + /// + /// Returns `true` if the store has previously obtained a message from party `j` through + /// [`RoundInput::add_message`] call. Returns `false` if `j` corresponds to index of local party + /// `i` (provided in constructor like [`RoundInput::new`]), if `j ≥ n` (`n` is amount of parties + /// provided in constructor like [`RoundInput::new`]), or if message from party `j` is not yet + /// received. + /// + /// ## Example + /// ```rust + /// # use round_based::rounds_router::{MessagesStore, simple_store::RoundInput}; + /// # use round_based::{Incoming, MessageType}; + /// # fn main() -> Result<(), Box> { + /// let mut input = RoundInput::<&'static str>::broadcast(1, 3); + /// assert!(!input.received_msg_from(0)); + /// input.add_message(Incoming{ + /// id: 0, + /// sender: 0, + /// msg_type: MessageType::Broadcast, + /// msg: "first party message", + /// })?; + /// assert!(input.received_msg_from(0)); + /// # + /// # Ok(()) } + /// ``` + pub fn received_msg_from(&self, j: PartyIndex) -> bool { + let j = if j < self.i { + j + } else if j == self.i { + return false; + } else { + j - 1 + }; + self.messages + .get(usize::from(j)) + .map(|slot| slot.is_some()) + .unwrap_or(false) + } + fn is_expected_type_of_msg(&self, msg_type: MessageType) -> bool { self.expected_msg_type == msg_type }