feat(sprout-proxy): add /public read-only WebSocket endpoint#274
Open
tlongwell-block wants to merge 1 commit intomainfrom
Open
feat(sprout-proxy): add /public read-only WebSocket endpoint#274tlongwell-block wants to merge 1 commit intomainfrom
tlongwell-block wants to merge 1 commit intomainfrom
Conversation
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.
Summary
Add a
/publicread-only WebSocket endpoint tosprout-proxythat allows unauthenticated Nostr clients to subscribe to designated public channels without authentication. This enables embedding live channel feeds in websites, dashboards, and third-party tools.What it does
/publicroute — content-negotiates between NIP-11 JSON and WebSocket upgrade, just like the authenticated root handlerREQandCLOSEare accepted;EVENTmessages are rejected with["OK", <id>, false, "restricted: read-only access"]SPROUT_PROXY_PUBLIC_CHANNELS(comma-separated UUIDs) are accessible; all others are invisiblehandle_req— the public handler shares the same REQ/filter/upstream pipeline as authenticated connections, avoiding code duplicationDoS Protection (8 layers)
MAX_PUBLIC_CONNECTIONS = 100MAX_PUBLIC_SUBS_PER_CONN = 5MAX_PUBLIC_FILTERS_PER_REQ = 3MAX_PUBLIC_MSG_BYTES = 4096MAX_PUBLIC_LIMIT = 200PUBLIC_IDLE_TIMEOUT = 120sSPROUT_PROXY_PUBLIC_LIFETIME_SECS(default 3600)max_message_size+max_frame_sizeSubscription Lifecycle
The implementation tracks subscriptions with dual sets (
active_subsfor cap counting,upstream_subsfor CLOSE routing), handling all 7 lifecycle events:active_subsonlyactive_subs, sends upstream CLOSE only if inupstream_subsupstream_subsentriesBug Fixes (also applied to authenticated handler)
During 9 rounds of iterative review, 12 bugs were found and fixed:
active_subswasn't cleaned up when upstream sent CLOSED, permanently consuming a slotsend_req— subscription was tracked before the upstream send succeedednip11_responseunwrap — replaced.unwrap()with proper error handlingConfiguration
When
SPROUT_PROXY_PUBLIC_CHANNELSis empty or unset, the/publicroute is not registered at all.Files Changed
crates/sprout-proxy/src/server.rscrates/sprout-proxy/src/main.rscrates/sprout-proxy/src/upstream.rsactive_sub_ids()test helpercrates/sprout-proxy/Cargo.tomlhttp-body-util,tower)Cargo.lockTesting
Review History
9 rounds of iterative crossfire review (dual-model: GPT-5 + Claude), progressing from 7.5 → 9.5/10. Each round targeted real correctness bugs, not style nits.