diff options
-rw-r--r-- | Cargo.lock | 18 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/interface/peer_server.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/timer.rs | 44 | ||||
-rwxr-xr-x | tests/netns.sh | 2 |
6 files changed, 29 insertions, 40 deletions
@@ -987,11 +987,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "slab" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "slab" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1313,15 +1308,6 @@ dependencies = [ [[package]] name = "tokio-timer" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tokio-timer" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ @@ -1502,10 +1488,10 @@ dependencies = [ "structopt 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "structopt-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "subtle 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-utun 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "treebitmap 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1649,7 +1635,6 @@ dependencies = [ "checksum serde_json 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7bf1cbb1387028a13739cb018ee0d9b3db534f22ca3c84a5904f7eadfde14e75" "checksum simplelog 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce595117de34b75e057b41e99079e43e9fcc4e5ec9c7ba5f2fea55321f0c624e" "checksum slab 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d807fd58c4181bbabed77cb3b891ba9748241a552bcc5be698faaebefc54f46e" -"checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" "checksum slab 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fdeff4cd9ecff59ec7e3744cbca73dfe5ac35c2aedb2cfba8a1c715a18912e9d" "checksum snow 0.1.8-preview (git+https://github.com/mcginty/snow?branch=wireguard)" = "<none>" "checksum socket2 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ff606e0486e88f5fc6cfeb3966e434fb409abbc7a3ab495238f70a1ca97f789d" @@ -1682,7 +1667,6 @@ dependencies = [ "checksum tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e8f46863230f9a05cf52d173721ec391b9c5782a2465f593029922b8782b9ffe" "checksum tokio-tcp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec9b094851aadd2caf83ba3ad8e8c4ce65a42104f7b94d9e6550023f0407853f" "checksum tokio-threadpool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3d05cdd6a78005e535d2b27c21521bdf91fbb321027a62d8e178929d18966d" -"checksum tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6131e780037787ff1b3f8aad9da83bca02438b72277850dd6ad0d455e0e20efc" "checksum tokio-timer 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "29a89e4ad0c8f1e4c9860e605c38c69bfdad3cccd4ea446e58ff588c1c07a397" "checksum tokio-udp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "137bda266504893ac4774e0ec4c2108f7ccdbcb7ac8dced6305fe9e4e0b5041a" "checksum tokio-uds 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "65ae5d255ce739e8537221ed2942e0445f4b3b813daebac1c0050ddaaa3587f9" @@ -49,11 +49,11 @@ pnet_packet = "^0.21" snow = { git = "https://github.com/mcginty/snow", features = ["ring-accelerated"], branch = "wireguard" } socket2 = "^0.3" subtle = "^0.5" +tokio = "^0.1.5" tokio-io = "^0.1" tokio-core = "^0.1" tokio-uds = "^0.1" tokio-utun = "^0.1.10" -tokio-timer = "^0.1" tokio-signal = "^0.1" treebitmap = "^0.2" x25519-dalek = "^0.1" diff --git a/src/interface/peer_server.rs b/src/interface/peer_server.rs index 954b3a0..1e082b0 100644 --- a/src/interface/peer_server.rs +++ b/src/interface/peer_server.rs @@ -398,7 +398,6 @@ impl PeerServer { } Ok(()) } - } impl Future for PeerServer { @@ -30,10 +30,10 @@ extern crate snow; extern crate socket2; extern crate subtle; extern crate test; +extern crate tokio; extern crate tokio_io; extern crate tokio_uds; extern crate tokio_utun; -extern crate tokio_timer; extern crate tokio_signal; extern crate treebitmap; extern crate x25519_dalek; diff --git a/src/timer.rs b/src/timer.rs index bbf80f3..ca00e29 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -1,8 +1,8 @@ use consts::TIMER_RESOLUTION; -use futures::{Future, Stream, Sink, Poll, unsync}; -use std::time::Duration; +use futures::{Async, Future, Stream, Sink, Poll, unsync}; +use std::time::{Instant, Duration}; +use tokio::timer::Delay; use tokio_core::reactor::Handle; -use tokio_timer; use interface::SharedPeer; #[derive(Debug)] @@ -13,9 +13,18 @@ pub enum TimerMessage { Wipe(SharedPeer), } +pub struct TimerHandle { + tx: unsync::oneshot::Sender<()> +} + +impl TimerHandle { + pub fn cancel(self) -> Result<(), ()> { + self.tx.send(()) + } +} + pub struct Timer { handle: Handle, - timer: tokio_timer::Timer, tx: unsync::mpsc::Sender<TimerMessage>, rx: unsync::mpsc::Receiver<TimerMessage>, } @@ -23,25 +32,24 @@ pub struct Timer { impl Timer { pub fn new(handle: Handle) -> Self { let (tx, rx) = unsync::mpsc::channel::<TimerMessage>(1024); - let timer = tokio_timer::wheel() - .tick_duration(*TIMER_RESOLUTION) - .num_slots(1 << 14) - .build(); - Self { handle, timer, tx, rx } + Self { handle, tx, rx } } - pub fn send_after(&mut self, delay: Duration, message: TimerMessage) { + pub fn send_after(&mut self, delay: Duration, message: TimerMessage) -> TimerHandle { trace!("queuing timer message {:?}", &message); - let timer = self.timer.sleep(delay + (*TIMER_RESOLUTION * 2)); - let future = timer.and_then({ - let tx = self.tx.clone(); - move |_| { - tx.clone().send(message).then(|_| Ok(())) - } - }).then(|_| Ok(())); + let (cancel_tx, mut cancel_rx) = unsync::oneshot::channel(); + let tx = self.tx.clone(); + let future = Delay::new(Instant::now() + delay + (*TIMER_RESOLUTION * 2)) + .map_err(|e| panic!("timer failed; err={:?}", e)) + .and_then(move |_| { + if let Ok(Async::Ready(())) = cancel_rx.poll() { + trace!("timer cancel signal sent, won't send message."); + } + tx.send(message).then(|_| Ok(())) + }); self.handle.spawn(future); + TimerHandle { tx: cancel_tx } } - } impl Stream for Timer { diff --git a/tests/netns.sh b/tests/netns.sh index 4196255..85a3c51 100755 --- a/tests/netns.sh +++ b/tests/netns.sh @@ -95,12 +95,10 @@ pp ip netns add $netns1 pp ip netns add $netns2 ip0 link set up dev lo -# ip0 link add dev wg1 type wireguard n0 $program wg1 sleep 0.5 ip0 link set wg1 netns $netns1 -# ip0 link add dev wg1 type wireguard n0 $program wg2 sleep 0.5 ip0 link set wg2 netns $netns2 |