Module subscription_wire
Expand description
What every subscription session binding shares
(docs/design/subscriptions-websocket.md §6.3, §6.4, §6.6): the frames,
admission (Init, authentication, refusal close codes), which browser
origins may open a session, the per-principal session count, and the
rate-limit seam that charges each subscription open.
WebTransport (cratestack-webtransport) and WebSocket
(cratestack-websocket) only move these frames over their own
transport.
Modules§
- admission
- Admitting a subscription session, whatever carries it
(
docs/design/subscriptions-websocket.md§6.3): the first frame must beInit, its headers stand in for the handshake’s when present, and a refusal’s close code follows the error’s status. - frame
- The frames a WebTransport subscription session carries
(
docs/design/subscriptions-websocket.md§6.4, §6a.2). - origin
- Which browser origins may open a session (design §6.3, “Origin”).
- principal
- Who a session belongs to: the key re-authentication must preserve (design §6.3, “Expiry and refresh”) and the key sessions are counted under (§6.6, “Sockets per principal”).
- rate_
limit - Rate-limiting subscription opens on the session bindings
(
docs/design/subscriptions-websocket.md§6.7): the seam WebSocket and WebTransport call, implemented bycratestack-axum’sSubscriptionRateLimiteroverOpExecutor::admit_rate_limit. One token per subscriptionRequest; the session itself is not charged.
Structs§
- Client
Frame - Anything a client sends.
- Empty
- An empty object (
{}), the payload ofreadyandend. - Handshake
- What the handshake (WebTransport CONNECT, WebSocket upgrade) carried that authentication needs later.
- Init
Body Initbody: the credentials a browser cannot put on the CONNECT request. Empty for a client that authenticated with CONNECT headers.- Server
Frame - Anything the server sends. Exactly one of the optional fields is set.
- Session
Charger - One session’s standing answer to “who pays”: built once per session and cloned into every subscription task. With no limiter it admits everything.
- Session
Registry - Open sessions per key, shared by every session of one server. A poisoned lock is recovered rather than propagated: the guarded state is a counter no panic can leave half-updated, and propagating would turn one panicked task into a refusal of every later session.
- Session
Slot - One admitted session. Dropping it frees the slot, however the session ended.
- Subscription
Charge - What a binding knows about one subscription open.
Enums§
- Client
Message - A client frame, classified.
- Origin
Policy - Which
Origins are accepted. - Subscription
Refusal - Why an open was refused before
Ready.
Traits§
- Subscription
Rate Limit - Charges one subscription open.
Debugso binding configs keep deriving it.
Functions§
- authenticate_
session - Runs the app’s
AuthProviderover the handshake request.Initheaders, when present, stand in for the handshake’s: that is how a browser, which cannot set headers onnew WebTransport(url)ornew WebSocket(url), presents credentials. A native client sends them on the handshake and an emptyInit. - default_
principal_ key - The default principal key (
PrincipalKeyFnin a binding config): the principal’sactor.id, else the auth identity’sid, else itssub. A context with none of them is anonymous. - init_
headers - The first frame must be
Init: its headers, elseNone. - refusal_
close_ code - The close code a refusal ends the session with, from the error’s HTTP
status: 401 → 4401 and 403 → 4403, as on REST; a malformed
Init→ 4400; and a provider that could not decide (5xx: a key server down) → 4500, which is not a verdict on the credentials — a client must retry later rather than sign the user out. - session_
key - What a session is counted under: the principal, or the remote IP for an anonymous caller, so one address cannot hold unlimited anonymous sessions either.