diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-06-07 12:45:35 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2021-06-07 14:42:11 +0200 |
commit | 00b875ba9414463d0041da6924fd9b54d6a06dee (patch) | |
tree | 76c98674e9d4881ef66da84d107aa05dd1a9f7c1 /src/addrman.cpp | |
parent | bdb62096f0109b2ec76849d33d6cf7187dea299f (diff) | |
download | bitcoin-00b875ba9414463d0041da6924fd9b54d6a06dee.tar.xz |
addrman: remove invalid addresses when unserializing
The Tor v2 addresses, left over from when Tor v2 was supported will be
unserialized as a dummy, invalid `::` (all zeros) IPv6 address. Remove
them so that they do not take up space in addrman.
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r-- | src/addrman.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index 14b412a038..24531e8a6f 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -75,6 +75,38 @@ double CAddrInfo::GetChance(int64_t nNow) const return fChance; } +void CAddrMan::RemoveInvalid() +{ + for (size_t bucket = 0; bucket < ADDRMAN_NEW_BUCKET_COUNT; ++bucket) { + for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) { + const auto id = vvNew[bucket][i]; + if (id != -1 && !mapInfo[id].IsValid()) { + ClearNew(bucket, i); + } + } + } + + for (size_t bucket = 0; bucket < ADDRMAN_TRIED_BUCKET_COUNT; ++bucket) { + for (size_t i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) { + const auto id = vvTried[bucket][i]; + if (id == -1) { + continue; + } + const auto& addr_info = mapInfo[id]; + if (addr_info.IsValid()) { + continue; + } + vvTried[bucket][i] = -1; + --nTried; + SwapRandom(addr_info.nRandomPos, vRandom.size() - 1); + vRandom.pop_back(); + mapAddr.erase(addr_info); + mapInfo.erase(id); + m_tried_collisions.erase(id); + } + } +} + CAddrInfo* CAddrMan::Find(const CNetAddr& addr, int* pnId) { std::map<CNetAddr, int>::iterator it = mapAddr.find(addr); |