Function seec_channel::sub_channel

source ·
pub async fn sub_channel<S, R, Msg, SubMsg>(
    sender: &mut S,
    receiver: &mut R,
    local_buffer: usize
) -> Result<(Sender<SubMsg>, Receiver<SubMsg>), CommunicationError>
where S: SenderT<Msg>, R: ReceiverT<Msg>, Sender<SubMsg>: Into<Msg>, Msg: Into<Option<Sender<SubMsg>>> + RemoteSend, SubMsg: RemoteSend, CommunicationError: From<S::Error> + From<R::Error>,
Examples found in repository?
crates/zappot/examples/co_base_ot.rs (line 36)
26
27
28
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
async fn sender(args: Args) -> Vec<[Block; 2]> {
    // Create a secure RNG to use in the protocol
    let mut rng = OsRng;
    let mut sender = Sender::new();
    // Create a channel by listening on a socket address. Once another party connect, this
    // returns the channel
    let (mut base_sender, _, mut base_receiver, _) =
        seec_channel::tcp::listen::<seec_channel::Sender<_>>(("127.0.0.1", args.port))
            .await
            .expect("Error listening for channel connection");
    let (ch_sender, mut ch_receiver) = sub_channel(&mut base_sender, &mut base_receiver, 8)
        .await
        .expect("Establishing sub channel");
    // Perform the random ots
    sender
        .send_random(args.num_ots, &mut rng, &ch_sender, &mut ch_receiver)
        .await
        .expect("Failed to generate ROTs")
}

/// Example of the receiver side
async fn receiver(args: Args) -> (Vec<Block>, BitVec) {
    // Create a secure RNG to use in the protocol
    let mut rng = OsRng;
    // Create the receiver. The struct holds no state
    let mut receiver = Receiver::new();
    // Connect to the sender on the listened on port
    let (mut base_sender, _, mut base_receiver, _) =
        seec_channel::tcp::connect::<seec_channel::Sender<_>>(("127.0.0.1", args.port))
            .await
            .expect("Error listening for channel connection");
    let (ch_sender, mut ch_receiver) = sub_channel(&mut base_sender, &mut base_receiver, 8)
        .await
        .expect("Establishing sub channel");

    // Randomly choose one of the blocks
    let choices: BitVec = rng
        .sample_iter::<bool, _>(distributions::Standard)
        .take(args.num_ots)
        .collect();

    // Perform the random ots
    let ots = receiver
        .receive_random(&choices, &mut rng, &ch_sender, &mut ch_receiver)
        .await
        .expect("Failed to generate ROTs");
    (ots, choices)
}
More examples
Hide additional examples
crates/zappot/examples/alsz_ot_extension.rs (line 41)
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
78
79
80
81
async fn sender(args: Args) -> (Vec<[Block; 2]>, usize, usize) {
    // Create a secure RNG to use in the protocol
    let mut rng = OsRng;
    // Create the ot extension sender. A base OT **receiver** is passed as an argument and used
    // to create the base_ots
    let mut sender = Sender::new(base_ot::Receiver);
    // Create a channel by listening on a socket address. Once another party connect, this
    // returns the channel
    let (mut base_sender, send_cnt, mut base_receiver, recv_cnt) =
        seec_channel::tcp::listen::<seec_channel::Sender<_>>(("127.0.0.1", args.port))
            .await
            .expect("Error listening for channel connection");
    let (ch_sender, mut ch_receiver) = sub_channel(&mut base_sender, &mut base_receiver, 128)
        .await
        .expect("Establishing sub channel");

    // Perform the random ots
    let ots = sender
        .send_random(args.num_ots, &mut rng, &ch_sender, &mut ch_receiver)
        .await
        .expect("Failed to generate ROTs");
    (ots, send_cnt.get(), recv_cnt.get())
}

/// Example of the receiver side
async fn receiver(args: Args) -> (Vec<Block>, BitVec) {
    // Create a secure RNG to use in the protocol
    let mut rng = OsRng;
    // Create the ot extension receiver. A base OT **sender** is passed as an argument and used
    // to create the base_ots
    let mut receiver = Receiver::new(base_ot::Sender);
    let (mut base_sender, _, mut base_receiver, _) =
        seec_channel::tcp::connect::<seec_channel::Sender<_>>(("127.0.0.1", args.port))
            .await
            .expect("Error listening for channel connection");
    let (ch_sender, mut ch_receiver) = sub_channel(&mut base_sender, &mut base_receiver, 128)
        .await
        .expect("Establishing sub channel");

    // Randomly choose one of the blocks
    let choices: BitVec = {
        let mut bv = bitvec![usize, Lsb0; 0; args.num_ots];
        rng.fill(bv.as_raw_mut_slice());
        bv
    };

    // Perform the random ot extension
    let ots = receiver
        .receive_random(&choices, &mut rng, &ch_sender, &mut ch_receiver)
        .await
        .expect("Failed to generate ROTs");
    (ots, choices)
}