summaryrefslogtreecommitdiffstats
path: root/src/router/inbound.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/router/inbound.rs')
-rw-r--r--src/router/inbound.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/router/inbound.rs b/src/router/inbound.rs
new file mode 100644
index 0000000..eba63c4
--- /dev/null
+++ b/src/router/inbound.rs
@@ -0,0 +1,52 @@
+use std::thread;
+use spin;
+use lifeguard::Recycled;
+use super::anti_replay::AntiReplay;
+use std::sync::mpsc::{Receiver, sync_channel};
+use std::sync::Arc;
+
+struct ParallelJobInner {
+ done : bool,
+ msg : Vec<u8>,
+ key : [u8; 32]
+}
+
+type ParallelJob = spin::Mutex<ParallelJobInner>;
+
+struct InboundInorder {
+ job : Arc<ParallelJob>,
+ state : Arc<KeyState>,
+}
+
+struct Inorder<'a> (Arc<spin::Mutex<Option<Job<'a>>>>);
+
+struct Job<'a> {
+ msg : Recycled<'a, Vec<u8>>,
+ arp : Arc<KeyState>, // replay protector and key-pair
+ key : Option<(Arc<Peer>, Arc<KeyPair>)> // provided if the key has not been confirmed
+}
+
+fn worker_inorder<'a>(channel : Receiver<Inorder<'a>>) {
+ let mut current = 0;
+
+ // reads from inorder channel
+ for ordered in channel.recv().iter() {
+
+ loop {
+ // check if job is complete
+ match ordered.0.try_lock() {
+ None => (),
+ Some(guard) => if let Some(job) = *guard {
+ if job.arp.lock().update(6) {
+ // write to output
+
+ break;
+ }
+ }
+ }
+
+ // wait for job to complete
+ thread::park();
+ }
+ }
+} \ No newline at end of file