summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-28 16:27:26 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-28 16:27:26 +0200
commit6785aa4cb56833131b69f4d2b44301908b1a1b4c (patch)
treed9dc6ec7a3c45291f44ae3e8d707200a1b1da410 /src/main.rs
parentRenamed confirmed -> initator on keypair (diff)
downloadwireguard-rs-6785aa4cb56833131b69f4d2b44301908b1a1b4c.tar.xz
wireguard-rs-6785aa4cb56833131b69f4d2b44301908b1a1b4c.zip
Join with worker threads on device drop
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs78
1 files changed, 65 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs
index 5c58b24..fc1a26a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -7,11 +7,60 @@ mod types;
use hjul::*;
+use std::error::Error;
+use std::fmt;
+use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use sodiumoxide;
-use types::KeyPair;
+use types::{Bind, KeyPair};
+
+struct Test {}
+
+impl Bind for Test {
+ type Error = BindError;
+ type Endpoint = SocketAddr;
+
+ fn new() -> Test {
+ Test {}
+ }
+
+ fn set_port(&self, port: u16) -> Result<(), Self::Error> {
+ Ok(())
+ }
+
+ fn get_port(&self) -> Option<u16> {
+ None
+ }
+
+ fn recv(&self, buf: &mut [u8]) -> Result<(usize, Self::Endpoint), Self::Error> {
+ Ok((0, "127.0.0.1:8080".parse().unwrap()))
+ }
+
+ fn send(&self, buf: &[u8], dst: &Self::Endpoint) -> Result<(), Self::Error> {
+ Ok(())
+ }
+}
+
+#[derive(Debug)]
+enum BindError {}
+
+impl Error for BindError {
+ fn description(&self) -> &str {
+ "Generic Bind Error"
+ }
+
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ None
+ }
+}
+
+impl fmt::Display for BindError {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "Not Possible")
+ }
+}
#[derive(Debug, Clone)]
struct PeerTimer {
@@ -24,20 +73,23 @@ fn main() {
// choose optimal crypto implementations for platform
sodiumoxide::init().unwrap();
+ {
+ let router = router::Device::new(
+ 4,
+ |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"),
+ );
- let router = router::Device::new(
- 4,
- |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"),
- );
+ let pt = PeerTimer {
+ a: runner.timer(|| println!("timer-a fired for peer")),
+ b: runner.timer(|| println!("timer-b fired for peer")),
+ };
- let pt = PeerTimer {
- a: runner.timer(|| println!("timer-a fired for peer")),
- b: runner.timer(|| println!("timer-b fired for peer")),
- };
+ let peer = router.new_peer(pt.clone());
- let peer = router.new_peer(pt.clone());
+ println!("{:?}", pt);
+ }
- println!("{:?}", pt);
+ println!("joined");
}