From dee23969f5b1cfce7b352d6782a86cac062ec12e Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Thu, 21 Nov 2019 17:12:00 +0100 Subject: Daemonization --- src/configuration/config.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/configuration/config.rs') diff --git a/src/configuration/config.rs b/src/configuration/config.rs index f11d90d..2a149ee 100644 --- a/src/configuration/config.rs +++ b/src/configuration/config.rs @@ -18,8 +18,7 @@ use bind::Owner; pub struct PeerState { pub rx_bytes: u64, pub tx_bytes: u64, - pub last_handshake_time_sec: u64, - pub last_handshake_time_nsec: u64, + pub last_handshake_time: Option<(u64, u64)>, pub public_key: PublicKey, pub allowed_ips: Vec<(IpAddr, u32)>, pub endpoint: Option, @@ -289,9 +288,12 @@ impl Configuration for WireguardConfig for p in peers { // convert the system time to (secs, nano) since epoch - let last_handshake = (*p.walltime_last_handshake.lock()) - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap_or(Duration::from_secs(0)); // any time before epoch is mapped to epoch + let last_handshake_time = (*p.walltime_last_handshake.lock()).and_then(|t| { + let duration = t + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap_or(Duration::from_secs(0)); + Some((duration.as_secs(), duration.subsec_nanos() as u64)) + }); if let Some(psk) = self.wireguard.get_psk(&p.pk) { // extract state into PeerState @@ -302,8 +304,7 @@ impl Configuration for WireguardConfig tx_bytes: p.tx_bytes.load(Ordering::Relaxed), persistent_keepalive_interval: p.get_keepalive_interval(), allowed_ips: p.router.list_allowed_ips(), - last_handshake_time_nsec: last_handshake.subsec_nanos() as u64, - last_handshake_time_sec: last_handshake.as_secs(), + last_handshake_time, public_key: p.pk, }) } -- cgit v1.2.3-59-g8ed1b