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