From 6ba40f17cb484c0b9b76caf926ef24539892d5a6 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Mon, 4 Nov 2019 13:19:27 +0100 Subject: Work on Up/Down operation on WireGuard device --- src/configuration/config.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/configuration/config.rs') diff --git a/src/configuration/config.rs b/src/configuration/config.rs index e3eb0af..ed78e43 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -1,7 +1,7 @@ use spin::Mutex; use std::net::{IpAddr, SocketAddr}; use std::sync::atomic::Ordering; -use std::time::SystemTime; +use std::time::{Duration, SystemTime}; use x25519_dalek::{PublicKey, StaticSecret}; use super::*; @@ -125,11 +125,8 @@ pub trait Configuration { /// /// - `peer': The public key of the peer /// - `psk` - fn set_persistent_keepalive_interval( - &self, - peer: &PublicKey, - interval: usize, - ) -> Option; + fn set_persistent_keepalive_interval(&self, peer: &PublicKey, secs: u64) + -> Option; /// Remove all allowed IPs from the peer /// @@ -254,11 +251,11 @@ impl Configuration for WireguardConfig { fn set_persistent_keepalive_interval( &self, peer: &PublicKey, - interval: usize, + secs: u64, ) -> Option { match self.wireguard.lookup_peer(peer) { Some(peer) => { - peer.set_persistent_keepalive_interval(interval); + peer.set_persistent_keepalive_interval(secs); None } None => Some(ConfigError::NoSuchPeer), @@ -292,7 +289,7 @@ impl Configuration for WireguardConfig { // convert the system time to (secs, nano) since epoch let last_handshake = (*p.walltime_last_handshake.lock()) .duration_since(SystemTime::UNIX_EPOCH) - .expect("There should be no earlier time"); + .unwrap_or(Duration::from_secs(0)); // any time before epoch is mapped to epoch // extract state into PeerState state.push(PeerState { -- cgit v1.2.3-59-g8ed1b