Skip to main content

Dispatch

Trait Dispatch 

Source
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§

Source

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).

Source

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).

Source

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§

Source

fn next_timeout_ms(&self, _now_ms: u64) -> Option<u64>

Optional next timeout hint in milliseconds from now_ms. When provided, run_poll clamps its epoll wait timeout to min(10, delay).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§