|
@@ -27,12 +27,14 @@ use crate::VecData;
|
|
|
enum Command {
|
|
|
PreProc(usize),
|
|
|
PreProcFinish(Vec<PreProcSingleRespMsg>),
|
|
|
+ Query(usize),
|
|
|
}
|
|
|
|
|
|
enum Response {
|
|
|
PubParams(Vec<u8>),
|
|
|
PreProcMsg(Vec<u8>),
|
|
|
PreProcDone,
|
|
|
+ QueryMsg(Vec<u8>),
|
|
|
}
|
|
|
|
|
|
// The internal client state for a single outstanding preprocess query
|
|
@@ -79,6 +81,9 @@ impl Client {
|
|
|
// State for preprocessing queries ready to be used
|
|
|
let mut preproc_state: VecDeque<PreProcSingleState> = VecDeque::new();
|
|
|
|
|
|
+ // State for outstanding active queries
|
|
|
+ let mut query_state: VecDeque<PreProcSingleState> = VecDeque::new();
|
|
|
+
|
|
|
// Wait for commands
|
|
|
loop {
|
|
|
match incoming_cmd_recv.recv() {
|
|
@@ -120,6 +125,18 @@ impl Client {
|
|
|
preproc_out_state = Vec::new();
|
|
|
outgoing_resp_send.send(Response::PreProcDone).unwrap();
|
|
|
}
|
|
|
+ Ok(Command::Query(idx)) => {
|
|
|
+ // panic if there are no preproc states
|
|
|
+ // available
|
|
|
+ let nextstate = preproc_state.pop_front().unwrap();
|
|
|
+ let offset = (num_records + nextstate.rand_idx - idx) & num_records_mask;
|
|
|
+ let mut querymsg: Vec<u8> = Vec::new();
|
|
|
+ querymsg.extend(idx.to_le_bytes());
|
|
|
+ query_state.push_back(nextstate);
|
|
|
+ outgoing_resp_send
|
|
|
+ .send(Response::QueryMsg(querymsg))
|
|
|
+ .unwrap();
|
|
|
+ }
|
|
|
_ => panic!("Received something unexpected in client loop"),
|
|
|
}
|
|
|
}
|
|
@@ -160,6 +177,15 @@ impl Client {
|
|
|
_ => panic!("Received something unexpected in preproc_finish"),
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ pub fn query(&self, idx: usize) -> Vec<u8> {
|
|
|
+ self.incoming_cmd.send(Command::Query(idx)).unwrap();
|
|
|
+ let ret = match self.outgoing_resp.recv() {
|
|
|
+ Ok(Response::QueryMsg(x)) => x,
|
|
|
+ _ => panic!("Received something unexpected in preproc"),
|
|
|
+ };
|
|
|
+ ret
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#[repr(C)]
|
|
@@ -213,3 +239,13 @@ pub extern "C" fn spir_client_preproc_finish(
|
|
|
};
|
|
|
client.preproc_finish(&msg_slice);
|
|
|
}
|
|
|
+
|
|
|
+#[no_mangle]
|
|
|
+pub extern "C" fn spir_client_query(clientptr: *mut Client, idx: usize) -> VecData {
|
|
|
+ let client = unsafe {
|
|
|
+ assert!(!clientptr.is_null());
|
|
|
+ &mut *clientptr
|
|
|
+ };
|
|
|
+ let retvec = client.query(idx);
|
|
|
+ to_vecdata(retvec)
|
|
|
+}
|