Function seec_channel::sync

source ·
pub async fn sync<S, R>(
    sender: &mut S,
    receiver: &mut R
) -> Result<(), CommunicationError>
Examples found in repository?
crates/seec/examples/precompute_mts.rs (line 72)
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
async fn main() -> anyhow::Result<()> {
    // Initialize logging, see top of file for instructions on how to get output.
    tracing_subscriber::fmt()
        .with_env_filter(EnvFilter::from_default_env())
        .init();

    let args = Args::parse();

    let (mut sender, bytes_written, mut receiver, bytes_read) = match args.id {
        0 => seec_channel::tcp::listen(&args.server).await?,
        1 => {
            seec_channel::tcp::connect_with_timeout(&args.server, Duration::from_secs(120)).await?
        }
        illegal => anyhow::bail!("Illegal party id {illegal}. Must be 0 or 1."),
    };

    let (mt_ch, mut sync_ch) = sub_channels_for!(
        &mut sender,
        &mut receiver,
        128,
        mul_triple::boolean::ot_ext::DefaultMsg,
        seec_channel::SyncMsg
    )
    .await
    .context("sub-channel establishment")?;

    let mtp =
        mul_triple::boolean::ot_ext::OtMTProvider::new_with_default_ot_ext(OsRng, mt_ch.0, mt_ch.1);

    let mut mt_storage = MTStorage::create(&args.output).context("create mt storage")?;
    mt_storage.set_batch_size(args.batch_size);
    let now = Instant::now();
    mt_storage
        .store_mts(args.num, mtp)
        .await
        .context("unable to precompute and store MTs")?;
    info!(
        elapsed_ms = now.elapsed().as_millis(),
        bytes_written = bytes_written.get(),
        bytes_received = bytes_read.get(),
        "Finished precomputing MTs"
    );

    seec_channel::sync(&mut sync_ch.0, &mut sync_ch.1)
        .await
        .context("unable to sync")?;

    Ok(())
}