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//! # turn-server-proto
10//!
11//! `turn-server-proto` provides a sans-IO API for a TURN server communicating with many TURN clients.
12//!
13//! Relevant standards:
14//! - [RFC5766]: Traversal Using Relays around NAT (TURN).
15//! - [RFC6062]: Traversal Using Relays around NAT (TURN) Extensions for TCP Allocations
16//! - [RFC6156]: Traversal Using Relays around NAT (TURN) Extension for IPv6
17//! - [RFC8656]: Traversal Using Relays around NAT (TURN): Relay Extensions to Session
18//! Traversal Utilities for NAT (STUN)
19//!
20//! [RFC5766]: https://datatracker.ietf.org/doc/html/rfc5766
21//! [RFC6062]: https://tools.ietf.org/html/rfc6062
22//! [RFC6156]: https://tools.ietf.org/html/rfc6156
23//! [RFC8656]: https://tools.ietf.org/html/rfc8656
24
25#![deny(missing_debug_implementations)]
26#![deny(missing_docs)]
27#![cfg_attr(docsrs, feature(doc_cfg))]
28#![no_std]
29
30extern crate alloc;
31
32#[cfg(any(feature = "std", test))]
33extern crate std;
34
35pub mod api;
36pub mod server;
37
38#[cfg(feature = "rustls")]
39pub mod rustls;
40
41#[cfg(feature = "openssl")]
42pub mod openssl;
43
44pub use stun_proto as stun;
45pub use turn_types as types;
46
47#[cfg(test)]
48mod tests {
49 use tracing::subscriber::DefaultGuard;
50 use tracing_subscriber::layer::SubscriberExt;
51 use tracing_subscriber::Layer;
52
53 pub fn test_init_log() -> DefaultGuard {
54 turn_types::debug_init();
55 let level_filter = std::env::var("TURN_LOG")
56 .or(std::env::var("RUST_LOG"))
57 .ok()
58 .and_then(|var| var.parse::<tracing_subscriber::filter::Targets>().ok())
59 .unwrap_or(
60 tracing_subscriber::filter::Targets::new().with_default(tracing::Level::TRACE),
61 );
62 let registry = tracing_subscriber::registry().with(
63 tracing_subscriber::fmt::layer()
64 .with_file(true)
65 .with_line_number(true)
66 .with_level(true)
67 .with_target(false)
68 .with_test_writer()
69 .with_filter(level_filter),
70 );
71 tracing::subscriber::set_default(registry)
72 }
73}