turn_server_proto/lib.rs
1// Copyright (C) 2025 Matthew Waters <matthew@centricular.com>
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8//
9// SPDX-License-Identifier: MIT OR Apache-2.0
10
11//! # turn-server-proto
12//!
13//! `turn-server-proto` provides a sans-IO API for a TURN server communicating with many TURN clients.
14//!
15//! Relevant standards:
16//! - [RFC5766]: Traversal Using Relays around NAT (TURN).
17//! - [RFC6062]: Traversal Using Relays around NAT (TURN) Extensions for TCP Allocations
18//! - [RFC6156]: Traversal Using Relays around NAT (TURN) Extension for IPv6
19//! - [RFC8656]: Traversal Using Relays around NAT (TURN): Relay Extensions to Session
20//! Traversal Utilities for NAT (STUN)
21//!
22//! [RFC5766]: https://datatracker.ietf.org/doc/html/rfc5766
23//! [RFC6062]: https://tools.ietf.org/html/rfc6062
24//! [RFC6156]: https://tools.ietf.org/html/rfc6156
25//! [RFC8656]: https://tools.ietf.org/html/rfc8656
26//!
27//! ## Rustls crypto providers
28//!
29//! `turn-server-proto` does not enable any cryptographic providers on rustls.
30//! It is the user's responsibility (library or application) to enable and use
31//! the relevant cryptographic provider (ring, aws-lc-rs, RustCrypto, etc),
32//! that they wish to use.
33
34#![deny(missing_debug_implementations)]
35#![deny(missing_docs)]
36#![cfg_attr(docsrs, feature(doc_cfg))]
37#![deny(clippy::std_instead_of_core)]
38#![deny(clippy::std_instead_of_alloc)]
39#![no_std]
40
41extern crate alloc;
42
43#[cfg(any(feature = "std", test))]
44extern crate std;
45
46pub mod api;
47pub mod server;
48
49pub use stun_proto as stun;
50pub use turn_types as types;
51
52#[cfg(test)]
53mod tests {
54 use tracing::subscriber::DefaultGuard;
55 use tracing_subscriber::layer::SubscriberExt;
56 use tracing_subscriber::Layer;
57
58 pub fn test_init_log() -> DefaultGuard {
59 turn_types::debug_init();
60 let level_filter = std::env::var("TURN_LOG")
61 .or(std::env::var("RUST_LOG"))
62 .ok()
63 .and_then(|var| var.parse::<tracing_subscriber::filter::Targets>().ok())
64 .unwrap_or(
65 tracing_subscriber::filter::Targets::new().with_default(tracing::Level::TRACE),
66 );
67 let registry = tracing_subscriber::registry().with(
68 tracing_subscriber::fmt::layer()
69 .with_file(true)
70 .with_line_number(true)
71 .with_level(true)
72 .with_target(false)
73 .with_test_writer()
74 .with_filter(level_filter),
75 );
76 tracing::subscriber::set_default(registry)
77 }
78}