12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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<usize>,
- incoming_response: SyncSender<Vec<u8>>,
- outgoing_data: Receiver<Vec<u8>>,
- pub pub_params: Vec<u8>,
- }
- 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,
- }
- }
- }
|