Skip to main content

UdpManager

Struct UdpManager 

Source
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 UdpManager<SourceTupleExtractor>

Source

pub fn new( cluster: ClusterConfig, max_flows: usize, max_rx_datagram_size: usize, hash_seed: u64, ) -> Self

Construct a manager with the default 4-tuple/2-tuple source extractor.

Source§

impl<E: FlowKeyExtractor> UdpManager<E>

Source

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.

Source

pub fn flow_count(&self) -> usize

Number of currently admitted flows. Mirrors udp.active_flows.

Source

pub fn max_flows(&self) -> usize

The configured flow-table cap.

Source

pub fn is_draining(&self) -> bool

Whether the listener is draining.

Source

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.

Source

pub fn flow(&self, flow: FlowId) -> Option<&UdpFlow>

Borrow a flow by id (for the shell’s access log on close).

Source

pub fn handle_input(&mut self, input: ManagerInput<'_>, now: Instant)

Feed one input into the manager. Pure: now is injected.

Source

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

Source

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.

Source

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

Source

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.

Source

pub fn poll_output(&mut self) -> Option<Output>

Drain the next queued output, or None when the queue is empty.

Auto Trait Implementations§

§

impl<E> Freeze for UdpManager<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for UdpManager<E>
where E: RefUnwindSafe,

§

impl<E> Send for UdpManager<E>
where E: Send,

§

impl<E> Sync for UdpManager<E>
where E: Sync,

§

impl<E> Unpin for UdpManager<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for UdpManager<E>
where E: UnsafeUnpin,

§

impl<E> UnwindSafe for UdpManager<E>
where E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more