From bb0a8acea3161a08ac69cc2e35489f8d33741d1a Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Thu, 26 Dec 2019 22:55:33 +0100 Subject: Make under_load global for WireGuard device --- src/wireguard/wireguard.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/wireguard/wireguard.rs') diff --git a/src/wireguard/wireguard.rs b/src/wireguard/wireguard.rs index 2fa14fc..bf550ef 100644 --- a/src/wireguard/wireguard.rs +++ b/src/wireguard/wireguard.rs @@ -58,33 +58,33 @@ pub struct WireguardInner { // handshake related state pub handshake: RwLock, - pub last_under_load: AtomicUsize, - pub pending: AtomicUsize, // num of pending handshake packets in queue + pub last_under_load: Mutex, + pub pending: AtomicUsize, // number of pending handshake packets in queue pub queue: ParallelQueue>, } -pub struct Wireguard { +pub struct WireGuard { inner: Arc>, } pub struct WaitCounter(StdMutex, Condvar); -impl fmt::Display for Wireguard { +impl fmt::Display for WireGuard { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "wireguard({:x})", self.id) } } -impl Deref for Wireguard { +impl Deref for WireGuard { type Target = WireguardInner; fn deref(&self) -> &Self::Target { &self.inner } } -impl Clone for Wireguard { +impl Clone for WireGuard { fn clone(&self) -> Self { - Wireguard { + WireGuard { inner: self.inner.clone(), } } @@ -116,7 +116,7 @@ impl WaitCounter { } } -impl Wireguard { +impl WireGuard { /// Brings the WireGuard device down. /// Usually called when the associated interface is brought down. /// @@ -307,7 +307,7 @@ impl Wireguard { self.tun_readers.wait(); } - pub fn new(writer: T::Writer) -> Wireguard { + pub fn new(writer: T::Writer) -> WireGuard { // workers equal to number of physical cores let cpus = num_cpus::get(); @@ -318,14 +318,14 @@ impl Wireguard { let (tx, mut rxs) = ParallelQueue::new(cpus, 128); // create arc to state - let wg = Wireguard { + let wg = WireGuard { inner: Arc::new(WireguardInner { enabled: RwLock::new(false), tun_readers: WaitCounter::new(), id: rng.gen(), mtu: AtomicUsize::new(0), peers: RwLock::new(HashMap::new()), - last_under_load: AtomicUsize::new(0), // TODO + last_under_load: Mutex::new(Instant::now() - TIME_HORIZON), send: RwLock::new(None), router: router::Device::new(num_cpus::get(), writer), // router owns the writing half pending: AtomicUsize::new(0), -- cgit v1.2.3-59-g8ed1b