|
@@ -1,43 +1,66 @@
|
|
|
-use crate::{Fetch, Send};
|
|
|
-use otils::ObliviousOps;
|
|
|
use std::{cmp::Ordering, time::UNIX_EPOCH};
|
|
|
|
|
|
-pub const FETCH: u32 = 0;
|
|
|
-pub const SEND: u32 = 1;
|
|
|
-pub const DUMMY: u32 = 2;
|
|
|
+use otils::Max;
|
|
|
+
|
|
|
+pub const FETCH: u16 = 0;
|
|
|
+pub const SEND: u16 = 1;
|
|
|
+pub const DUMMY: u16 = 2;
|
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
pub struct Request {
|
|
|
- pub receiver: i64,
|
|
|
- pub req_type: u32,
|
|
|
- pub mark: u32,
|
|
|
+ pub uid: i32,
|
|
|
+ pub req_type: u16,
|
|
|
+ pub mark: u16,
|
|
|
pub volume: usize,
|
|
|
pub message: u64,
|
|
|
+ pub _dum: [u64; 13],
|
|
|
}
|
|
|
|
|
|
impl Request {
|
|
|
- pub fn dummies(receiver: i64, len: usize) -> Vec<Self> {
|
|
|
+ pub fn new_send(uid: i32, message: u64) -> Self {
|
|
|
+ if uid >= i32::MAX {
|
|
|
+ panic!("uid: out of bounds.");
|
|
|
+ }
|
|
|
+ Request {
|
|
|
+ uid,
|
|
|
+ req_type: SEND,
|
|
|
+ mark: 0,
|
|
|
+ volume: std::time::SystemTime::now()
|
|
|
+ .duration_since(UNIX_EPOCH)
|
|
|
+ .unwrap()
|
|
|
+ .as_nanos() as usize,
|
|
|
+ message,
|
|
|
+ _dum: [0; 13],
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn new_fetch(uid: i32, volume: usize) -> Self {
|
|
|
+ if uid >= i32::MAX {
|
|
|
+ panic!("uid: out of bounds.");
|
|
|
+ }
|
|
|
+ Request {
|
|
|
+ uid,
|
|
|
+ req_type: FETCH,
|
|
|
+ mark: 0,
|
|
|
+ volume,
|
|
|
+ message: 0,
|
|
|
+ _dum: [0; 13],
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn dummies(uid: i32, len: usize) -> Vec<Self> {
|
|
|
(0..len)
|
|
|
.map(|_| Request {
|
|
|
- receiver,
|
|
|
+ uid,
|
|
|
req_type: DUMMY,
|
|
|
mark: 0,
|
|
|
volume: 0,
|
|
|
message: 0,
|
|
|
+ _dum: [0; 13],
|
|
|
})
|
|
|
.collect()
|
|
|
}
|
|
|
|
|
|
- pub fn max() -> Self {
|
|
|
- Request {
|
|
|
- receiver: i64::MAX,
|
|
|
- req_type: FETCH,
|
|
|
- mark: 0,
|
|
|
- volume: 0,
|
|
|
- message: 0,
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
pub fn is_fetch(&self) -> bool {
|
|
|
self.req_type == FETCH
|
|
|
}
|
|
@@ -51,43 +74,55 @@ impl Request {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl From<Send> for Request {
|
|
|
- fn from(s: Send) -> Self {
|
|
|
- Request {
|
|
|
- receiver: s.receiver,
|
|
|
- req_type: SEND,
|
|
|
- mark: 0,
|
|
|
- volume: std::time::SystemTime::now()
|
|
|
- .duration_since(UNIX_EPOCH)
|
|
|
- .unwrap()
|
|
|
- .as_nanos() as usize,
|
|
|
- message: s.message,
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-impl From<Fetch> for Request {
|
|
|
- fn from(f: Fetch) -> Self {
|
|
|
+impl Max for Request {
|
|
|
+ fn maximum() -> Self {
|
|
|
Request {
|
|
|
- receiver: f.receiver,
|
|
|
- req_type: FETCH,
|
|
|
+ uid: i32::MAX,
|
|
|
+ req_type: DUMMY,
|
|
|
mark: 0,
|
|
|
- volume: f.volume,
|
|
|
+ volume: 0,
|
|
|
message: 0,
|
|
|
+ _dum: [0; 13],
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// impl From<Send> for Request {
|
|
|
+// fn from(s: Send) -> Self {
|
|
|
+// Request {
|
|
|
+// receiver: s.receiver,
|
|
|
+// req_type: SEND,
|
|
|
+// mark: 0,
|
|
|
+// volume: std::time::SystemTime::now()
|
|
|
+// .duration_since(UNIX_EPOCH)
|
|
|
+// .unwrap()
|
|
|
+// .as_nanos() as usize,
|
|
|
+// message: s.message,
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+// impl From<Fetch> for Request {
|
|
|
+// fn from(f: Fetch) -> Self {
|
|
|
+// Request {
|
|
|
+// receiver: f.receiver,
|
|
|
+// req_type: FETCH,
|
|
|
+// mark: 0,
|
|
|
+// volume: f.volume,
|
|
|
+// message: 0,
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
impl PartialEq for Request {
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
- self.receiver == other.receiver && self.req_type == other.req_type
|
|
|
+ self.uid == other.uid && self.req_type == other.req_type && self.volume == other.volume
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// TODO this is not oblivious, just add the comparators back into otils later.
|
|
|
impl PartialOrd for Request {
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
|
- let receiver_ord = self.receiver.partial_cmp(&other.receiver);
|
|
|
+ let receiver_ord = self.uid.partial_cmp(&other.uid);
|
|
|
let type_ord = self.req_type.partial_cmp(&other.req_type);
|
|
|
let vol_ord = self.volume.partial_cmp(&other.volume);
|
|
|
match receiver_ord {
|
|
@@ -100,34 +135,14 @@ impl PartialOrd for Request {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-impl ObliviousOps for Request {
|
|
|
- fn oselect(cond: bool, a: Self, b: Self) -> Self {
|
|
|
- Request {
|
|
|
- receiver: i64::oselect(cond, a.receiver, b.receiver),
|
|
|
- req_type: u32::oselect(cond, a.req_type, b.req_type),
|
|
|
- mark: u32::oselect(cond, a.mark, b.mark),
|
|
|
- volume: usize::oselect(cond, a.volume, b.volume),
|
|
|
- message: u64::oselect(cond, a.message, b.message),
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- fn oswap(cond: bool, a: &mut Self, b: &mut Self) {
|
|
|
- i64::oswap(cond, &mut a.receiver, &mut b.receiver);
|
|
|
- u32::oswap(cond, &mut a.req_type, &mut b.req_type);
|
|
|
- u32::oswap(cond, &mut a.mark, &mut b.mark);
|
|
|
- usize::oswap(cond, &mut a.volume, &mut b.volume);
|
|
|
- u64::oswap(cond, &mut a.message, &mut b.message);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use super::*;
|
|
|
|
|
|
#[test]
|
|
|
fn test_eq() {
|
|
|
- let s_less: Request = Send::new(0, 0).into();
|
|
|
- let f_less: Request = Fetch::new(0, 0).into();
|
|
|
+ let s_less: Request = Request::new_send(0, 0);
|
|
|
+ let f_less: Request = Request::new_fetch(0, 0);
|
|
|
|
|
|
assert!(s_less == s_less);
|
|
|
assert!(f_less != s_less);
|
|
@@ -136,10 +151,10 @@ mod tests {
|
|
|
|
|
|
#[test]
|
|
|
fn test_ord() {
|
|
|
- let s_less: Request = Send::new(0, 0).into();
|
|
|
- let s_great: Request = Send::new(1, 0).into();
|
|
|
- let f_less: Request = Fetch::new(0, 0).into();
|
|
|
- let f_great: Request = Fetch::new(1, 0).into();
|
|
|
+ let s_less: Request = Request::new_send(0, 0);
|
|
|
+ let s_great: Request = Request::new_send(1, 0);
|
|
|
+ let f_less: Request = Request::new_fetch(0, 0);
|
|
|
+ let f_great: Request = Request::new_fetch(1, 0);
|
|
|
|
|
|
assert!(s_less < s_great);
|
|
|
assert!(s_great > s_less);
|