use rand::RngCore; use rand::rngs::ThreadRng; use std::thread::*; use std::sync::mpsc::*; use crate::params; pub struct Client { r: usize, thread_handle: JoinHandle<()>, incoming_query: SyncSender, incoming_response: SyncSender>, outgoing_data: Receiver>, pub pub_params: Vec, } impl Client { pub fn new(r: usize) -> Self { let (incoming_query, incoming_query_recv) = sync_channel(0); let (incoming_response, incoming_response_recv) = sync_channel(0); let (outgoing_data_send, outgoing_data) = sync_channel(0); let thread_handle = spawn(move || { let spiral_params = params::get_spiral_params(r); let mut clientrng = rand::thread_rng(); let mut spiral_client = spiral_rs::client::Client::init(&spiral_params, &mut clientrng); // The first communication is the pub_params let pub_params = spiral_client.generate_keys().serialize(); outgoing_data_send.send(pub_params).unwrap(); }); let pub_params = outgoing_data.recv().unwrap(); Client { r, thread_handle, incoming_query, incoming_response, outgoing_data, pub_params, } } }