use std::net::SocketAddr;
use std::time::Instant;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum SfuProtocol {
Udp,
Tcp,
SslTcp,
Tls,
}
impl SfuProtocol {
#[allow(dead_code)]
pub(crate) fn from_str0m(p: str0m::net::Protocol) -> Self {
use str0m::net::Protocol;
match p {
Protocol::Udp => Self::Udp,
Protocol::Tcp => Self::Tcp,
Protocol::SslTcp => Self::SslTcp,
Protocol::Tls => Self::Tls,
}
}
#[allow(dead_code)]
pub(crate) fn to_str0m(self) -> str0m::net::Protocol {
use str0m::net::Protocol;
match self {
Self::Udp => Protocol::Udp,
Self::Tcp => Protocol::Tcp,
Self::SslTcp => Protocol::SslTcp,
Self::Tls => Protocol::Tls,
}
}
}
#[derive(Debug)]
pub struct IncomingDatagram {
pub received_at: Instant,
pub proto: SfuProtocol,
pub source: SocketAddr,
pub destination: SocketAddr,
pub contents: Vec<u8>,
}
#[derive(Debug)]
pub struct OutgoingDatagram {
pub proto: SfuProtocol,
pub source: SocketAddr,
pub destination: SocketAddr,
pub contents: Vec<u8>,
}
impl OutgoingDatagram {
#[allow(dead_code)]
pub(crate) fn from_transmit(t: str0m::net::Transmit) -> Self {
Self {
proto: SfuProtocol::from_str0m(t.proto),
source: t.source,
destination: t.destination,
contents: t.contents.into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn protocol_roundtrip() {
use str0m::net::Protocol;
for p in [
Protocol::Udp,
Protocol::Tcp,
Protocol::SslTcp,
Protocol::Tls,
] {
let wrapped = SfuProtocol::from_str0m(p);
assert_eq!(wrapped.to_str0m(), p);
}
}
}