From 6fd54c027e6b78192a02de3e77d00552ec36968d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 24 Jan 2024 11:23:24 -0800 Subject: [PATCH] Expose `time_since_last_received` --- boringtun/src/noise/timers.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/boringtun/src/noise/timers.rs b/boringtun/src/noise/timers.rs index 6b91d576..57e7effa 100644 --- a/boringtun/src/noise/timers.rs +++ b/boringtun/src/noise/timers.rs @@ -323,6 +323,19 @@ impl Tunn { } } + /// Time since we last received a packet. + pub fn time_since_last_received(&self) -> Option { + let current_session = self.current; + if self.sessions[current_session % super::N_SESSIONS].is_some() { + let duration_since_tun_start = Instant::now().duration_since(self.timers.time_started); + let duration_since_last_packet = self.timers[TimeLastPacketReceived]; + + Some(duration_since_tun_start - duration_since_last_packet) + } else { + None + } + } + pub fn persistent_keepalive(&self) -> Option { let keepalive = self.timers.persistent_keepalive;