Skip to content

Commit 599cc69

Browse files
committed
Add Simulation::add_async_party
Signed-off-by: Denis Varlakov <denis@dfns.co>
1 parent 687132f commit 599cc69

File tree

1 file changed

+19
-2
lines changed
  • round-based/src/simulation

1 file changed

+19
-2
lines changed

round-based/src/simulation/mod.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ where
248248
{
249249
let mut sim = Self::with_capacity(n);
250250
for i in 0..n {
251-
let party = crate::state_machine::wrap_protocol(|party| init(i, party));
252-
sim.add_party(party)
251+
sim.add_async_party(|party| init(i, party))
253252
}
254253
sim
255254
}
@@ -282,6 +281,24 @@ where
282281
})
283282
}
284283

284+
/// Adds new party, defined as an async function, into the protocol
285+
///
286+
/// New party will be assigned index `i = n - 1` where `n` is amount of parties in the
287+
/// simulation after this party was added.
288+
///
289+
/// Async function will be converted into a [state machine](crate::state_machine). Because of that,
290+
/// it cannot await on any futures that aren't provided by `MpcParty` (that is given as an argument
291+
/// to this function).
292+
pub fn add_async_party<F>(&mut self, party: impl FnOnce(crate::state_machine::MpcParty<M>) -> F)
293+
where
294+
F: core::future::Future<Output = O> + 'a,
295+
{
296+
self.parties.push(Party::Active {
297+
party: Box::new(crate::state_machine::wrap_protocol(party)),
298+
wants_one_more_msg: false,
299+
})
300+
}
301+
285302
/// Returns amount of parties in the simulation
286303
pub fn parties_amount(&self) -> usize {
287304
self.parties.len()

0 commit comments

Comments
 (0)