1 #[cfg(test)] 2 mod proto_test; 3 4 pub mod addr; 5 pub mod chandata; 6 pub mod channum; 7 pub mod data; 8 pub mod dontfrag; 9 pub mod evenport; 10 pub mod lifetime; 11 pub mod peeraddr; 12 pub mod relayaddr; 13 pub mod reqfamily; 14 pub mod reqtrans; 15 pub mod rsrvtoken; 16 17 use std::fmt; 18 19 use 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, Hash)] 25 pub struct Protocol(pub u8); 26 27 // PROTO_UDP is IANA assigned protocol number for UDP. 28 pub const PROTO_TCP: Protocol = Protocol(6); 29 pub const PROTO_UDP: Protocol = Protocol(17); 30 31 impl 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. 47 pub const DEFAULT_PORT: u16 = stun::DEFAULT_PORT; 48 // DEFAULT_TLSPORT is for TURN over TLS and is same as STUN. 49 pub const DEFAULT_TLS_PORT: u16 = stun::DEFAULT_TLS_PORT; 50 51 // create_permission_request is shorthand for create permission request type. 52 pub 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. 57 pub fn allocate_request() -> MessageType { 58 MessageType::new(METHOD_ALLOCATE, CLASS_REQUEST) 59 } 60 61 // send_indication is shorthand for send indication message type. 62 pub fn send_indication() -> MessageType { 63 MessageType::new(METHOD_SEND, CLASS_INDICATION) 64 } 65 66 // refresh_request is shorthand for refresh request message type. 67 pub fn refresh_request() -> MessageType { 68 MessageType::new(METHOD_REFRESH, CLASS_REQUEST) 69 } 70