Turn Server SDK
A Rust client SDK for interacting with the turn-server gRPC API exposed by the turn-rs project. This crate provides both client and server utilities for TURN server integration.
Features
- TurnService Client: Query server information, session details, and manage TURN sessions
- TurnHooksServer: Implement custom authentication and event handling for TURN server hooks
- Password Generation: Generate STUN/TURN authentication passwords using MD5 or SHA256
Installation
Add this to your Cargo.toml:
[]
= "0.1.0-beta.1" # When published
= "0.1.0-beta.1"
Client Usage
The TurnService client allows you to interact with a running TURN server's gRPC API:
use ;
async
Server Usage (Hooks Implementation)
Implement the TurnHooksServer trait to provide custom authentication and handle TURN events:
use ;
;
async
Password Generation
Generate STUN/TURN authentication passwords for long-term credentials:
use ;
// Generate MD5 password (RFC 5389)
let md5_password = generate_password;
// Generate SHA256 password (RFC 8489)
let sha256_password = generate_password;
// Access the password bytes
match md5_password
Event Handling
The TurnHooksServer trait provides hooks for various TURN server events:
on_allocated: Called when a client allocates a relay porton_channel_bind: Called when a channel is bound to a peeron_create_permission: Called when permissions are created for peerson_refresh: Called when a session is refreshedon_destroy: Called when a session is destroyed
All event handlers are optional and have default no-op implementations. You only need to implement the ones you care about.
Error Handling
Most operations return Result<T, Status> where Status is a gRPC status code. Common error scenarios:
Status::not_found: Session or resource not foundStatus::unavailable: Server is not availableStatus::unauthenticated: Authentication failedStatus::internal: Internal server error
Re-exports
This crate re-exports:
tonic: The gRPC framework used for communicationprotos: The generated protobuf bindings for TURN server messages
You can use these directly from turn_server_sdk:
use ;
Documentation
For more detailed API documentation, see:
- API Documentation (when published)
- TURN Server Documentation
- RFC 8489 - Session Traversal Utilities for NAT (STUN)
- RFC 8656 - Traversal Using Relays around NAT (TURN)
License
This project is licensed under the MIT License - see the LICENSE file for details.