|
@@ -2,20 +2,34 @@ use std::os::raw::c_uchar;
|
|
|
use std::sync::mpsc::*;
|
|
|
use std::thread::*;
|
|
|
|
|
|
+use rayon::prelude::*;
|
|
|
+
|
|
|
use spiral_rs::client::PublicParameters;
|
|
|
+use spiral_rs::client::Query;
|
|
|
use spiral_rs::params::Params;
|
|
|
|
|
|
+use crate::ot::*;
|
|
|
use crate::params;
|
|
|
+use crate::to_vecdata;
|
|
|
+use crate::PreProcSingleMsg;
|
|
|
+use crate::PreProcSingleRespMsg;
|
|
|
+use crate::VecData;
|
|
|
|
|
|
enum Command {
|
|
|
PubParams(Vec<u8>),
|
|
|
- PreProcMsg(Vec<u8>),
|
|
|
+ PreProcMsg(Vec<PreProcSingleMsg>),
|
|
|
}
|
|
|
|
|
|
enum Response {
|
|
|
PreProcResp(Vec<u8>),
|
|
|
}
|
|
|
|
|
|
+// The internal client state for a single preprocess query
|
|
|
+struct PreProcSingleState<'a> {
|
|
|
+ db_keys: Vec<[u8; 16]>,
|
|
|
+ query: Query<'a>,
|
|
|
+}
|
|
|
+
|
|
|
pub struct Server {
|
|
|
r: usize,
|
|
|
thread_handle: JoinHandle<()>,
|
|
@@ -30,9 +44,36 @@ impl Server {
|
|
|
let thread_handle = spawn(move || {
|
|
|
let spiral_params = params::get_spiral_params(r);
|
|
|
let pub_params = PublicParameters::deserialize(&spiral_params, &pub_params);
|
|
|
+
|
|
|
+ // State for preprocessing queries
|
|
|
+ let mut preproc_state: Vec<PreProcSingleState> = Vec::new();
|
|
|
+
|
|
|
+ // Wait for commands
|
|
|
loop {
|
|
|
match incoming_cmd_recv.recv() {
|
|
|
Err(_) => break,
|
|
|
+ Ok(Command::PreProcMsg(cliquery)) => {
|
|
|
+ let num_preproc = cliquery.len();
|
|
|
+ let mut resp_state: Vec<PreProcSingleState> =
|
|
|
+ Vec::with_capacity(num_preproc);
|
|
|
+ let mut resp_msg: Vec<PreProcSingleRespMsg> =
|
|
|
+ Vec::with_capacity(num_preproc);
|
|
|
+ cliquery
|
|
|
+ .into_par_iter()
|
|
|
+ .map(|q| {
|
|
|
+ let db_keys = gen_db_enc_keys(r);
|
|
|
+ let query = Query::deserialize(&spiral_params, &q.spc_query);
|
|
|
+ let ot_resp = otkey_serve(q.ot_query, &db_keys);
|
|
|
+ (
|
|
|
+ PreProcSingleState { db_keys, query },
|
|
|
+ PreProcSingleRespMsg { ot_resp },
|
|
|
+ )
|
|
|
+ })
|
|
|
+ .unzip_into_vecs(&mut resp_state, &mut resp_msg);
|
|
|
+ preproc_state.append(&mut resp_state);
|
|
|
+ let ret: Vec<u8> = bincode::serialize(&resp_msg).unwrap();
|
|
|
+ outgoing_resp_send.send(Response::PreProcResp(ret)).unwrap();
|
|
|
+ }
|
|
|
_ => panic!("Received something unexpected"),
|
|
|
}
|
|
|
}
|
|
@@ -44,6 +85,17 @@ impl Server {
|
|
|
outgoing_resp,
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ pub fn preproc_PIRs(&self, msg: &[u8]) -> Vec<u8> {
|
|
|
+ self.incoming_cmd
|
|
|
+ .send(Command::PreProcMsg(bincode::deserialize(msg).unwrap()))
|
|
|
+ .unwrap();
|
|
|
+ let ret = match self.outgoing_resp.recv() {
|
|
|
+ Ok(Response::PreProcResp(x)) => x,
|
|
|
+ _ => panic!("Received something unexpected in preproc_PIRs"),
|
|
|
+ };
|
|
|
+ ret
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[no_mangle]
|
|
@@ -71,3 +123,21 @@ pub extern "C" fn spir_server_free(server: *mut Server) {
|
|
|
Box::from_raw(server);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+#[no_mangle]
|
|
|
+pub extern "C" fn spir_server_preproc_PIRs(
|
|
|
+ serverptr: *mut Server,
|
|
|
+ msgdata: *const c_uchar,
|
|
|
+ msglen: usize,
|
|
|
+) -> VecData {
|
|
|
+ let server = unsafe {
|
|
|
+ assert!(!serverptr.is_null());
|
|
|
+ &mut *serverptr
|
|
|
+ };
|
|
|
+ let msg_slice = unsafe {
|
|
|
+ assert!(!msgdata.is_null());
|
|
|
+ std::slice::from_raw_parts(msgdata, msglen)
|
|
|
+ };
|
|
|
+ let retvec = server.preproc_PIRs(&msg_slice);
|
|
|
+ to_vecdata(retvec)
|
|
|
+}
|