use flowscope::driver::{DriverBuilder, SlotHandle};
use flowscope::extract::{FiveTuple, FiveTupleKey};
use crate::protocol::{Dispatch, MessageProtocol, Protocol, ProtocolInitError};
#[derive(Debug, Clone, Copy)]
pub struct Quic;
impl MessageProtocol for Quic {}
impl Protocol for Quic {
type Message = flowscope::QuicInitial;
const NAME: &'static str = "quic";
fn dispatch() -> Dispatch {
Dispatch::Udp(vec![flowscope::quic::QUIC_PORT])
}
fn register(
builder: &mut DriverBuilder<FiveTuple>,
) -> Result<SlotHandle<Self::Message, FiveTupleKey>, ProtocolInitError> {
let ports = match Self::dispatch() {
Dispatch::Udp(p) => p,
_ => unreachable!("Quic::dispatch is Dispatch::Udp by construction"),
};
Ok(builder.datagram_on_ports(flowscope::quic::QuicUdpParser::new(), ports))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn dispatch_targets_udp_443() {
match Quic::dispatch() {
Dispatch::Udp(ports) => assert_eq!(ports, vec![443]),
other => panic!("expected Dispatch::Udp, got {other:?}"),
}
}
#[test]
fn name_is_quic() {
assert_eq!(Quic::NAME, "quic");
}
}