1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
//! WebRTC transport layer types for ICE, DTLS, and SCTP.
//!
//! This module provides types for working with the three transport layers used in WebRTC:
//!
//! - **ICE (Interactive Connectivity Establishment)** - Establishes peer-to-peer network connections
//! - **DTLS (Datagram Transport Layer Security)** - Provides encryption over UDP
//! - **SCTP (Stream Control Transmission Protocol)** - Multiplexes data channels over DTLS
//!
//! # Transport Stack
//!
//! WebRTC uses a layered transport architecture:
//!
//! ```text
//! ┌─────────────────────────────────────┐
//! │ Media/Data Channels │ Application Layer
//! ├─────────────────────────────────────┤
//! │ RTP/RTCP │ SCTP │ Protocol Layer
//! ├──────────────┴──────────────────────┤
//! │ DTLS (encryption) │ Security Layer
//! ├─────────────────────────────────────┤
//! │ ICE (NAT traversal) │ Connectivity Layer
//! ├─────────────────────────────────────┤
//! │ UDP/TCP │ Network Layer
//! └─────────────────────────────────────┘
//! ```
//!
//! # ICE Transport
//!
//! ICE establishes connectivity through NATs and firewalls by:
//!
//! 1. Gathering local network addresses ([`RTCIceCandidate`])
//! 2. Exchanging candidates with the remote peer
//! 3. Testing candidate pairs for connectivity
//! 4. Selecting the best working path
//!
//! Key ICE types:
//!
//! - [`RTCIceCandidate`] - A potential network address for communication
//! - [`RTCIceCandidateType`] - Type of candidate (host, srflx, prflx, relay)
//! - [`RTCIceTransportState`] - Current state of ICE connectivity
//! - [`RTCIceProtocol`] - Transport protocol (UDP or TCP)
//! - [`RTCIceRole`] - Whether controlling or controlled
//! - [`RTCIceServer`] - STUN/TURN server configuration
//!
//! # DTLS Transport
//!
//! DTLS provides end-to-end encryption over UDP:
//!
//! - [`RTCDtlsFingerprint`] - Certificate fingerprint for authentication
//! - [`RTCDtlsRole`] - Whether client or server in handshake
//! - [`RTCDtlsTransportState`] - Current state of DTLS connection
//!
//! # SCTP Transport
//!
//! SCTP multiplexes data channels over DTLS:
//!
//! - [`RTCSctpTransportState`] - Current state of SCTP association
//!
//! # Examples
//!
//! ## Working with ICE Candidates
//!
//! ```
//! use rtc::peer_connection::transport::{RTCIceCandidate, RTCIceCandidateType, RTCIceProtocol};
//!
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // Example candidate from ICE gathering
//! let candidate = RTCIceCandidate {
//! address: "192.168.1.100".to_string(),
//! port: 54321,
//! protocol: RTCIceProtocol::from("udp"),
//! typ: RTCIceCandidateType::Host,
//! component: 1,
//! priority: 2130706431,
//! ..Default::default()
//! };
//!
//! println!("Candidate type: {}", candidate.typ);
//! println!("Address: {}:{}", candidate.address, candidate.port);
//! # Ok(())
//! # }
//! ```
//!
//! ## Checking Transport States
//!
//! ```
//! use rtc::peer_connection::transport::{
//! RTCIceTransportState, RTCDtlsTransportState, RTCSctpTransportState
//! };
//!
//! fn is_connected(
//! ice_state: RTCIceTransportState,
//! dtls_state: RTCDtlsTransportState,
//! ) -> bool {
//! matches!(ice_state, RTCIceTransportState::Connected | RTCIceTransportState::Completed)
//! && dtls_state == RTCDtlsTransportState::Connected
//! }
//!
//! // All transports must be connected for media to flow
//! assert!(is_connected(
//! RTCIceTransportState::Connected,
//! RTCDtlsTransportState::Connected
//! ));
//! ```
//!
//! ## Candidate Type Classification
//!
//! ```
//! use rtc::peer_connection::transport::RTCIceCandidateType;
//!
//! fn requires_stun_server(candidate_type: RTCIceCandidateType) -> bool {
//! matches!(candidate_type, RTCIceCandidateType::Srflx)
//! }
//!
//! fn requires_turn_server(candidate_type: RTCIceCandidateType) -> bool {
//! matches!(candidate_type, RTCIceCandidateType::Relay)
//! }
//!
//! assert!(!requires_stun_server(RTCIceCandidateType::Host));
//! assert!(requires_stun_server(RTCIceCandidateType::Srflx));
//! assert!(requires_turn_server(RTCIceCandidateType::Relay));
//! ```
//!
//! ## DTLS Role Determination
//!
//! ```
//! use rtc::peer_connection::transport::RTCDtlsRole;
//!
//! // Offerer uses Auto (actpass in SDP)
//! let offerer_role = RTCDtlsRole::Auto;
//!
//! // Answerer should use Client (active in SDP) for lower latency
//! let answerer_role = RTCDtlsRole::Client;
//!
//! println!("Offerer: {}", offerer_role);
//! println!("Answerer: {}", answerer_role);
//! ```
//!
//! # Specifications
//!
//! - [RFC 8445] - ICE: Interactive Connectivity Establishment
//! - [RFC 6347] - DTLS: Datagram Transport Layer Security
//! - [RFC 8261] - SCTP over DTLS for WebRTC Data Channels
//! - [RFC 5245] - ICE (obsoleted by RFC 8445)
//! - [RFC 5389] - STUN: Session Traversal Utilities for NAT
//! - [RFC 8656] - TURN: Traversal Using Relays around NAT
//! - [W3C WebRTC Specification]
//!
//! [RFC 8445]: https://datatracker.ietf.org/doc/html/rfc8445
//! [RFC 6347]: https://datatracker.ietf.org/doc/html/rfc6347
//! [RFC 8261]: https://datatracker.ietf.org/doc/html/rfc8261
//! [RFC 5245]: https://datatracker.ietf.org/doc/html/rfc5245
//! [RFC 5389]: https://datatracker.ietf.org/doc/html/rfc5389
//! [RFC 8656]: https://datatracker.ietf.org/doc/html/rfc8656
//! [W3C WebRTC Specification]: https://w3c.github.io/webrtc-pc/
pub
pub
pub
pub use RTCDtlsFingerprint;
pub use RTCDtlsParameters;
pub use RTCDtlsRole;
pub use RTCDtlsTransportState;
use fmt;
pub use ;
pub use RTCIceCandidatePair;
pub use RTCIceCandidateType;
pub use RTCIceParameters;
pub use RTCIceProtocol;
pub use RTCIceRole;
pub use RTCIceServer;
pub use RTCIceTransportState;
pub use RTCSctpTransportState;
use crateRTCPeerConnection;
use crateRTCIceGatheringState;
pub use RTCIceComponent;
/// Identifies one of a peer connection's transports.
///
/// Obtainable only from a transport, and stable for that transport's lifetime. Its purpose is
/// comparison:
///
/// ```ignore
/// // Does this sender send over the same DTLS transport the data channels use?
/// sctp.transport().id() == sender.transport()?.id()
/// ```
///
/// # Why an id at all
///
/// W3C models the transport graph with object references, so a browser answers the question above
/// with `===`. Two Rust handles cannot offer that: they are values, and the objects they refer to
/// live behind the peer connection. Exposing identity explicitly is the honest alternative —
/// returning handles that compared unequal despite naming the same transport would be worse.
///
/// # Guarantees
///
/// - **Distinct transports have distinct ids**, including across peer connections. Comparing a
/// transport from one connection with a transport from another correctly reports "different",
/// which matters to anything holding many connections at once.
/// - **Stable across reads.** The value is assigned when the transport is created, not derived
/// when it is asked for.
///
/// # Non-guarantees
///
/// - **The value is opaque.** Do not parse, order, or persist it; assert `a == b`, never
/// `a == 3`.
/// - **It is not reproducible across runs.** It is seeded from a per-connection random nonce,
/// because distinctness across connections and reproducibility are mutually exclusive: two
/// connections built from identical inputs would otherwise produce identical ids.
/// - **It is unrelated to `RTCStatsId`.** Stats ids name entries in a stats report; there is one
/// `RTCTransportStats` entry describing the bundled transport, not one per transport.
;
/// Which transport within a peer connection an [`RTCTransportId`] names.
///
/// Occupies the low two bits, so the three transports of one connection are distinguishable from
/// each other as well as from every other connection's.
pub
/// Provides access to information about the ICE transport over which packets are sent and
/// received.
///
/// Obtained by walking from [`RTCDtlsTransport::ice_transport`].
///
/// ## Specifications
///
/// * [W3C]
///
/// [W3C]: https://www.w3.org/TR/webrtc/#dom-rtcicetransport
/// Provides access to information about the DTLS transport over which RTP, RTCP and SCTP are
/// sent and received.
///
/// Obtained by walking from [`RTCSctpTransport::transport`], or from a sender's or receiver's
/// `transport()`.
///
/// ## Specifications
///
/// * [W3C]
///
/// [W3C]: https://www.w3.org/TR/webrtc/#dom-rtcdtlstransport
/// Provides access to information about the SCTP transport that carries data channels.
///
/// Obtained from [`RTCPeerConnection::sctp`].
///
/// ## Specifications
///
/// * [W3C]
///
/// [W3C]: https://www.w3.org/TR/webrtc/#dom-rtcsctptransport
/// [`RTCPeerConnection::sctp`]: crate::peer_connection::RTCPeerConnection::sctp