accessman: skip incrementing num of slots for existing peer
When a peer is already existing, we should skip incrementing the `numRestricted` count. Also patched unit test for method `addPeerAccess`.
This commit is contained in:
2 files changed
+164
No files matched your search
@@ -559,10 +559,23 @@ func (a *accessMan) addPeerAccess(remotePub *btcec.PublicKey,
|
||||
|
||||
peerMapKey := string(remotePub.SerializeCompressed())
|
||||
|
||||
// Exit early if this is an existing peer, which means it won't take
|
||||
// another slot.
|
||||
_, found := a.peerScores[peerMapKey]
|
||||
if found {
|
||||
acsmLog.DebugS(ctx, "Skipped taking restricted slot for "+
|
||||
"existing peer")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
a.peerScores[peerMapKey] = peerSlotStatus{state: access}
|
||||
|
||||
// Exit early if this is not a restricted peer.
|
||||
if access != peerStatusRestricted {
|
||||
acsmLog.DebugS(ctx, "Skipped taking restricted slot as peer "+
|
||||
"already has access", "access", access)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user