This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
Add canonical peer status logging with sampling #269
Merged
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.
These logs would normally be noisy, so we sample them. And randomly log 1 in N (N is configurable).
This means that most logs are pretty random, but patterns will emerge when there are a large number of similar events.
These logs can then be hooked up to fail2ban to automatically block abnormal peers for a bit.
Example:
A node starts a connection, sends a ping, and closes it. 100 times a second.
We log a connection established at a rate of 1 in 100 (1%).
This would log roughly once a second.
a fail2ban filter can ban a peer after 30 of these logs in a minute. (average of 50 conns/peer/second). And ban that peer for 60 minutes (not sure yet on the timing, but likely anything >10 min is good).
This solution can be applied to similar problems too. Basically anything that boils down to "this is fine/normal if it happens sparingly, but not great if it happens a ton".
Another benefit to this compared to similar solutions is that it's stateless in libp2p. Libp2p doesn't have to do anything besides maybe log a line.