hn.today

Sanstun: A sans-IO, parallel-friendly WireGuard implementation in Rust

firezone.dev160 points45 comments
Screenshot of Sanstun: A sans-IO, parallel-friendly WireGuard implementation in Rust

Sanstun is Firezone’s Rust implementation of the WireGuard state machine, designed around sans-IO principles: protocol logic is separated from networking, time, and randomness so it can be tested and composed more easily. Firezone developed it after more than two years of patching boringtun to meet product needs, including deterministic time handling, configurable behavior, and fixes for edge cases. Sanstun also avoids buffering packets internally; applications decide what to queue when no session exists. Its API separates interfaces, which receive and validate datagrams, from tunnels, which handle messages for individual peers. This structure makes essential safeguards harder to bypass: inbound traffic passes through interface-level parsing, cookie checks, and rate limiting before reaching a tunnel.

The design also lets applications parallelize encryption and decryption within a single tunnel. WireGuard’s packet counters and session state require coordinated bookkeeping, but the expensive cryptographic work can run independently. Sanstun reserves counters and updates state in a brief setup step, then returns a transferable pending operation for a worker thread to encrypt or decrypt. Benchmarks report that for 1,280-byte packets, the bookkeeping for outbound encryption takes about 21 nanoseconds, compared with roughly 933 nanoseconds for encryption; inbound decryption takes about 915 nanoseconds, with similarly small setup and commit costs. This split suggests substantial throughput gains from worker-thread offloading, though real-world speedups will be lower because of thread-transfer and scheduling overhead.

Read on firezone.dev45 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.