Browse Source

fix another potential infinite loop

if a.nNew == 0 -> pickFromOldBucket=true, but we don't have enough items
  (a.nOld > len(oldBucketToAddrsMap) false)
pull/3232/head
Anton Kaliaev 6 years ago
parent
commit
146540c112
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 4 additions and 4 deletions
  1. +4
    -4
      p2p/pex/addrbook.go

+ 4
- 4
p2p/pex/addrbook.go View File

@ -413,12 +413,12 @@ ADDRS_LOOP:
for selectionIndex < numAddresses { for selectionIndex < numAddresses {
// determine whether to pick from an old bucket. // determine whether to pick from an old bucket.
// if there's not enough old addresses to pick from, then we cant pick from old bucket.
pickFromOldBucket := int((float64(selectionIndex)/float64(numAddresses))*100) >= biasTowardsNewAddrs
pickFromOldBucket = (pickFromOldBucket && a.nOld > 0 && len(oldBucketToAddrsMap) < a.nOld) || a.nNew == 0
biasedTowardsOldAddrs := int((float64(selectionIndex)/float64(numAddresses))*100) >= biasTowardsNewAddrs
// if there's not enough old addresses to pick from, then we can't pick from old bucket.
pickFromOldBucket := biasedTowardsOldAddrs && a.nOld > len(oldBucketToAddrsMap)
// if there's not enough new addrs to pick from, just return early. // if there's not enough new addrs to pick from, just return early.
if !pickFromOldBucket && len(newBucketToAddrsMap) >= a.nNew {
if !pickFromOldBucket && a.nNew <= len(newBucketToAddrsMap) {
return selection return selection
} }


Loading…
Cancel
Save