Technology1 min read

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

By · Published by Everything Blog

In short

Firezone created the project to address evolving product needs after finding it unsustainable to maintain API compatibility with upstream boringtun. The architecture separates core state operations from time, randomness, and file or network interactions to facilitate reliable system simulations. Unlike its predecessor, the library eliminates internal buffering mechanisms to prevent unexpected memory allocations. Instead, developers receive explicit API components for managing timers, events, and packet flows, leaving session packet buffering to the application layer.

Key points

  • Applications using the new library must handle packet buffering directly whenever an acti…: Applications using the new library must handle packet buffering directly whenever an active session does not exist.
  • Handshakes can now be triggered explicitly through the programming interface at any point…: Handshakes can now be triggered explicitly through the programming interface at any point during operation.
  • Adopting a sans-IO model allows engineers to execute system simulations much more effecti…: Adopting a sans-IO model allows engineers to execute system simulations much more effectively than before.

Sources checked by our analysis pipeline: 1

Introducing sanstun: A sans-IO, parallel-friendly, userspace WireGuard implementation in Rust

Today, we are announcing sanstun

: a sans-IO Rust implementation of the WireGuard® state machine, optimized for ease of use, security and performance through a parallel-friendly and idiomatic API.

What is sans-IO?

sans-IO is the idea that you design your system such that IO and side-effects are cleanly separated from the state and "business logic". The IO in sans-IO doesn't just mean file or network IO. It also includes things like time and randomness!

Due to their lack of side-effects, sans-IO components compose very well and are relatively easy to test. The design also avoids problems like function coloring and plays well with Rust's ownership rules.

The code examples and references in this post are in Rust but sans-IO isn't Rust-specific at all. Its patterns and ideas can be applied in any language. For a more in-depth explanation, our sans-IO post is a good place to start.

History

When we first built Firezone, we reached for boringtun

as our WireGuard implementation.

boringtun

more or less did what we wanted, but…

Technology