rtc_ice/tcp_type/mod.rs
1#[cfg(test)]
2mod tcp_type_test;
3
4use std::fmt;
5
6// TCPType is the type of ICE TCP candidate as described in
7// https://tools.ietf.org/html/rfc6544#section-4.5
8#[derive(Default, PartialEq, Eq, Debug, Copy, Clone)]
9/// The role of an ICE-TCP candidate, per [RFC 6544] ยง4.5.
10///
11/// [RFC 6544]: https://datatracker.ietf.org/doc/html/rfc6544#section-4.5
12#[non_exhaustive]
13pub enum TcpType {
14 /// The default value. For example UDP candidates do not need this field.
15 #[default]
16 Unspecified,
17 /// Active TCP candidate, which initiates TCP connections.
18 Active,
19 /// Passive TCP candidate, only accepts TCP connections.
20 Passive,
21 /// Like `Active` and `Passive` at the same time.
22 SimultaneousOpen,
23}
24
25// from creates a new TCPType from string.
26impl From<&str> for TcpType {
27 fn from(raw: &str) -> Self {
28 match raw {
29 "active" => Self::Active,
30 "passive" => Self::Passive,
31 "so" => Self::SimultaneousOpen,
32 _ => Self::Unspecified,
33 }
34 }
35}
36
37impl fmt::Display for TcpType {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 let s = match *self {
40 Self::Active => "active",
41 Self::Passive => "passive",
42 Self::SimultaneousOpen => "so",
43 Self::Unspecified => "unspecified",
44 };
45 write!(f, "{s}")
46 }
47}