Skip to content

Commit

Permalink
Send msgs as Vecs
Browse files Browse the repository at this point in the history
  • Loading branch information
fkettelhoit committed Sep 9, 2024
1 parent e9feb0f commit 656d66f
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 111 deletions.
2 changes: 1 addition & 1 deletion benches/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use garble_lang::{
use parlay::protocol::simulate_mpc_async;

fn join_benchmark(c: &mut Criterion) {
let n_records = 200;
let n_records = 10;
let code = include_str!(".join.garble.rs");

let bench_id = format!("join {n_records} records");
Expand Down
39 changes: 36 additions & 3 deletions src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ pub(crate) struct MsgChannel<C: Channel>(pub C);

impl<C: Channel> MsgChannel<C> {
/// Serializes and sends an MPC message to the other party.
pub(crate) async fn send_to(
pub(crate) async fn send_single_to<S: Serialize>(
&mut self,
party: usize,
phase: &str,
msg: &impl Serialize,
msg: &S,
) -> Result<(), Error> {
let msg = bincode::serialize(msg).map_err(|e| Error {
phase: format!("sending {phase}"),
Expand All @@ -74,7 +74,7 @@ impl<C: Channel> MsgChannel<C> {
}

/// Receives and deserializes an MPC message from the other party.
pub(crate) async fn recv_from<T: DeserializeOwned>(
pub(crate) async fn recv_single_from<T: DeserializeOwned>(
&mut self,
party: usize,
phase: &str,
Expand All @@ -89,6 +89,39 @@ impl<C: Channel> MsgChannel<C> {
})
}

/// Serializes and sends an MPC message to the other party.
pub(crate) async fn send_to<S: Serialize>(
&mut self,
party: usize,
phase: &str,
msg: &[S],
) -> Result<(), Error> {
let msg = bincode::serialize(msg).map_err(|e| Error {
phase: format!("sending {phase}"),
reason: ErrorKind::SerdeError(format!("{e:?}")),
})?;
self.0.send_bytes_to(party, msg).await.map_err(|e| Error {
phase: phase.to_string(),
reason: ErrorKind::SendError(format!("{e:?}")),
})
}

/// Receives and deserializes an MPC message from the other party.
pub(crate) async fn recv_from<T: DeserializeOwned>(
&mut self,
party: usize,
phase: &str,
) -> Result<Vec<T>, Error> {
let msg = self.0.recv_bytes_from(party).await.map_err(|e| Error {
phase: phase.to_string(),
reason: ErrorKind::RecvError(format!("{e:?}")),
})?;
bincode::deserialize(&msg).map_err(|e| Error {
phase: format!("receiving {phase}"),
reason: ErrorKind::SerdeError(format!("{e:?}")),
})
}

/// Receives and deserializes a Vec from the other party (while checking the length).
pub(crate) async fn recv_vec_from<T: DeserializeOwned>(
&mut self,
Expand Down
Loading

0 comments on commit 656d66f

Please sign in to comment.