summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-31 20:25:16 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-31 20:25:16 +0200
commit46d76b80c6b1b3b1c549b770b1a5ba791b49da8a (patch)
tree0c880785943dd00e66cff6d8cd7560d42dc68c24 /src/main.rs
parentExplicitly clear t0 in KDF macro (diff)
downloadwireguard-rs-46d76b80c6b1b3b1c549b770b1a5ba791b49da8a.tar.xz
wireguard-rs-46d76b80c6b1b3b1c549b770b1a5ba791b49da8a.zip
Reduce number of type parameters in router
Merge multiple related type parameters into trait, allowing for easier refactoring and better maintainability.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 600e144..cfe93eb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,7 +13,44 @@ use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
-use types::{Bind, KeyPair};
+use types::{Bind, KeyPair, Tun};
+
+#[derive(Debug)]
+enum TunError {}
+
+impl Error for TunError {
+ fn description(&self) -> &str {
+ "Generic Tun Error"
+ }
+
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ None
+ }
+}
+
+impl fmt::Display for TunError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "Not Possible")
+ }
+}
+
+struct TunTest {}
+
+impl Tun for TunTest {
+ type Error = TunError;
+
+ fn mtu(&self) -> usize {
+ 1500
+ }
+
+ fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Self::Error> {
+ Ok(0)
+ }
+
+ fn write(&self, src: &[u8]) -> Result<(), Self::Error> {
+ Ok(())
+ }
+}
struct Test {}
@@ -73,6 +110,7 @@ fn main() {
{
let router = router::Device::new(
4,
+ TunTest {},
|t: &PeerTimer, data: bool, sent: bool| t.a.reset(Duration::from_millis(1000)),
|t: &PeerTimer, data: bool, sent: bool| t.b.reset(Duration::from_millis(1000)),
|t: &PeerTimer| println!("new key requested"),