feat: merge upstream chat features with enhanced rate limiting and relay #35
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.
This PR enhances the upstream
feature/ephemeral-chatbranch with additional features for better rate limiting, local testing support, and comprehensive documentation.Key Additions
Changes from Upstream
New Files
AGENTS.mdrelay-server.jssrc/state/ratelimit.jsEnhanced Features
Technical Changes
src/config/constants.js: AddedCHAT_MIN_COOLDOWN,CHAT_BURST_LIMIT,CHAT_BURST_WINDOW,CHAT_MAX_LENGTH,CHAT_NICK_MAX_LENGTHsrc/p2p/swarm.js: AddedRELAY_PORTsupport,connectToRelay(),getAllConnections()src/p2p/messaging.js: IntegratedChatRateLimiter, signature verification for chatsrc/web/routes.js: Enhanced/api/chatwith rate limiting and nickname supportpublic/app.js: Cooldown timer UI, nickname modal, improved message displaypublic/index.html: Nickname modal, cooldown indicator elementpublic/style.css: Cooldown animation, nickname modal stylingProtocol Enhancement
CHAT Message Format
{ "type": "CHAT", "id": "<node-public-key>", "nick": "optional_nickname", "msg": "message content", "ts": 1704326400000, "hops": 0, "nonce": 12345, "sig": "<signature of 'chat:${msg}:${ts}'>" }Rate Limiting Rules
429withcooldownfield in millisecondsLocal Testing with TCP Relay
For environments where DHT discovery fails (WSL2, Docker, corporate networks):
Cooldown Timer
When rate limited, the input is disabled and shows remaining seconds:
Nickname Modal
Click
[set nick]to open modal:Test Plan
npm install && npm start— node starts without errorsENABLE_CHAT=true— chat panel visibledirectcount shows 1 (relay connection counted)Breaking Changes
None. All changes are additive and backward compatible with existing nodes.
Related PR
#20