Skip to content

WIP: Add adaptive advert flood rate limiter#2545

Draft
ViezeVingertjes wants to merge 1 commit into
meshcore-dev:devfrom
ViezeVingertjes:advert-flood-protection
Draft

WIP: Add adaptive advert flood rate limiter#2545
ViezeVingertjes wants to merge 1 commit into
meshcore-dev:devfrom
ViezeVingertjes:advert-flood-protection

Conversation

@ViezeVingertjes
Copy link
Copy Markdown
Contributor

Adds an adaptive rate limiter on advert forwarding so one node cannot flood the mesh with bogus or abusive adverts. Bursts are still allowed when traffic is normal; the cap tightens when someone tries to hammer fake adverts.

That max rises and falls with recent traffic so normal use still gets through, but floods hit the cap fast and the rest is dropped until the next window.

Kept CLI changes minimal, on by default for happy neighbors.
get advert.ratelimit
set advert.ratelimit {on/off}

Context:
Most (intentional) abuse we had so far was spamming fake adverts, as it's one of the easiest things one (claude) can make apparantly. I tried to keep it as small/simple as possible, while still putting a brake on it, so it doesnt flood further into the mesh.

The EWMA config could be added to CLI perhaps as future improvement, with perhaps some kind of stats/status command, but left that out of scope for now.

Copy link
Copy Markdown

@4np 4np left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating this :) I understand you want to keep a minimal footprint to alleviate some of the issues we're seeing with bad actors, but I wonder if it would be better to be able to detect bad actors and penalize them by silencing them with an increasing amount of time? Sometimes people genuinely send a message split in multiple packets, which can occasionally be more than 3, whereas bad actors can still flood the mesh by sending 3 messages and then staying silent for 5 mins.

};

class AdaptiveRateLimiter {
enum {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding some documentation explaining the approach uses Exponentially Weighted Moving Average (EWMA). It might be good to have unit tests for this class to verify its behavior.

Copy link
Copy Markdown
Contributor Author

@ViezeVingertjes ViezeVingertjes May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests

We do unit tests these days?! haha.
No, all jokes aside, that should be easy to add in this case so will definetely do.

}

public:
AdaptiveRateLimiter(uint16_t secs, uint8_t burst, uint8_t floor)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding some in-line documentation explaining what these arguments mean.

@ViezeVingertjes ViezeVingertjes changed the title Add adaptive advert flood rate limiter WIP: Add adaptive advert flood rate limiter May 13, 2026
@ViezeVingertjes
Copy link
Copy Markdown
Contributor Author

ViezeVingertjes commented May 13, 2026

I understand you want to keep a minimal footprint to alleviate some of the issues we're seeing with bad actors

Correct, the attack is on-going so we needed something quick and simple. 💯

but I wonder if it would be better to be able to detect bad actors and penalize them by silencing them with an increasing amount of time?

I think it depends on the attack, what they seem to prefer so far is just generating random keys/names and flood-adverting those to annoy people with auto-add and generate some congestion on the mesh.

Sometimes people genuinely send a message split in multiple packets, which can occasionally be more than 3

Very true, this rate limit only apply to PAYLOAD_TYPE_ADVERT though as that is the challenge on hand, it did cross my mind for a second to look at other packets, but my first thought would be, that it would be to easy to abuse it for DoS and left it at that for now. So far they dont seem to spam channels (yet) fingers crossed.

Thanks for the review!
Will polish it once it has proven itself in the mesh for a bit. 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants