Skip to content

refactor(relay): route requests through RequestMux#32

Merged
floatdrop merged 1 commit into
feat/request-muxfrom
refactor/relay-requestmux
Jun 28, 2026
Merged

refactor(relay): route requests through RequestMux#32
floatdrop merged 1 commit into
feat/request-muxfrom
refactor/relay-requestmux

Conversation

@floatdrop

Copy link
Copy Markdown
Owner

Stacked on #31 (RequestMux + HandleType). Review/merge that first; GitHub will retarget this to draft-18 once #31 lands.

What

Replaces the relay session handler's hand-rolled AcceptRequest loop + type switch with the session.RequestMux the library now provides. Per-type handlers register via the generic HandleType (the typed message is handed in — no manual req.First.(*message.X) assertion), and the two cross-cutting policies become small shared helpers:

  • verifyRequest — §10.2.2 token verification + the per-request dispatch log, shared by every known type.
  • namespaceRequest — §13.7.1 per-session cap, collapsing the three previously-duplicated namespace-state cases (PublishNamespace / SubscribeNamespace / SubscribeTracks).

OnUnknown keeps the §3.3.2 reset-and-isolate behavior, and the session-fatal TokenCacheError close moves to just after Run returns (same outcome as the old in-loop check).

Why

Dogfoods RequestMux/HandleType on the relay's real, policy-heavy dispatch path — the strongest confidence signal that the new API holds up beyond toy servers. Also removes the namespace-case triplication.

We prototyped this first and compared honestly: an earlier version needed a reqAs generic shim to satisfy errcheck's type-assertion rule, which made it a wash. Adding HandleType to the mux (in #31) removed that wart, so the migration is now clean. It's ~16 lines longer than the switch (the token-verify guard is explicit per handler instead of once before a switch), accepted as the cost of self-contained per-type handlers + dogfooding.

Behavior

No change. Routing, auth, per-type limiting, goroutine lifecycle (h.spawnwg), unknown-type reset, and token-cache session close are all preserved. One nuance: unknown-type requests are no longer token-verified before reset (the verify pre-step is now per-handled-type), which is consistent with "verify only applies to handled types."

Testing

  • All existing relay tests pass unchanged under -race (go test -race ./pkg/relay/...).
  • Full go test ./..., golangci-lint run ./pkg/relay/ — 0 issues.

🤖 Generated with Claude Code

Replace the bespoke AcceptRequest loop + type switch in the session
handler with the session.RequestMux it now has available. Per-type
handlers register via the generic HandleType (typed message handed in, no
manual assertion); the two cross-cutting policies become small shared
helpers — verifyRequest (§10.2.2 token verification + dispatch log) and
namespaceRequest (§13.7.1 cap), the latter collapsing the three repeated
namespace-state cases. OnUnknown keeps the §3.3.2 reset-and-isolate
behavior; the token-cache session-fatal close moves just after Run returns.

Dogfoods RequestMux on the relay's policy-heavy dispatch path. No behavior
change; all relay tests pass unchanged under -race.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@floatdrop floatdrop merged commit ba3aa6a into feat/request-mux Jun 28, 2026
9 checks passed
floatdrop added a commit that referenced this pull request Jun 28, 2026
Replace the bespoke AcceptRequest loop + type switch in the session
handler with the session.RequestMux it now has available. Per-type
handlers register via the generic HandleType (typed message handed in, no
manual assertion); the two cross-cutting policies become small shared
helpers — verifyRequest (§10.2.2 token verification + dispatch log) and
namespaceRequest (§13.7.1 cap), the latter collapsing the three repeated
namespace-state cases. OnUnknown keeps the §3.3.2 reset-and-isolate
behavior; the token-cache session-fatal close moves just after Run returns.

Dogfoods RequestMux on the relay's policy-heavy dispatch path. No behavior
change; all relay tests pass unchanged under -race.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant