| 535 | } |
| 536 | |
| 537 | void CAddrMan::ResolveCollisions_() |
| 538 | { |
| 539 | for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) { |
| 540 | int id_new = *it; |
| 541 | |
| 542 | bool erase_collision = false; |
| 543 | |
| 544 | // If id_new not found in mapInfo remove it from m_tried_collisions |
| 545 | if (mapInfo.count(id_new) != 1) { |
| 546 | erase_collision = true; |
| 547 | } else { |
| 548 | CAddrInfo& info_new = mapInfo[id_new]; |
| 549 | |
| 550 | // Which tried bucket to move the entry to. |
| 551 | int tried_bucket = info_new.GetTriedBucket(nKey); |
| 552 | int tried_bucket_pos = info_new.GetBucketPosition(nKey, false, tried_bucket); |
| 553 | if (!info_new.IsValid()) { // id_new may no longer map to a valid address |
| 554 | erase_collision = true; |
| 555 | } else if (vvTried[tried_bucket][tried_bucket_pos] != -1) { // The position in the tried bucket is not empty |
| 556 | |
| 557 | // Get the to-be-evicted address that is being tested |
| 558 | int id_old = vvTried[tried_bucket][tried_bucket_pos]; |
| 559 | CAddrInfo& info_old = mapInfo[id_old]; |
| 560 | |
| 561 | // Has successfully connected in last X hours |
| 562 | if (GetAdjustedTime() - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { |
| 563 | erase_collision = true; |
| 564 | } else if (GetAdjustedTime() - info_old.nLastTry < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours |
| 565 | |
| 566 | // Give address at least 60 seconds to successfully connect |
| 567 | if (GetAdjustedTime() - info_old.nLastTry > 60) { |
| 568 | LogPrint(BCLog::ADDRMAN, "Swapping %s for %s in tried table\n", info_new.ToString(), info_old.ToString()); |
| 569 | |
| 570 | // Replaces an existing address already in the tried table with the new address |
| 571 | Good_(info_new, false, GetAdjustedTime()); |
| 572 | erase_collision = true; |
| 573 | } |
| 574 | } |
| 575 | } else { // Collision is not actually a collision anymore |
| 576 | Good_(info_new, false, GetAdjustedTime()); |
| 577 | erase_collision = true; |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | if (erase_collision) { |
| 582 | m_tried_collisions.erase(it++); |
| 583 | } else { |
| 584 | it++; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | CAddrInfo CAddrMan::SelectTriedCollision_() |
| 590 | { |
nothing calls this directly
no test coverage detected