| 188 | } |
| 189 | |
| 190 | void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime) |
| 191 | { |
| 192 | int nId; |
| 193 | |
| 194 | nLastGood = nTime; |
| 195 | |
| 196 | CAddrInfo* pinfo = Find(addr, &nId); |
| 197 | |
| 198 | // if not found, bail out |
| 199 | if (!pinfo) |
| 200 | return; |
| 201 | |
| 202 | CAddrInfo& info = *pinfo; |
| 203 | |
| 204 | // check whether we are talking about the exact same CService (including same port) |
| 205 | if (info != addr) |
| 206 | return; |
| 207 | |
| 208 | // update info |
| 209 | info.nLastSuccess = nTime; |
| 210 | info.nLastTry = nTime; |
| 211 | info.nAttempts = 0; |
| 212 | // nTime is not updated here, to avoid leaking information about |
| 213 | // currently-connected peers. |
| 214 | |
| 215 | // if it is already in the tried set, don't do anything else |
| 216 | if (info.fInTried) |
| 217 | return; |
| 218 | |
| 219 | // find a bucket it is in now |
| 220 | int nRnd = RandomInt(ADDRMAN_NEW_BUCKET_COUNT); |
| 221 | int nUBucket = -1; |
| 222 | for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) { |
| 223 | int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT; |
| 224 | int nBpos = info.GetBucketPosition(nKey, true, nB); |
| 225 | if (vvNew[nB][nBpos] == nId) { |
| 226 | nUBucket = nB; |
| 227 | break; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | // if no bucket is found, something bad happened; |
| 232 | // TODO: maybe re-add the node, but for now, just bail out |
| 233 | if (nUBucket == -1) |
| 234 | return; |
| 235 | |
| 236 | // which tried bucket to move the entry to |
| 237 | int tried_bucket = info.GetTriedBucket(nKey); |
| 238 | int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket); |
| 239 | |
| 240 | // Will moving this address into tried evict another entry? |
| 241 | if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) { |
| 242 | LogPrint(BCLog::ADDRMAN, "Collision inserting element into tried table, moving %s to m_tried_collisions=%d\n", addr.ToString(), m_tried_collisions.size()); |
| 243 | if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) { |
| 244 | m_tried_collisions.insert(nId); |
| 245 | } |
| 246 | } else { |
| 247 | LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString()); |
nothing calls this directly
no test coverage detected