pub struct SniPreread<Front: SocketHandler> {
pub frontend: Front,
pub frontend_token: Token,
pub frontend_readiness: Readiness,
pub backend_readiness: Readiness,
pub backend: Option<TcpStream>,
pub backend_token: Option<Token>,
pub request_id: Ulid,
pub frontend_buffer: Checkout,
/* private fields */
}Expand description
TCP session state that owns the frontend socket and the accumulating
Checkout while SniPrereadCore decides a route. See the module doc
for the full lifecycle and the exit-accounting contract for
tcp.sni_preread.active.
Fields§
§frontend: Front§frontend_token: Token§frontend_readiness: Readiness§backend_readiness: Readiness§backend: Option<TcpStream>§backend_token: Option<Token>§request_id: Ulid§frontend_buffer: CheckoutThe session’s own frontend accumulator, growing from wire offset 0.
NEVER consume()d while undecided.
Implementations§
Source§impl<Front: SocketHandler> SniPreread<Front>
impl<Front: SocketHandler> SniPreread<Front>
Sourcepub fn new(
frontend: Front,
frontend_token: Token,
request_id: Ulid,
frontend_buffer: Checkout,
effective_max_bytes: usize,
) -> Self
pub fn new( frontend: Front, frontend_token: Token, request_id: Ulid, frontend_buffer: Checkout, effective_max_bytes: usize, ) -> Self
Instantiate a new SniPreread SessionState with:
- frontend_interest: READABLE | HUP | ERROR
- backend_interest: HUP | ERROR (WRITABLE armed once routed)
pub fn effective_max_bytes(&self) -> usize
pub fn outcome(&self) -> Option<&RoutedOutcome>
pub fn is_routed(&self) -> bool
pub fn started_at(&self) -> Instant
Sourcepub fn has_received_bytes(&self) -> bool
pub fn has_received_bytes(&self) -> bool
Bytes already accumulated from the frontend. Distinguishes a genuine
mid-preread abort (bytes were seen) from a bare TCP health-check
connect/FIN with no bytes at all (cf. expect.rs’s identical guard).
pub fn front_socket(&self) -> &TcpStream
pub fn back_socket_mut(&mut self) -> Option<&mut TcpStream>
pub fn set_back_socket(&mut self, socket: TcpStream)
pub fn set_back_token(&mut self, token: Token)
Sourcepub fn readable(
&mut self,
metrics: &mut SessionMetrics,
cfg: &PrereadConfig<'_>,
) -> SessionResult
pub fn readable( &mut self, metrics: &mut SessionMetrics, cfg: &PrereadConfig<'_>, ) -> SessionResult
Read available bytes and feed them to the core. Emits the
tcp.sni_preread.routed / tcp.sni_preread.rejected.<reason>
metrics and log lines itself; the caller (TcpSession::readable in
lib/src/tcp.rs) only needs to react to the returned
SessionResult and, on a fresh route, sync TcpSession::cluster_id
from Self::outcome.
Sourcepub fn on_timeout(&mut self, cfg: &PrereadConfig<'_>)
pub fn on_timeout(&mut self, cfg: &PrereadConfig<'_>)
Feed the preread deadline firing. Always terminal: a fired deadline
resolves to Reject(Fragmented) (or replays an already-latched
verdict in the vanishingly unlikely race where routing and the
deadline land in the same tick – the core’s decided latch makes
that safe either way).
Sourcepub fn on_front_closed(&mut self, cfg: &PrereadConfig<'_>)
pub fn on_front_closed(&mut self, cfg: &PrereadConfig<'_>)
Feed a frontend close observed before a routing decision (e.g. HUP
racing ahead of readable’s own 0-byte detection, dispatched from
TcpSession::front_hup). Mirrors readable’s
SocketResult::Closed handling: silent when no bytes were ever
received (the bare TCP health-check pattern), metered otherwise.
Sourcepub fn back_writable(&self) -> SessionResult
pub fn back_writable(&self) -> SessionResult
The back_writable dispatch point: only ever reachable once routed
– the not-yet-routed guard in
TcpSession::attempt_backend_connect_if_needed (lib/src/tcp.rs,
both call sites inside ready_inner) guarantees
connect_to_backend (and therefore any backend-writable event)
never runs before a route decision. The actual per-ProxyProtocolConfig
dispatch lives in TcpSession::upgrade_sni_preread (it needs the
TcpProxy/listener context this struct deliberately does not hold),
so this just signals the transition.