-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Discv5 ip limits for routing table (#308)
* Add ip limits to routing table and routing table buckets * Fix order of ip limit check and duplicate check for replacement * Fix ip limit for node with updated ip in ENR * Fix bug where address wouldn't update on ENR update and update some comments * Reuse some add/remove code in routing table * Fix seen bug on ENR update in routing table * Rework addNode to make sure to do address check always and adjust some logs. * More documentation on the ip limits in routing table [skip ci]
- Loading branch information
Showing
7 changed files
with
607 additions
and
148 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import | ||
std/[tables, hashes], | ||
stew/shims/net as stewNet | ||
|
||
{.push raises: [Defect].} | ||
|
||
type | ||
IpLimits* = object | ||
limit*: uint | ||
ips: Table[ValidIpAddress, uint] | ||
|
||
proc hash(ip: ValidIpAddress): Hash = hash($ip) | ||
|
||
proc inc*(ipLimits: var IpLimits, ip: ValidIpAddress): bool = | ||
let val = ipLimits.ips.getOrDefault(ip, 0) | ||
if val < ipLimits.limit: | ||
ipLimits.ips[ip] = val + 1 | ||
true | ||
else: | ||
false | ||
|
||
proc dec*(ipLimits: var IpLimits, ip: ValidIpAddress) = | ||
let val = ipLimits.ips.getOrDefault(ip, 0) | ||
if val == 1: | ||
ipLimits.ips.del(ip) | ||
elif val > 1: | ||
ipLimits.ips[ip] = val - 1 |
This file contains 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
This file contains 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
Oops, something went wrong.