From 293914e47b046f862608a1af91864b6b38336aa5 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Wed, 6 Nov 2019 13:50:38 +0100 Subject: Implement disable/enable timers --- src/wireguard/peer.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/wireguard/peer.rs') diff --git a/src/wireguard/peer.rs b/src/wireguard/peer.rs index 9f24dea..b77e8c6 100644 --- a/src/wireguard/peer.rs +++ b/src/wireguard/peer.rs @@ -4,12 +4,11 @@ use super::timers::{Events, Timers}; use super::HandshakeJob; use super::bind::Bind; -use super::bind::Reader as BindReader; -use super::tun::{Reader, Tun}; +use super::tun::Tun; use std::fmt; use std::ops::Deref; -use std::sync::atomic::{AtomicBool, AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; use std::sync::Arc; use std::time::{Instant, SystemTime}; @@ -34,8 +33,7 @@ pub struct PeerInner { pub queue: Mutex>>, // handshake queue // stats and configuration - pub pk: PublicKey, // public key, DISCUSS: avoid this. TODO: remove - pub keepalive_interval: AtomicU64, // keepalive interval + pub pk: PublicKey, // public key, DISCUSS: avoid this. TODO: remove pub rx_bytes: AtomicU64, // received bytes pub tx_bytes: AtomicU64, // transmitted bytes @@ -78,11 +76,20 @@ impl Deref for Peer { } impl Peer { + /// Bring the peer down. Causing: + /// + /// - Timers to be stopped and disabled. + /// - All keystate to be zeroed pub fn down(&self) { self.stop_timers(); + self.router.down(); } - pub fn up(&self) {} + /// Bring the peer up. + pub fn up(&self) { + self.router.up(); + self.start_timers(); + } } impl PeerInner { -- cgit v1.2.3-59-g8ed1b