Skip to content

Commit 33007fa

Browse files
authored
Merge pull request #150 from sine-fdn/remove-message-chunking
Remove message chunking
2 parents a3b7b53 + 82bc50b commit 33007fa

File tree

7 files changed

+61
-210
lines changed

7 files changed

+61
-210
lines changed

docs/src/examples/channel.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The `Channel` trait in our MPC engine provides a flexible and extensible abstraction for message-passing between parties. It allows communication to be implemented in various ways, enabling users to choose between platform-specific implementations. Polytune is deliberately communication-agnostic, while remaining quite flexible, offering the following features:
44

55
- **Customizable Transport**: Implement the `Channel` trait using any transport mechanism — HTTP, WebSockets, in-memory queues, or custom networking protocols.
6-
- **Serialization-Aware**: The trait ensures that messages can be efficiently serialized and chunked when necessary, making it ideal for large payloads.
6+
- **Serialization-Aware**: The trait ensures that messages can be efficiently serialized.
77

88
We provide example implementations for:
99

@@ -37,13 +37,13 @@ trait Channel {
3737
&self,
3838
p: usize,
3939
msg: Vec<u8>,
40-
info: SendInfo,
40+
phase: &str,
4141
) -> Result<(), Self::SendError>;
4242

4343
async fn recv_bytes_from(
4444
&self,
4545
p: usize,
46-
info: RecvInfo,
46+
phase: &str,
4747
) -> Result<Vec<u8>, Self::RecvError>;
4848
}
4949
```
@@ -53,7 +53,7 @@ trait Channel {
5353
1. **Channel Parameters**:
5454

5555
- `p`: Index of the target party for send/receive
56-
- `info`: Various information useful for logging
56+
- `phase`: Phase of the protocol where the message is sent
5757
- `msg`: Message sent to the target party (only in `send_bytes_to`)
5858

5959
2. **Connection Management**:

examples/api-integration/src/main.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::{
88
};
99
use clap::Parser;
1010
use polytune::{
11-
channel::{Channel, RecvInfo, SendInfo},
11+
channel::Channel,
1212
garble_lang::{compile_with_constants, literal::Literal},
1313
mpc,
1414
};
@@ -373,25 +373,18 @@ impl Channel for HttpChannel {
373373
&self,
374374
p: usize,
375375
msg: Vec<u8>,
376-
info: SendInfo,
376+
phase: &str,
377377
) -> Result<(), Self::SendError> {
378378
let simulated_delay_in_ms = 300;
379379
let client = reqwest::Client::new();
380380
let url = format!("{}msg/{}", self.urls[p], self.party);
381381
let mb = msg.len() as f64 / 1024.0 / 1024.0;
382-
let i = info.sent();
383-
let total = info.total();
384-
let phase = info.phase();
385-
if i == 1 {
386-
info!("Sending msg {phase} to party {p} ({mb:.2}MB), {i}/{total}...");
387-
} else {
388-
info!(" (sending msg {phase} to party {p} ({mb:.2}MB), {i}/{total})");
389-
}
382+
info!("Sending msg {phase} to party {p} ({mb:.2}MB)...");
390383
loop {
391384
sleep(Duration::from_millis(simulated_delay_in_ms)).await;
392385
let req = client.post(&url).body(msg.clone()).send();
393386
let Ok(Ok(res)) = timeout(Duration::from_secs(1), req).await else {
394-
warn!(" req timeout: chunk {}/{} for party {}", i + 1, total, p);
387+
warn!(" req timeout: party {}", p);
395388
continue;
396389
};
397390
match res.status() {
@@ -408,7 +401,7 @@ impl Channel for HttpChannel {
408401
}
409402
}
410403

411-
async fn recv_bytes_from(&self, p: usize, _info: RecvInfo) -> Result<Vec<u8>, Self::RecvError> {
404+
async fn recv_bytes_from(&self, p: usize, _phase: &str) -> Result<Vec<u8>, Self::RecvError> {
412405
let mut r = self.recv[p].lock().await;
413406
timeout(Duration::from_secs(30 * 60), r.recv())
414407
.await

examples/http-multi-server-channels/src/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ use axum::{
66
routing::post,
77
};
88
use clap::Parser;
9-
use polytune::{
10-
channel::{Channel, RecvInfo, SendInfo},
11-
garble_lang::compile,
12-
mpc,
13-
};
9+
use polytune::{channel::Channel, garble_lang::compile, mpc};
1410
use reqwest::StatusCode;
1511
use std::{net::SocketAddr, path::PathBuf, result::Result, time::Duration};
1612
use tokio::{
@@ -112,7 +108,7 @@ impl Channel for HttpChannel {
112108
&self,
113109
p: usize,
114110
msg: Vec<u8>,
115-
_info: SendInfo,
111+
_phase: &str,
116112
) -> Result<(), Self::SendError> {
117113
let client = reqwest::Client::new();
118114
let url = format!("{}msg/{}", self.urls[p], self.party);
@@ -133,7 +129,7 @@ impl Channel for HttpChannel {
133129
}
134130
}
135131

136-
async fn recv_bytes_from(&self, p: usize, _info: RecvInfo) -> Result<Vec<u8>, Self::RecvError> {
132+
async fn recv_bytes_from(&self, p: usize, _phase: &str) -> Result<Vec<u8>, Self::RecvError> {
137133
let mut r = self.recv[p].lock().await;
138134
Ok(timeout(Duration::from_secs(1), r.recv())
139135
.await

examples/http-single-server-channels/src/http_channel.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::time::Duration;
22

3-
use polytune::channel::{Channel, RecvInfo, SendInfo};
3+
use polytune::channel::Channel;
44
use reqwest::StatusCode;
55
use tokio::time::sleep;
66

@@ -62,7 +62,7 @@ impl Channel for PollingHttpChannel {
6262
&self,
6363
p: usize,
6464
msg: Vec<u8>,
65-
_info: SendInfo,
65+
_phase: &str,
6666
) -> Result<(), HttpChannelError> {
6767
let url = format!("{}/send/{}/{}/{}", self.url, self.session, self.party, p);
6868
let resp: reqwest::Response = self.client.post(url).body(msg).send().await?;
@@ -73,11 +73,7 @@ impl Channel for PollingHttpChannel {
7373
}
7474
}
7575

76-
async fn recv_bytes_from(
77-
&self,
78-
p: usize,
79-
_info: RecvInfo,
80-
) -> Result<Vec<u8>, HttpChannelError> {
76+
async fn recv_bytes_from(&self, p: usize, _phase: &str) -> Result<Vec<u8>, HttpChannelError> {
8177
let url = format!("{}/recv/{}/{}/{}", self.url, self.session, p, self.party);
8278
let mut attempts = 0;
8379
loop {

examples/sql-integration/src/main.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::{
88
};
99
use clap::Parser;
1010
use polytune::{
11-
channel::{Channel, RecvInfo, SendInfo},
11+
channel::Channel,
1212
garble_lang::{
1313
ast::{Type, Variant},
1414
compile_with_constants,
@@ -689,25 +689,18 @@ impl Channel for HttpChannel {
689689
&self,
690690
p: usize,
691691
msg: Vec<u8>,
692-
info: SendInfo,
692+
phase: &str,
693693
) -> Result<(), Self::SendError> {
694694
let simulated_delay_in_ms = 300;
695695
let client = reqwest::Client::new();
696696
let url = format!("{}msg/{}", self.urls[p], self.party);
697697
let mb = msg.len() as f64 / 1024.0 / 1024.0;
698-
let i = info.sent();
699-
let total = info.total();
700-
let phase = info.phase();
701-
if i == 1 {
702-
info!("Sending msg {phase} to party {p} ({mb:.2}MB), {i}/{total}...");
703-
} else {
704-
info!(" (sending msg {phase} to party {p} ({mb:.2}MB), {i}/{total})");
705-
}
698+
info!("Sending msg {phase} to party {p} ({mb:.2}MB)...");
706699
loop {
707700
sleep(Duration::from_millis(simulated_delay_in_ms)).await;
708701
let req = client.post(&url).body(msg.clone()).send();
709702
let Ok(Ok(res)) = timeout(Duration::from_secs(1), req).await else {
710-
warn!(" req timeout: chunk {}/{} for party {}", i + 1, total, p);
703+
warn!(" req timeout: party {}", p);
711704
continue;
712705
};
713706
match res.status() {
@@ -724,7 +717,7 @@ impl Channel for HttpChannel {
724717
}
725718
}
726719

727-
async fn recv_bytes_from(&self, p: usize, _info: RecvInfo) -> Result<Vec<u8>, Self::RecvError> {
720+
async fn recv_bytes_from(&self, p: usize, _phase: &str) -> Result<Vec<u8>, Self::RecvError> {
728721
let mut r = self.recv[p].lock().await;
729722
timeout(Duration::from_secs(30 * 60), r.recv())
730723
.await

examples/wasm-http-channels/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::str::FromStr;
22

33
use gloo_timers::future::TimeoutFuture;
44
use polytune::{
5-
channel::{Channel, RecvInfo, SendInfo},
5+
channel::Channel,
66
garble_lang::{compile, literal::Literal, token::SignedNumType},
77
mpc,
88
};
@@ -64,7 +64,7 @@ impl Channel for HttpChannel {
6464
&self,
6565
p: usize,
6666
msg: Vec<u8>,
67-
_info: SendInfo,
67+
_phase: &str,
6868
) -> Result<(), Self::SendError> {
6969
let client = reqwest::Client::new();
7070
let url = format!("{}send/{}/{}", self.url, self.party, p);
@@ -83,7 +83,7 @@ impl Channel for HttpChannel {
8383
return Err(format!("Could not reach {url}"));
8484
}
8585

86-
async fn recv_bytes_from(&self, p: usize, _info: RecvInfo) -> Result<Vec<u8>, Self::RecvError> {
86+
async fn recv_bytes_from(&self, p: usize, _phase: &str) -> Result<Vec<u8>, Self::RecvError> {
8787
let client = reqwest::Client::new();
8888
let url = format!("{}recv/{}/{}", self.url, self.party, p);
8989
for _ in 0..50 {

0 commit comments

Comments
 (0)