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
49#[cfg(feature = "rustls")]
50pub mod rustls;
51
52#[cfg(feature = "openssl")]
53pub mod openssl;
54
55pub use stun_proto as stun;
56pub use turn_types as types;
57
58#[cfg(test)]
59mod tests {
60 use tracing::subscriber::DefaultGuard;
61 use tracing_subscriber::layer::SubscriberExt;
62 use tracing_subscriber::Layer;
63
64 pub fn test_init_log() -> DefaultGuard {
65 turn_types::debug_init();
66 let level_filter = std::env::var("TURN_LOG")
67 .or(std::env::var("RUST_LOG"))
68 .ok()
69 .and_then(|var| var.parse::<tracing_subscriber::filter::Targets>().ok())
70 .unwrap_or(
71 tracing_subscriber::filter::Targets::new().with_default(tracing::Level::TRACE),
72 );
73 let registry = tracing_subscriber::registry().with(
74 tracing_subscriber::fmt::layer()
75 .with_file(true)
76 .with_line_number(true)
77 .with_level(true)
78 .with_target(false)
79 .with_test_writer()
80 .with_filter(level_filter),
81 );
82 tracing::subscriber::set_default(registry)
83 }
84}