pub struct UdpManager<E: FlowKeyExtractor = SourceTupleExtractor> { /* private fields */ }Expand description
The pure UDP flow manager. Generic over the flow-key extractor so the seam
stays type-checked; the shell instantiates it with SourceTupleExtractor.
Implementations§
Source§impl<E: FlowKeyExtractor> UdpManager<E>
impl<E: FlowKeyExtractor> UdpManager<E>
Sourcepub fn with_extractor(
cluster: ClusterConfig,
max_flows: usize,
max_rx_datagram_size: usize,
hash_seed: u64,
extractor: E,
) -> Self
pub fn with_extractor( cluster: ClusterConfig, max_flows: usize, max_rx_datagram_size: usize, hash_seed: u64, extractor: E, ) -> Self
Construct a manager with a custom flow-key extractor.
Sourcepub fn flow_count(&self) -> usize
pub fn flow_count(&self) -> usize
Number of currently admitted flows. Mirrors udp.active_flows.
Sourcepub fn is_draining(&self) -> bool
pub fn is_draining(&self) -> bool
Whether the listener is draining.
Sourcepub fn affinity_with_port(&self) -> bool
pub fn affinity_with_port(&self) -> bool
Whether the active cluster config keys flows on the 4-tuple (source
IP + port) rather than source IP only. The shell needs this to mirror
the manager’s flow keying for its SendToBackend socket resolution.
Sourcepub fn flow(&self, flow: FlowId) -> Option<&UdpFlow>
pub fn flow(&self, flow: FlowId) -> Option<&UdpFlow>
Borrow a flow by id (for the shell’s access log on close).
Sourcepub fn handle_input(&mut self, input: ManagerInput<'_>, now: Instant)
pub fn handle_input(&mut self, input: ManagerInput<'_>, now: Instant)
Feed one input into the manager. Pure: now is injected.
Sourcepub fn abort_flow(&mut self, flow: FlowId, _now: Instant, reason: CloseReason)
pub fn abort_flow(&mut self, flow: FlowId, _now: Instant, reason: CloseReason)
Tear down a single flow on demand, emitting the same outputs a normal
idle close produces — Output::Metric(MetricEvent::FlowEvicted) then
Output::CloseFlow(flow) — so the shell draining poll_output()
decrements udp.active_flows and frees the upstream socket exactly once.
The shell calls this when it cannot establish a flow it just admitted:
the upstream connect() failed (EMFILE / connection refused) or no
backend resolved. Without it the flow would sit AwaitingBackend /
Established pinning a max_flows slot for the full idle timeout.
Idempotent: a missing flow or one already Closing is a no-op — no
double-evict, no gauge underflow. Works in either AwaitingBackend or
Established. now is accepted for signature symmetry with the other
time-driven entry points (the teardown itself is time-independent).
Sourcepub fn close_all(&mut self, now: Instant)
pub fn close_all(&mut self, now: Instant)
Tear down EVERY live flow, emitting — for each — the same outputs a
normal idle close produces (Output::Metric(MetricEvent::FlowEvicted)
then Output::CloseFlow(flow)), so the shell draining poll_output()
decrements udp.active_flows and frees each upstream socket exactly once
per flow.
The shell calls this on listener remove / deactivate / soft-stop before
dropping the manager, so the active-flows gauge does not leak. Draining
the flow table + slab to zero; a flow already Closing is skipped
(idempotent, no double-evict, no underflow). After this returns,
flow_count() == 0 and no timer is armed.
Sourcepub fn handle_timeout(&mut self, now: Instant)
pub fn handle_timeout(&mut self, now: Instant)
Fire all flows whose idle deadline has elapsed at now. A flow is only
closed if its generation token still matches the scheduled deadline —
generation mismatch means the flow saw traffic and was rescheduled, so
the stale expiry is ignored (defeats the busy-loop / stale-close bug).
Sourcepub fn poll_timeout(&self) -> Option<Instant>
pub fn poll_timeout(&self) -> Option<Instant>
The next manager-wide deadline, or None if no flow is armed. After a
[handle_timeout] at deadline d, the value returned here is guaranteed
> d (or None) — the strict-advance invariant handle_timeout asserts
in debug builds, which is what stops the shell busy-looping.
Sourcepub fn poll_output(&mut self) -> Option<Output>
pub fn poll_output(&mut self) -> Option<Output>
Drain the next queued output, or None when the queue is empty.