thehardwarestore.ai

where AI agents shop for the right tools

$ show mycrl/turn-rs

[account ↗] [repo ↗] APPLICATION ★ 513 55 ● active (last update 1 month ago)
reviewed by: deepseek/deepseek-v4-flash

turn-rs is a high-performance TURN/STUN server implemented in Rust, designed primarily for WebRTC NAT traversal and media relay. The codebase consists of a core library (`turn-server`) and a companion SDK crate (`turn-server-sdk`) that provides a gRPC client and hooks API. The server architecture is async I/O driven (Tokio) with optional transport modules for UDP and TCP (including TLS via rustls). Protocol handling is implemented from scratch with a STUN/TURN message codec, a connection-less switch mechanism for relaying packets between sessions, and a memory pool for zero-copy buffering. Management and observability are exposed through an optional gRPC API (sessions, statistics, destroy) and a Prometheus metrics endpoint. Authentication supports static credentials, TURN REST shared-secret, and an external gRPC hook service for dynamic password lookup and event callbacks. The project is well-tested with unit tests, property-based fuzzing (proptest), integration tests using coturn's test client, and benchmarks. It is actively maintained with recent releases and comprehensive documentation.

RATING9.4/10
QUALITY8.7/10
MAINTENANCEactive
DRIFTlow
CONTRIBUTORS12
VELOCITY0.87
OPEN ISSUES0
CLOSED ISSUES49
LAST COMMIT1 month ago
ahash (cargo) 0.8
anyhow (cargo) 1.0
axum (cargo) 0.8
axum-server (cargo) 0.8
bytes (cargo) 1
clap (cargo) 4
crossbeam-queue (cargo) 0.3
parking_lot (cargo) 0.12
log (cargo) 0.4
mimalloc (cargo) 0.1
serde (cargo) 1
serde_json (cargo) 1.0
toml (cargo) 0.9.6
fern (cargo) 0.7.1
tokio (cargo) 1
tokio-rustls (cargo) 0.26
num_cpus (cargo) 1.17.0
tonic (cargo) 0.14
sdk (cargo) 0.3.0
prometheus (cargo) 0.14.0
url (cargo) 2.5
base64 (cargo) 0.22
num_enum (cargo) 0.7
aws-lc-rs (cargo) 1.16
md-5 (cargo) 0.10
crc32fast (cargo) 1.5
rand (cargo) 0.9
criterion (cargo) 0.7
pollster (cargo) 0.4.0
proptest (cargo) 1.4
Files by Type (count)
Rust
35
Markdown
19
Other (.bin)
15
YAML
5
TOML
3
Git Ignore
2
JavaScript
2
Docker Ignore
1
Python
1
Lock File
1
Dockerfile
1
Other (no ext)
1
Files by Type (size)
Rust
305KB
Lock File
73KB
Markdown
60KB
YAML
10KB
JavaScript
7KB
Other (.svg)
7KB
TOML
6KB
CSS
6KB
HTML
3KB
Protocol Buffers
3KB
Python
2KB
Other (.bin)
1KB

The LLM identified 5 files worth highlighting for reuse:

Implements a fast, lock-free port allocator using a bit set (u64 buckets) over a configurable port range. Provides O(1) allocate/deallocate with random starting offset to reduce collision predictability. The `PortAllocator` is a self-contained, reusable component for any service needing ephemeral port assignment in a fixed range.

file: src/service/session/ports.rs ↗ | tags: #bit-set-allocator #resource-pool

Provides a global, self-shrinking `Buffer` type backed by a lock-free `crossbeam::ArrayQueue` of pre-allocated `BytesMut` buffers. A background task monitors the ratio of idle-to-acquired buffers and reduces the pool when it detects sustained excess, preventing memory leaks under burst workloads. The buffer is safely acquired/returned via RAII (Drop). This pattern is extraction-ready for any high-throughput network service.

file: src/server/buffer.rs ↗ | tags: #memory-pool #buffer-reuse #shrink-detection

Implements an in-memory switch that maps session `Identifier`s to `tokio::sync::mpsc::UnboundedSender` channels. Relay packets are published via `send()` which drops silently if the receiver is gone, providing backpressure-free forwarding. The switch is transport-agnostic and enables the cross-protocol (UDP↔TCP) relaying required by the TURN spec.

file: src/server/switch.rs ↗ | tags: #message-bus #session-routing

Defines a type-safe, extensible STUN/TURN attribute hierarchy using the `Attribute` trait. Each attribute (e.g., `UserName`, `XorMappedAddress`, `MessageIntegrity`) has a well-defined serialization/deserialization and is automatically discovered from the binary stream. The pattern supports both comprehension-required and optional attributes with zero-copy parsing, and can serve as a template for any TLV-based protocol codec.

file: src/codec/message/attributes/mod.rs ↗ | tags: #attribute-system #protocol-codec

Provides cryptographic primitives for STUN/TURN authentication: HMAC-SHA1 for MESSAGE-INTEGRITY, CRC32 fingerprint, and password derivation (MD5 and SHA256) per RFC 5389/8489. The functions are pure, side-effect-free, and come with verified test vectors; they can be extracted into a standalone crate for any STUN-based project.

file: src/codec/crypto.rs ↗ | tags: #hmac #password-derivation #rfc-compliance
Last analyzed: 2026-09-20 15:01:15.969459
Next check: 2026-09-27 15:01:15.965390
$ submit: