aboutsummaryrefslogtreecommitdiffstats
path: root/src/configuration
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-21 17:12:00 +0100
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-11-21 17:12:00 +0100
commitdee23969f5b1cfce7b352d6782a86cac062ec12e (patch)
tree15360be6307d32515f9d1be1efcba3dc470c42d9 /src/configuration
parentClean dependencies and imports (diff)
downloadwireguard-rs-dee23969f5b1cfce7b352d6782a86cac062ec12e.tar.xz
wireguard-rs-dee23969f5b1cfce7b352d6782a86cac062ec12e.zip
Daemonization
Diffstat (limited to 'src/configuration')
-rw-r--r--src/configuration/config.rs15
-rw-r--r--src/configuration/uapi/get.rs17
2 files changed, 16 insertions, 16 deletions
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<SocketAddr>,
@@ -289,9 +288,12 @@ impl<T: tun::Tun, B: bind::PlatformBind> Configuration for WireguardConfig<T, B>
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<T: tun::Tun, B: bind::PlatformBind> Configuration for WireguardConfig<T, B>
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,
})
}
diff --git a/src/configuration/uapi/get.rs b/src/configuration/uapi/get.rs
index f0746b3..9e6ab36 100644
--- a/src/configuration/uapi/get.rs
+++ b/src/configuration/uapi/get.rs
@@ -32,24 +32,23 @@ pub fn serialize<C: Configuration, W: io::Write>(writer: &mut W, config: &C) ->
let mut peers = config.get_peers();
while let Some(p) = peers.pop() {
write("public_key", hex::encode(p.public_key.as_bytes()))?;
+ write("preshared_key", hex::encode(p.preshared_key))?;
write("rx_bytes", p.rx_bytes.to_string())?;
write("tx_bytes", p.tx_bytes.to_string())?;
write(
- "last_handshake_time_sec",
- p.last_handshake_time_nsec.to_string(),
- )?;
- write(
- "last_handshake_time_nsec",
- p.last_handshake_time_nsec.to_string(),
- )?;
- write(
"persistent_keepalive_interval",
p.persistent_keepalive_interval.to_string(),
)?;
+
+ if let Some((secs, nsecs)) = p.last_handshake_time {
+ write("last_handshake_time_sec", secs.to_string())?;
+ write("last_handshake_time_nsec", nsecs.to_string())?;
+ }
+
if let Some(endpoint) = p.endpoint {
write("endpoint", endpoint.into_address().to_string())?;
}
- write("preshared_key", hex::encode(p.preshared_key))?;
+
for (ip, cidr) in p.allowed_ips {
write("allowed_ip", ip.to_string() + "/" + &cidr.to_string())?;
}