Fix/per ip rate limiting - #64
Open
secretnamebasis wants to merge 2 commits into
Open
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.
Description
The incoming-connection rate limiter (
accept_limiter) was a single globalrate.Limiter(10/sec, burst of 40) shared across every peer. Under broad legitimate churn from many
different peers, this budget could be exhausted and starve out a single new, otherwise-good
connection attempt — one noisy or high-churn source could crowd out everyone else.
This PR adds a per-source-IP limiter (
map[string]*rate.Limiter, 1/sec sustained, burst of 5each) as the primary fairness gate on the accept path, checked before the global limiter. The
global limiter is kept as a looser ceiling behind it against a genuine multi-source flood, and
bumped to 20/sec, burst 60 to make room for the per-IP gating to do the real work. A 5-minute
ticker evicts per-IP entries idle over 15 minutes so the map doesn't grow unbounded on a
long-running node.
NOTE: The process is the following:
devbranch.dev, we will merge it totestnetfor tests, and then intomainfor final release.Fixes # (issue)
Type of change
Please select the right one.
Which part is impacted ?
Checklist:
License
I'm am contributing & releasing the code under DERO Research License (which can be found here).