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