Skip to content

Commit

Permalink
Fix ip colocation limit
Browse files Browse the repository at this point in the history
  • Loading branch information
SionoiS committed Jan 9, 2024
1 parent d830ffb commit d523505
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions waku/node/peer_manager/peer_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -386,11 +386,12 @@ proc onPeerEvent(pm: PeerManager, peerId: PeerId, event: PeerEvent) {.async.} =
# in theory this should always be one, but just in case
let peersBehindIp = pm.ipTable[ip.get]

let idx = max((peersBehindIp.len - pm.colocationLimit), 0)
for peerId in peersBehindIp[0..<idx]:
debug "Pruning connection due to ip colocation", peerId = peerId, ip = ip
asyncSpawn(pm.switch.disconnect(peerId))
pm.peerStore.delete(peerId)
# pm.colocationLimit == 0 disables the ip colocation limit
if pm.colocationLimit != 0 and peersBehindIp.len > pm.colocationLimit:
for peerId in peersBehindIp[0..<(peersBehindIp.len - pm.colocationLimit)]:
debug "Pruning connection due to ip colocation", peerId = peerId, ip = ip
asyncSpawn(pm.switch.disconnect(peerId))
pm.peerStore.delete(peerId)
of Left:
direction = UnknownDirection
connectedness = CanConnect
Expand Down

0 comments on commit d523505

Please sign in to comment.