Skip to main content

UdpFlow

Struct UdpFlow 

Source
pub struct UdpFlow {
    pub client: SocketAddr,
    pub backend_id: Option<String>,
    pub backend_addr: Option<SocketAddr>,
    pub phase: FlowPhase,
    pub config: ClusterConfig,
    pub requests_seen: u32,
    pub responses_seen: u32,
    pub idle_deadline: Instant,
    pub timer_gen: u64,
    pub first_upstream_pending: bool,
}
Expand description

Per-admitted-flow state. Slab slot payload owned by the manager.

Fields§

§client: SocketAddr

Real (pre-NAT) client source address — the symmetric NAT return target and the PPv2 source address.

§backend_id: Option<String>

Backend id, set when the core selects the flow’s backend at admission.

§backend_addr: Option<SocketAddr>

Backend address, set when the core selects the flow’s backend at admission.

§phase: FlowPhase

Lifecycle phase.

§config: ClusterConfig

Captured per-cluster knobs (responses/requests/timeouts/PPv2). Captured at admission so a mid-flow reconfig does not change a live flow’s teardown contract (stable affinity).

§requests_seen: u32

Client datagrams forwarded so far (counts toward requests).

§responses_seen: u32

Backend replies returned so far (counts toward responses).

§idle_deadline: Instant

Absolute idle deadline; reset on every datagram in either direction.

§timer_gen: u64

Refresh counter. Incremented every time the idle deadline is pushed back. No expiry path reads it: a wheel expiry closes the flow only when idle_deadline is still <= now (deadline revalidation in UdpManager::handle_timeout), which is what keeps a stale expiry from closing a refreshed flow.

§first_upstream_pending: bool

True until the first upstream datagram is sent; gates PPv2 prefixing when proxy_protocol_every_datagram is false (first-datagram-only).

Implementations§

Source§

impl UdpFlow

Source

pub fn new( client: SocketAddr, config: ClusterConfig, backend_id: BackendId, backend_addr: SocketAddr, now: Instant, ) -> Self

Create a flow for client on the backend admission just selected, with its idle deadline armed front_timeout from now.

The backend arrives at construction because selection happens before the flow exists: a flow is never without one.

Source

pub fn touch(&mut self, timeout: Duration, now: Instant) -> u64

Push the idle deadline back to now + timeout and advance timer_gen. The later deadline is what invalidates an in-flight wheel expiry for the old one: UdpManager::handle_timeout revalidates idle_deadline <= now before closing. Returns the new timer_gen; no caller consumes it.

Source

pub fn on_client_datagram(&mut self, now: Instant) -> u64

Record that one client datagram was actually forwarded upstream: bump the requests counter and refresh the front idle deadline. Returns the new timer_gen. Call this only at a real forward site, so requests measures datagrams that actually reached a backend. Use touch for an idle refresh that is not a forward.

Source

pub fn on_backend_datagram(&mut self, now: Instant) -> u64

Record that one backend reply was returned; refresh the back idle deadline. Returns the new timer_gen.

Source

pub fn set_phase(&mut self, next: FlowPhase)

Transition the flow to next, asserting the move is legal. One edge remains: Established → Closing, a live flow torn down. A flow is admitted Established, so there is no forward edge left, and every other transition — including a self-loop — is a bug.

The idempotent-close case does not reach here: UdpManager::close_flow returns early on a flow already Closing rather than re-setting it.

Debug-only guard — the assignment itself is unconditional so release behavior is identical.

Source

pub fn requests_exhausted(&self) -> bool

Whether the requests knob has been exhausted (0 = unlimited).

Source

pub fn responses_exhausted(&self) -> bool

Whether the responses knob has been exhausted (0 = unlimited). A DNS flow with responses = 1 closes after its single reply.

Source

pub fn teardown_reason(&self) -> Option<CloseReason>

The teardown reason if any knob is exhausted, else None. Idle is handled separately by the manager via the timer wheel.

Source

pub fn take_proxy_protocol(&mut self) -> bool

Whether this upstream datagram should carry a PPv2 DGRAM prefix, given the cluster’s first-datagram-only vs every-datagram policy. Marks the first-datagram bookkeeping as consumed.

Trait Implementations§

Source§

impl Clone for UdpFlow

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UdpFlow

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.