Skip to content

Commit

Permalink
Add Simulation::add_async_party
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Varlakov <[email protected]>
  • Loading branch information
survived committed Nov 28, 2024
1 parent 687132f commit 599cc69
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions round-based/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ where
{
let mut sim = Self::with_capacity(n);
for i in 0..n {
let party = crate::state_machine::wrap_protocol(|party| init(i, party));
sim.add_party(party)
sim.add_async_party(|party| init(i, party))
}
sim
}
Expand Down Expand Up @@ -282,6 +281,24 @@ where
})
}

/// Adds new party, defined as an async function, into the protocol
///
/// New party will be assigned index `i = n - 1` where `n` is amount of parties in the
/// simulation after this party was added.
///
/// Async function will be converted into a [state machine](crate::state_machine). Because of that,
/// it cannot await on any futures that aren't provided by `MpcParty` (that is given as an argument
/// to this function).
pub fn add_async_party<F>(&mut self, party: impl FnOnce(crate::state_machine::MpcParty<M>) -> F)
where
F: core::future::Future<Output = O> + 'a,
{
self.parties.push(Party::Active {
party: Box::new(crate::state_machine::wrap_protocol(party)),
wants_one_more_msg: false,
})
}

/// Returns amount of parties in the simulation
pub fn parties_amount(&self) -> usize {
self.parties.len()
Expand Down

0 comments on commit 599cc69

Please sign in to comment.