cloudflare / boringtun

Userspace WireGuard® Implementation in Rust
BSD 3-Clause "New" or "Revised" License
5.92k stars 397 forks source link

Be sure to count for system sleep in timers #317

Closed schultetwin1 closed 1 year ago

schultetwin1 commented 1 year ago

Currently the timers in boringtun use std::time::Instant. This timer does not increment while the machine is asleep on macOS and Linux meaning the device does not know to properly handshake on wake from sleep.

To solve this we use CLOCK_BOOTTIME on Linux/Android and CLOCK_MONOTONIC on macOS/iOS to get the actual duration since the last handshake.

Fixes #316

jeff-hiner commented 1 year ago

This is long overdue, thanks!.

@schultetwin1 I think sleepyinstant is something that belongs as a separate public crate, and would absolutely be useful to more than just us.

Noah-Kennedy commented 1 year ago

@schultetwin1 sleepyinstant will need to go on crates.io for us to get this through. We can't do crates.io releases with path dependencies.

Could you split this off into two PRs, one of which adds sleepyinstant, and the other of which will move us over to sleepyinstant? After the first is merged I can publish sleepyinstant, allowing us to do releases which depend on that crate.