Skip to content

Commit 3f4bfd7

Browse files
committed
perf(connlib): drive wireguard timers on demand
boringtun's `next_timer_update` now reports the exact instant of the next required timer action, so the tunnel no longer needs polling on a fixed one-second interval. Bump boringtun to pick that up and query it directly when computing the next timeout. Related: firezone/boringtun#213 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XsRkNsA4r812CDfwPH8ehF
1 parent 0331104 commit 3f4bfd7

3 files changed

Lines changed: 6 additions & 22 deletions

File tree

rust/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/libs/connlib/snownet/src/node.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ where
850850
agent,
851851
index,
852852
tunnel,
853-
next_wg_timer_update: now,
854853
stats: Default::default(),
855854
buffer: vec![0; ip_packet::MAX_FZ_PAYLOAD],
856855
intent_sent_at,
@@ -1337,8 +1336,6 @@ struct Connection<RId> {
13371336
#[debug(skip)]
13381337
tunnel: Tunn,
13391338
remote_pub_key: PublicKey,
1340-
/// When to next update the [`Tunn`]'s timers.
1341-
next_wg_timer_update: Instant,
13421339

13431340
last_proactive_handshake_sent_at: Option<Instant>,
13441341

@@ -1386,7 +1383,7 @@ where
13861383
.poll_timeout()
13871384
.map(|instant| (instant, "ICE agent")),
13881385
)
1389-
.chain(Some((self.next_wg_timer_update, "boringtun tunnel")))
1386+
.chain(self.tunnel.next_timer_update())
13901387
.chain(
13911388
self.candidate_timeout
13921389
.map(|instant| (instant, "candidate timeout")),
@@ -1447,18 +1444,6 @@ where
14471444

14481445
self.handle_tunnel_timeout(now, allocations, transmits);
14491446

1450-
// If this was a scheduled update, hop to the next interval.
1451-
if now >= self.next_wg_timer_update {
1452-
self.next_wg_timer_update = now + Duration::from_secs(1); // TODO: Remove fixed interval in favor of precise `next_timer_update` function in `boringtun`.
1453-
}
1454-
1455-
// If `boringtun` wants to be called earlier than the scheduled interval, move it forward.
1456-
if let Some(next_update) = self.tunnel.next_timer_update()
1457-
&& next_update < self.next_wg_timer_update
1458-
{
1459-
self.next_wg_timer_update = next_update;
1460-
}
1461-
14621447
while let Some(event) = self.agent.poll_ice_event() {
14631448
match event {
14641449
IceAgentEvent::DiscoveredRecv { .. } => {}

rust/libs/connlib/snownet/src/node/connections.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ mod tests {
669669
Duration::ZERO,
670670
),
671671
remote_pub_key: PublicKey::from(rand::random::<[u8; 32]>()),
672-
next_wg_timer_update: Instant::now(),
673672
last_proactive_handshake_sent_at: None,
674673
relay: SelectedRelay { id: relay_id },
675674
state: crate::node::ConnectionState::Connecting {

0 commit comments

Comments
 (0)