Skip to content

Commit 0b78e68

Browse files
feat: more fine-granular timer update (#94)
At present, it is up to the host app how often it calls `update_timers_at`. Once a second should be enough but ideally, a `Tunn` just exposes when the next internal timer fires. This is being tackled more generally in #61. In order to ensure we send keep-alive messages in time, we incorporate `want_passive_keepalive_at` into the `next_timer_update` into it.
1 parent a541c0e commit 0b78e68

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

boringtun/src/noise/timers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use super::errors::WireGuardError;
55
use crate::noise::{Tunn, TunnResult, N_SESSIONS};
6+
use std::iter;
67
use std::ops::{Index, IndexMut};
78

89
use rand::Rng;
@@ -376,7 +377,10 @@ impl Tunn {
376377
///
377378
/// If this returns `None`, you may call it at your usual desired precision (usually once a second is enough).
378379
pub fn next_timer_update(&self) -> Option<Instant> {
379-
self.timers.send_handshake_at
380+
iter::empty()
381+
.chain(self.timers.send_handshake_at)
382+
.chain(self.timers.want_passive_keepalive_at)
383+
.min()
380384
}
381385

382386
#[deprecated(note = "Prefer `Tunn::time_since_last_handshake_at` to avoid time-impurity")]

0 commit comments

Comments
 (0)