Repository navigation
fix(tracker): limit segment reports per peer across REST and WebSocket - #139
Merged
Merged
Conversation
Inventory reports are relayed as received to each of the reporter's neighbors (64 by default), and the only limits were 64 KiB frames and 20 messages per second, so one connection could make the tracker relay over a megabyte per second to every neighbor. Each connection now also has a token bucket of segment-ID characters: 16 K per second, bursts of 256 K for a full re-report after reconnecting. Over it, the connection is closed with 1008. Clients report a few IDs per segment, far below this. API_REFERENCE now lists the WebSocket limits.
# Conflicts: # CHANGELOG.md
The REST segment report accepted any number of IDs of any length (up to the 1 MB body) and relayed them to WebSocket subscribers, bypassing both the WebSocket report limits and the new rate limit. Segment ID validation and an InventoryRateLimiter keyed by broadcast and peer now live in inventory-limits.ts; TrackerServer passes one limiter to the REST handler and the WebSocket hub, so a peer's reports count once whichever interface it uses. Over the rate, REST answers 429 and the WebSocket is closed with 1008.
Owner
Author
|
Self-review:
|
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.
Problem
Inventory reports are relayed as received to the reporter's neighbors (64 by default), or to every subscriber for legacy clients. Two gaps:
POST /api/v1/broadcasts/:id/peers/:peerId/segmentsaccepted any number of IDs of any length, up to the 1 MB body limit, and relayed them to WebSocket subscribers. That bypassed even the WebSocket per-report limits.#138 bounds what the store keeps, but not what is relayed.
Change
tracker/src/inventory-limits.ts:segmentIdList: at most 512 IDs, each 1 to 512 characters. The WebSocket hub already enforced this; REST now does too.InventoryRateLimiter: a token bucket of segment-ID characters per broadcast peer, 16 K/s sustained with bursts of 256 K. The burst fits a full re-report after a reconnect. Idle buckets are swept.TrackerServercreates one limiter and passes it to the REST handler and the WebSocket hub, so a peer's budget is shared across both interfaces.1008("Segment report rate limit exceeded") and REST answers429.Tests
segmentIdListand forInventoryRateLimiter: burst, refill, cap, per-peer isolation, and no charge on refusal.1008.