Skip to main content

Module udp

Module udp 

Source
Expand description

UDP load-balancing I/O shell + mio event-loop wiring (issue #1273).

This module is the impure half of the UDP datapath: it owns every syscall, the buffer copies, the per-flow connected upstream sockets, the timer arming, the BackendMap/health/metrics edges, and the slab/token bookkeeping. It drives the pure sans-io core in crate::protocol::udp (the UdpManager / UdpFlow two-level split) through ManagerInput / Output.

Architecture (mirrors tcp.rs, but UDP is one-listener-many-flows):

  • UdpListener wraps the single mio::net::UdpSocket a listener binds. There is no accept loop — a readable event means “datagrams waiting”, not “a new connection”.
  • UdpProxy holds the listeners, the per-listener UdpManagers, the shared BackendMap, the session slab and the registry. It does not implement ProxyConfiguration / L7Proxy (their signatures are TcpStream-bound); the server calls its inherent notify directly.
  • UdpListenerSession is the ProxySession the server’s generic readiness path drives. One session backs one listener; its update_readiness demuxes by token (listener-token = client recv; upstream-token = backend recv). It owns the per-flow connected sockets and the upstream_token -> FlowId map.

UDP never goes through accept() / create_session(): a Protocol::UDP listener readable event falls through Server::ready’s generic arm into ProxySession::ready.

Long-form lifecycle (datapath, NAT return, teardown, control plane, hardening): lib/src/protocol/udp/LIFECYCLE.md.

Structs§

UdpHealthChecker
Timer-driven, non-blocking UDP backend health prober. Owned by UdpProxy; driven from the server event loop exactly like the HTTP HealthChecker (poll once per iteration, ready(token) on owned readiness).
UdpListener
One UDP listener: a single mio::net::UdpSocket plus its routing config. Unlike a TCP listener there is no accept loop — a readable event is a batch of datagrams the session drains to WouldBlock.
UdpListenerSession
The ProxySession backing one UDP listener. The server’s generic readiness path drives this (UDP is not in the listen-accept arm). It owns the per-flow connected upstream sockets and demuxes events by token.
UdpProxy
The UDP proxy. Holds the listeners, one UdpManager per listener token, the shared BackendMap, the session slab and a cloned registry. Does NOT implement ProxyConfiguration / L7Proxy; the server drives it through the inherent notify plus the activate/give-back helpers.