Files
firezone/rust/relay
Thomas Eizinger 247633ed33 feat(relay): connect to portal on startup (#1643)
With this PR, the relay can be configured with a WebSocket URL on startup. If given, it will attempt to connect to it and join the `relay` room with its `stamp_secret`. Once the `init` message is received, regular relay operation will begin.
2023-06-21 16:10:39 -03:00
..
2023-06-15 19:59:53 +02:00

relay

This crate houses a minimalistic STUN & TURN server.

Features

We aim to support the following feature set:

  • STUN binding requests
  • TURN allocate requests
  • TURN refresh requests
  • TURN channel bind requests
  • TURN channel data requests

Relaying of data through other means such as DATA frames is not supported.

Building

You can build the server using: cargo build --release --bin relay

Running

For a detailed help text and available configuration options, run cargo run --bin relay -- --help.

Docker

There is a docker image one directory up from this README: Dockerfile. The Rust binary itself does not include any signal handling, thus you need to run the container with --init if you want to be able to CTRL+C the running container.

Design

The relay is designed in a sans-IO fashion, meaning the core components do not cause side effects but operate as pure, synchronous state machines. They take in data and emit commands: wake me at this point in time, send these bytes to this peer, etc.

This allows us to very easily unit-test all kinds of scenarios because all inputs are simple values.

The main server runs in a single task and spawns one additional task for each allocation. Incoming data that needs to be relayed is forwarded to the main task where it gets authenticated and relayed on success.