| 1042 | } |
| 1043 | |
| 1044 | int AddrManImpl::CheckAddrman() const |
| 1045 | { |
| 1046 | AssertLockHeld(cs); |
| 1047 | |
| 1048 | LOG_TIME_MILLIS_WITH_CATEGORY_MSG_ONCE( |
| 1049 | strprintf("new %i, tried %i, total %u", nNew, nTried, vRandom.size()), BCLog::ADDRMAN); |
| 1050 | |
| 1051 | std::unordered_set<nid_type> setTried; |
| 1052 | std::unordered_map<nid_type, int> mapNew; |
| 1053 | std::unordered_map<Network, NewTriedCount> local_counts; |
| 1054 | |
| 1055 | if (vRandom.size() != (size_t)(nTried + nNew)) |
| 1056 | return -7; |
| 1057 | |
| 1058 | for (const auto& entry : mapInfo) { |
| 1059 | nid_type n = entry.first; |
| 1060 | const AddrInfo& info = entry.second; |
| 1061 | if (info.fInTried) { |
| 1062 | if (!TicksSinceEpoch<std::chrono::seconds>(info.m_last_success)) { |
| 1063 | return -1; |
| 1064 | } |
| 1065 | if (info.nRefCount) |
| 1066 | return -2; |
| 1067 | setTried.insert(n); |
| 1068 | local_counts[info.GetNetwork()].n_tried++; |
| 1069 | } else { |
| 1070 | if (info.nRefCount < 0 || info.nRefCount > ADDRMAN_NEW_BUCKETS_PER_ADDRESS) |
| 1071 | return -3; |
| 1072 | if (!info.nRefCount) |
| 1073 | return -4; |
| 1074 | mapNew[n] = info.nRefCount; |
| 1075 | local_counts[info.GetNetwork()].n_new++; |
| 1076 | } |
| 1077 | const auto it{mapAddr.find(info)}; |
| 1078 | if (it == mapAddr.end() || it->second != n) { |
| 1079 | return -5; |
| 1080 | } |
| 1081 | if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n) |
| 1082 | return -14; |
| 1083 | if (info.m_last_try < NodeSeconds{0s}) { |
| 1084 | return -6; |
| 1085 | } |
| 1086 | if (info.m_last_success < NodeSeconds{0s}) { |
| 1087 | return -8; |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | if (setTried.size() != (size_t)nTried) |
| 1092 | return -9; |
| 1093 | if (mapNew.size() != (size_t)nNew) |
| 1094 | return -10; |
| 1095 | |
| 1096 | for (int n = 0; n < ADDRMAN_TRIED_BUCKET_COUNT; n++) { |
| 1097 | for (int i = 0; i < ADDRMAN_BUCKET_SIZE; i++) { |
| 1098 | if (vvTried[n][i] != -1) { |
| 1099 | if (!setTried.contains(vvTried[n][i])) |
| 1100 | return -11; |
| 1101 | const auto it{mapInfo.find(vvTried[n][i])}; |
nothing calls this directly
no test coverage detected