aboutsummaryrefslogtreecommitdiffstats
path: root/src/wireguard/router/worker.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/wireguard/router/worker.rs')
-rw-r--r--src/wireguard/router/worker.rs30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/wireguard/router/worker.rs b/src/wireguard/router/worker.rs
index d95050e..bbb644c 100644
--- a/src/wireguard/router/worker.rs
+++ b/src/wireguard/router/worker.rs
@@ -1,13 +1,31 @@
-use super::Device;
-
use super::super::{tun, udp, Endpoint};
use super::types::Callbacks;
-use super::receive::ReceieveJob;
+use super::queue::ParallelJob;
+use super::receive::ReceiveJob;
use super::send::SendJob;
-fn worker<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>>(
- device: Device<E, C, T, B>,
+use crossbeam_channel::Receiver;
+
+pub enum JobUnion<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> {
+ Outbound(SendJob<E, C, T, B>),
+ Inbound(ReceiveJob<E, C, T, B>),
+}
+
+pub fn worker<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>>(
+ receiver: Receiver<JobUnion<E, C, T, B>>,
) {
- // fetch job
+ loop {
+ match receiver.recv() {
+ Err(_) => break,
+ Ok(JobUnion::Inbound(job)) => {
+ job.parallel_work();
+ job.queue().consume();
+ }
+ Ok(JobUnion::Outbound(job)) => {
+ job.parallel_work();
+ job.queue().consume();
+ }
+ }
+ }
}