pub trait Dispatch {
// Required methods
fn on_udp(
&mut self,
src: SocketAddr,
dg: &[u8],
now_ms: u64,
) -> DispatchOut<'_>;
fn on_tun(&mut self, inner: &[u8], now_ms: u64) -> &[EgressDatagram];
fn tick(&mut self, now_ms: u64) -> Option<&[EgressDatagram]>;
// Provided method
fn next_timeout_ms(&self, _now_ms: u64) -> Option<u64> { ... }
}Expand description
A single-threaded data-plane dispatch interface.
Implementors hold all mutable state (AEAD session, FEC transport, codec,
auxiliary logs). run_poll drives this trait from an epoll loop.
§Addressing (multipeer 2a seam)
on_udp is told the datagram’s source address and every egress datagram
carries its own destination (see EgressDatagram::dst), so a future
multi-peer Dispatch can route by address. A single-peer implementor is
free to ignore src and stamp a fixed dst on everything it emits —
exactly what crate::poll’s test dispatches below do, and what
yipd’s DataPlane does until the Task 5 PeerManager lands.
Required Methods§
Sourcefn on_udp(&mut self, src: SocketAddr, dg: &[u8], now_ms: u64) -> DispatchOut<'_>
fn on_udp(&mut self, src: SocketAddr, dg: &[u8], now_ms: u64) -> DispatchOut<'_>
Called when a UDP datagram arrives, with the address it came from.
Returns what run_poll must forward (to TUN, back to UDP, both, or
nothing).
Sourcefn on_tun(&mut self, inner: &[u8], now_ms: u64) -> &[EgressDatagram]
fn on_tun(&mut self, inner: &[u8], now_ms: u64) -> &[EgressDatagram]
Called when a TUN frame arrives. Returns egress datagrams to send on
the UDP socket (may be empty), each tagged with its FEC fate group and
destination so a GSO-capable driver can coalesce safely (see
EgressDatagram).
Sourcefn tick(&mut self, now_ms: u64) -> Option<&[EgressDatagram]>
fn tick(&mut self, now_ms: u64) -> Option<&[EgressDatagram]>
Called at least every 10 ms. Returns addressed feedback/keepalive datagrams (usually 0 or 1) that should be sent on the UDP socket.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".