Sanstun: A Parallel-Friendly WireGuard in Rust
Original source
Sanstun: A sans-IO, parallel-friendly WireGuard implementation in Rust
Hacker News →Firezone released sanstun, a Rust implementation of WireGuard built on sans-IO principles—cleanly separating protocol state from IO operations including networking, timing, and randomness. The project emerged from frustrations with boringtun, an existing WireGuard implementation the team had been forking and patching for years. Over time, more than 70 patches accumulated to address API incompatibility, inadequate time handling, and problematic internal buffering.
Sanstun solves these problems by eliminating implicit buffering. When a session doesn’t exist, the library no longer auto-buffers outgoing packets; applications handle buffering explicitly instead. This removes unnecessary allocations, allows tunable buffer sizing, and makes the API more intuitive. The sans-IO design also improves testability and naturally aligns with Rust’s ownership model, avoiding the hidden complexity of side-effect-laden code.
The implementation maps WireGuard’s protocol directly onto Rust types to catch bugs at compile time. An Interface type serves as the single entry point for inbound packets, applying rate limiting to defend against expensive Diffie-Hellman handshake attacks. Tunnel types represent peer connections and are routed via public key or tunnel identifier. Since WireGuard doesn’t share state between tunnels, this architecture readily supports parallel processing across multiple peers and within individual tunnels.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.