| 969 | } |
| 970 | |
| 971 | int AddrManImpl::CheckAddrman() const |
| 972 | { |
| 973 | AssertLockHeld(cs); |
| 974 | |
| 975 | LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE( |
| 976 | strprintf("new %i, tried %i, total %u", nNew, nTried, vRandom.size()), BCLog::ADDRMAN); |
| 977 | |
| 978 | std::unordered_set<nid_type> setTried; |
| 979 | std::unordered_map<nid_type, int> mapNew; |
| 980 | |
| 981 | if (vRandom.size() != (size_t)(nTried + nNew)) |
| 982 | return -7; |
| 983 | |
| 984 | for (const auto& entry : mapInfo) { |
| 985 | nid_type n = entry.first; |
| 986 | const AddrInfo& info = entry.second; |
| 987 | if (info.fInTried) { |
| 988 | if (!info.nLastSuccess) |
| 989 | return -1; |
| 990 | if (info.nRefCount) |
| 991 | return -2; |
| 992 | setTried.insert(n); |
| 993 | } else { |
| 994 | if (info.nRefCount < 0 || info.nRefCount > ADDRMAN_NEW_BUCKETS_PER_ADDRESS) |
| 995 | return -3; |
| 996 | if (!info.nRefCount) |
| 997 | return -4; |
| 998 | mapNew[n] = info.nRefCount; |
| 999 | } |
| 1000 | const auto it{mapAddr.find(info)}; |
| 1001 | if (it == mapAddr.end() || it->second != n) { |
| 1002 | return -5; |
| 1003 | } |
| 1004 | if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n) |
| 1005 | return -14; |
| 1006 | if (info.nLastTry < 0) |
| 1007 | return -6; |
| 1008 | if (info.nLastSuccess < 0) |
| 1009 | return -8; |
| 1010 | } |
| 1011 | |
| 1012 | if (setTried.size() != (size_t)nTried) |
| 1013 | return -9; |
| 1014 | if (mapNew.size() != (size_t)nNew) |
| 1015 | return -10; |
| 1016 | |
| 1017 | for (int n = 0; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) { |
| 1018 | for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) { |
| 1019 | if (vvTried[n][i] != -1) { |
| 1020 | if (!setTried.count(vvTried[n][i])) |
| 1021 | return -11; |
| 1022 | const auto it{mapInfo.find(vvTried[n][i])}; |
| 1023 | if (it == mapInfo.end() || it->second.GetTriedBucket(nKey, m_asmap) != n) { |
| 1024 | return -17; |
| 1025 | } |
| 1026 | if (it->second.GetBucketPosition(nKey, false, n) != i) { |
| 1027 | return -18; |
| 1028 | } |
nothing calls this directly
no test coverage detected