1use std::net::SocketAddr;
4use std::time::Instant;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum SfuProtocol {
10 Udp,
12 Tcp,
14 SslTcp,
16 Tls,
18}
19
20impl SfuProtocol {
21 #[allow(dead_code)]
22 pub(crate) fn from_str0m(p: str0m::net::Protocol) -> Self {
23 use str0m::net::Protocol;
24 match p {
25 Protocol::Udp => Self::Udp,
26 Protocol::Tcp => Self::Tcp,
27 Protocol::SslTcp => Self::SslTcp,
28 Protocol::Tls => Self::Tls,
29 }
30 }
31 #[allow(dead_code)]
32 pub(crate) fn to_str0m(self) -> str0m::net::Protocol {
33 use str0m::net::Protocol;
34 match self {
35 Self::Udp => Protocol::Udp,
36 Self::Tcp => Protocol::Tcp,
37 Self::SslTcp => Protocol::SslTcp,
38 Self::Tls => Protocol::Tls,
39 }
40 }
41}
42
43#[derive(Debug)]
46pub struct IncomingDatagram {
47 pub received_at: Instant,
49 pub proto: SfuProtocol,
51 pub source: SocketAddr,
53 pub destination: SocketAddr,
55 pub contents: Vec<u8>,
57}
58
59#[derive(Debug)]
61pub struct OutgoingDatagram {
62 pub proto: SfuProtocol,
64 pub source: SocketAddr,
66 pub destination: SocketAddr,
68 pub contents: Vec<u8>,
70}
71
72impl OutgoingDatagram {
73 #[allow(dead_code)]
74 pub(crate) fn from_transmit(t: str0m::net::Transmit) -> Self {
75 Self {
76 proto: SfuProtocol::from_str0m(t.proto),
77 source: t.source,
78 destination: t.destination,
79 contents: t.contents.into(),
80 }
81 }
82}
83
84#[cfg(test)]
85mod tests {
86 use super::*;
87
88 #[test]
89 fn protocol_roundtrip() {
90 use str0m::net::Protocol;
91 for p in [
92 Protocol::Udp,
93 Protocol::Tcp,
94 Protocol::SslTcp,
95 Protocol::Tls,
96 ] {
97 let wrapped = SfuProtocol::from_str0m(p);
98 assert_eq!(wrapped.to_str0m(), p);
99 }
100 }
101}