aboutsummaryrefslogtreecommitdiffstats
path: root/src/platform
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2020-03-29 18:21:48 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2020-03-29 18:21:48 +0200
commit12a7b371d4fed75f3934cf7d3788a6cf51c33c22 (patch)
tree970fc1287d6cbdbd419ef9151e6e94a077b5a7fd /src/platform
parentMerge branch 'tests' (diff)
downloadwireguard-rs-12a7b371d4fed75f3934cf7d3788a6cf51c33c22.tar.xz
wireguard-rs-12a7b371d4fed75f3934cf7d3788a6cf51c33c22.zip
Restructuring and dependency version bump.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/dummy/tun/dummy.rs (renamed from src/platform/dummy/tun.rs)27
-rw-r--r--src/platform/dummy/tun/mod.rs12
-rw-r--r--src/platform/dummy/tun/void.rs43
3 files changed, 72 insertions, 10 deletions
diff --git a/src/platform/dummy/tun.rs b/src/platform/dummy/tun/dummy.rs
index 1955884..0f3479a 100644
--- a/src/platform/dummy/tun.rs
+++ b/src/platform/dummy/tun/dummy.rs
@@ -1,7 +1,13 @@
-use hex;
-use log::debug;
-use rand::rngs::OsRng;
-use rand::Rng;
+// This provides a mock tunnel interface.
+// Which enables unit tests where WireGuard interfaces
+// are configured to match each other and a full test of:
+//
+// - Handshake
+// - Transport encryption/decryption
+//
+// Can be executed.
+
+use super::*;
use std::cmp::min;
use std::error::Error;
@@ -11,15 +17,16 @@ use std::sync::Mutex;
use std::thread;
use std::time::Duration;
-use super::super::tun::*;
-
-#[derive(Debug)]
-pub enum TunError {
- Disconnected,
-}
+use hex;
+use log::debug;
+use rand::rngs::OsRng;
+use rand::Rng;
pub struct TunTest {}
+// Represents the "other end" (kernel/OS end) of the TUN connection:
+//
+// Used to send/receive packets to the mock WireGuard interface.
pub struct TunFakeIO {
id: u32,
store: bool,
diff --git a/src/platform/dummy/tun/mod.rs b/src/platform/dummy/tun/mod.rs
new file mode 100644
index 0000000..da03c7a
--- /dev/null
+++ b/src/platform/dummy/tun/mod.rs
@@ -0,0 +1,12 @@
+use super::super::tun::*;
+
+mod dummy;
+mod void;
+
+#[derive(Debug)]
+pub enum TunError {
+ Disconnected,
+}
+
+pub use dummy::*;
+pub use void::*;
diff --git a/src/platform/dummy/tun/void.rs b/src/platform/dummy/tun/void.rs
new file mode 100644
index 0000000..0777541
--- /dev/null
+++ b/src/platform/dummy/tun/void.rs
@@ -0,0 +1,43 @@
+/*
+// This code provides a "void" implementation of the tunnel interface:
+// The implementation never reads and immediately discards any write without error
+//
+// This is used during benchmarking and profiling of the inbound path.
+
+use super::*;
+
+pub struct VoidTun {}
+
+pub struct VoidReader {}
+
+pub struct VoidWriter {}
+
+impl Tun for VoidTun {
+ type Writer = VoidWriter;
+ type Reader = VoidReader;
+ type Error = TunError;
+}
+
+
+impl Reader for VodReader {
+ type Error = TunError;
+
+ fn write(&self, src: &[u8]) -> Result<(), Self::Error> {
+ debug!(
+ "dummy::TUN({}) : write ({}, {})",
+ self.id,
+ src.len(),
+ hex::encode(src)
+ );
+ if self.store {
+ let m = src.to_owned();
+ match self.tx.lock().unwrap().send(m) {
+ Ok(_) => Ok(()),
+ Err(_) => Err(TunError::Disconnected),
+ }
+ } else {
+ Ok(())
+ }
+ }
+}
+*/