refactor(relay): route requests through RequestMux#32
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #31 (RequestMux + HandleType). Review/merge that first; GitHub will retarget this to
draft-18once #31 lands.What
Replaces the relay session handler's hand-rolled
AcceptRequestloop + type switch with thesession.RequestMuxthe library now provides. Per-type handlers register via the genericHandleType(the typed message is handed in — no manualreq.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).OnUnknownkeeps the §3.3.2 reset-and-isolate behavior, and the session-fatalTokenCacheErrorclose moves to just afterRunreturns (same outcome as the old in-loop check).Why
Dogfoods
RequestMux/HandleTypeon 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
reqAsgeneric shim to satisfyerrcheck's type-assertion rule, which made it a wash. AddingHandleTypeto 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.spawn→wg), 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
-race(go test -race ./pkg/relay/...).go test ./...,golangci-lint run ./pkg/relay/— 0 issues.🤖 Generated with Claude Code