webrtc_turn/proto/
mod.rs

1#[cfg(test)]
2mod proto_test;
3
4pub mod addr;
5pub mod chandata;
6pub mod channum;
7pub mod data;
8pub mod dontfrag;
9pub mod evenport;
10pub mod lifetime;
11pub mod peeraddr;
12pub mod relayaddr;
13pub mod reqfamily;
14pub mod reqtrans;
15pub mod rsrvtoken;
16
17use std::fmt;
18
19use stun::message::*;
20
21// proto implements RFC 5766 Traversal Using Relays around NAT.
22
23// protocol is IANA assigned protocol number.
24#[derive(PartialEq, Eq, Default, Debug, Clone, Copy)]
25pub struct Protocol(pub u8);
26
27// PROTO_UDP is IANA assigned protocol number for UDP.
28pub const PROTO_TCP: Protocol = Protocol(6);
29pub const PROTO_UDP: Protocol = Protocol(17);
30
31impl fmt::Display for Protocol {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        let others = format!("{}", self.0);
34        let s = match *self {
35            PROTO_UDP => "UDP",
36            PROTO_TCP => "TCP",
37            _ => others.as_str(),
38        };
39
40        write!(f, "{}", s)
41    }
42}
43
44// Default ports for TURN from RFC 5766 Section 4.
45
46// DEFAULT_PORT for TURN is same as STUN.
47pub const DEFAULT_PORT: u16 = stun::DEFAULT_PORT;
48// DEFAULT_TLSPORT is for TURN over TLS and is same as STUN.
49pub const DEFAULT_TLS_PORT: u16 = stun::DEFAULT_TLS_PORT;
50
51// create_permission_request is shorthand for create permission request type.
52pub fn create_permission_request() -> MessageType {
53    MessageType::new(METHOD_CREATE_PERMISSION, CLASS_REQUEST)
54}
55
56// allocate_request is shorthand for allocation request message type.
57pub fn allocate_request() -> MessageType {
58    MessageType::new(METHOD_ALLOCATE, CLASS_REQUEST)
59}
60
61// send_indication is shorthand for send indication message type.
62pub fn send_indication() -> MessageType {
63    MessageType::new(METHOD_SEND, CLASS_INDICATION)
64}
65
66// refresh_request is shorthand for refresh request message type.
67pub fn refresh_request() -> MessageType {
68    MessageType::new(METHOD_REFRESH, CLASS_REQUEST)
69}