diff options
author | John Newbery <john@johnnewbery.com> | 2021-07-19 12:57:16 +0100 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2021-07-20 11:45:52 +0100 |
commit | 65332b1178c75e1f83415bad24918996a1524866 (patch) | |
tree | 44128681db330ad8f011763c11f702c8c0c7ea36 /src/addrman.h | |
parent | 201c5e4aec5210b258644ff96379cda0ca7273ab (diff) |
[addrman] Remove RemoveInvalid()
Instead of deserializing addresses, placing them in the buckets, and
then removing them if they're invalid, check first and don't place in
the buckets if they're invalid.
Diffstat (limited to 'src/addrman.h')
-rw-r--r-- | src/addrman.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/addrman.h b/src/addrman.h index 6f081b8dc1..e2c6d1d0d3 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -365,7 +365,8 @@ public: s >> info; int nKBucket = info.GetTriedBucket(nKey, m_asmap); int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket); - if (vvTried[nKBucket][nKBucketPos] == -1) { + if (info.IsValid() + && vvTried[nKBucket][nKBucketPos] == -1) { info.nRandomPos = vRandom.size(); info.fInTried = true; vRandom.push_back(nIdCount); @@ -419,6 +420,9 @@ public: const int entry_index{bucket_entry.second}; CAddrInfo& info = mapInfo[entry_index]; + // Don't store the entry in the new bucket if it's not a valid address for our addrman + if (!info.IsValid()) continue; + // The entry shouldn't appear in more than // ADDRMAN_NEW_BUCKETS_PER_ADDRESS. If it has already, just skip // this bucket_entry. @@ -441,7 +445,7 @@ public: } } - // Prune new entries with refcount 0 (as a result of collisions). + // Prune new entries with refcount 0 (as a result of collisions or invalid address). int nLostUnk = 0; for (auto it = mapInfo.cbegin(); it != mapInfo.cend(); ) { if (it->second.fInTried == false && it->second.nRefCount == 0) { @@ -453,11 +457,9 @@ public: } } if (nLost + nLostUnk > 0) { - LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions\n", nLostUnk, nLost); + LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions or invalid addresses\n", nLostUnk, nLost); } - RemoveInvalid(); - Check(); } @@ -770,9 +772,6 @@ private: //! Update an entry's service bits. void SetServices_(const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs); - //! Remove invalid addresses. - void RemoveInvalid() EXCLUSIVE_LOCKS_REQUIRED(cs); - friend class CAddrManTest; }; |