Skip to main content

rtci_turn/
lib.rs

1#![warn(rust_2018_idioms)]
2#![warn(missing_docs)]
3#![allow(dead_code)]
4
5//! TURN for the Sans-I/O WebRTC stack.
6//!
7//! Traversal Using Relays around NAT ([RFC 8656], which replaced RFC 5766 and RFC 6156). TURN
8//! is ICE's fallback: when no direct path between two peers can be found, each relays its
9//! media through a server, which allocates a public address on their behalf.
10//!
11//! The client covers the client role of RFC 8656: UDP relayed addresses of either family or
12//! both (`REQUESTED-ADDRESS-FAMILY`, `ADDITIONAL-ADDRESS-FAMILY`), permissions, channels,
13//! `DONT-FRAGMENT`, even and reserved ports, ICMP errors, and the long-term credential of
14//! RFC 8489 (SHA-256 password algorithm, `USERHASH`, `MESSAGE-INTEGRITY-SHA256`, and RFC
15//! 5389's MD5 for servers that have nothing else); and TCP allocations ([RFC 6062]):
16//! `Connect`, `ConnectionAttempt`, and a data connection per peer. Requests are sent on the
17//! retransmission timer of RFC 8489 section 6.2, and every received STUN message is read
18//! through `rtci_stun::validated`. There is no TURN server here.
19//!
20//! # Structure
21//!
22//! * [`client`] — the Sans-I/O client: allocate a relayed address, create permissions,
23//!   bind channels, and send or receive through the allocation. It owns no sockets.
24//! * [`proto`] — the TURN-specific STUN attributes and methods (`ALLOCATE`,
25//!   `CREATE-PERMISSION`, `CHANNEL-BIND`, `XOR-RELAYED-ADDRESS`, ChannelData framing),
26//!   built on [`rtci-stun`].
27//!
28//! # Example
29//!
30//! A client is configured with the server to allocate from and the long-term credentials to
31//! authenticate with; driving it is then a matter of feeding it datagrams and polling for
32//! [`Event`](client::Event)s:
33//!
34//! ```
35//! use rtci_turn::client::ClientConfig;
36//! use shared::TransportProtocol;
37//!
38//! let config = ClientConfig {
39//!     turn_serv_addr: "turn.example.com:3478".to_owned(),
40//!     local_addr: "0.0.0.0:0".parse().unwrap(),
41//!     transport_protocol: TransportProtocol::UDP,
42//!     username: "user".to_owned(),
43//!     password: "pass".to_owned(),
44//!     realm: "example.com".to_owned(),
45//!     stun_serv_addr: String::new(), // optional: only for Binding requests
46//!     software: String::new(),
47//!     rto_in_ms: 0, // 0 selects the default initial RTO, 500 ms
48//!     allocation_refresh_interval_cap: None,
49//!     ..Default::default()
50//! };
51//! assert_eq!(config.turn_serv_addr, "turn.example.com:3478");
52//! ```
53//!
54//! The application owns the socket: it feeds what arrives to the client, sends what the client
55//! queues, and adds the relayed address to its ICE agent as a relay candidate. The crate is
56//! re-exported as `rtci::turn`.
57//!
58//! [RFC 8656]: https://datatracker.ietf.org/doc/html/rfc8656
59//! [RFC 6062]: https://datatracker.ietf.org/doc/html/rfc6062
60//! [`rtci-stun`]: https://docs.rs/rtc-stun
61
62/// The Sans-I/O TURN client: allocate a relayed address and send through it.
63/// The crypto provider API.
64///
65/// Re-exported because this crate's public constructors take an
66/// [`Arc<dyn RTCCryptoProvider>`](crypto::RTCCryptoProvider), which a caller must be able to name
67/// without adding — and version-matching — a direct `rtci-crypto` dependency.
68pub use crypto;
69
70pub mod client;
71/// Entry points for stateful fuzz targets. Gated behind `cfg(fuzzing)`; not part of the
72/// supported API.
73#[cfg(all(fuzzing, any(feature = "crypto-ring", feature = "crypto-aws-lc-rs")))]
74pub mod fuzzing;
75/// The TURN-specific STUN attributes, methods and ChannelData framing.
76pub mod proto;
77pub mod rest;