| 605 | } |
| 606 | |
| 607 | bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, NodeSeconds time) |
| 608 | { |
| 609 | AssertLockHeld(cs); |
| 610 | |
| 611 | nid_type nId; |
| 612 | |
| 613 | m_last_good = time; |
| 614 | |
| 615 | AddrInfo* pinfo = Find(addr, &nId); |
| 616 | |
| 617 | // if not found, bail out |
| 618 | if (!pinfo) return false; |
| 619 | |
| 620 | AddrInfo& info = *pinfo; |
| 621 | |
| 622 | // update info |
| 623 | info.m_last_success = time; |
| 624 | info.m_last_try = time; |
| 625 | info.nAttempts = 0; |
| 626 | // nTime is not updated here, to avoid leaking information about |
| 627 | // currently-connected peers. |
| 628 | |
| 629 | // if it is already in the tried set, don't do anything else |
| 630 | if (info.fInTried) return false; |
| 631 | |
| 632 | // if it is not in new, something bad happened |
| 633 | if (!Assume(info.nRefCount > 0)) return false; |
| 634 | |
| 635 | |
| 636 | // which tried bucket to move the entry to |
| 637 | int tried_bucket = info.GetTriedBucket(nKey, m_netgroupman); |
| 638 | int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket); |
| 639 | |
| 640 | // Will moving this address into tried evict another entry? |
| 641 | if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) { |
| 642 | if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) { |
| 643 | m_tried_collisions.insert(nId); |
| 644 | } |
| 645 | // Output the entry we'd be colliding with, for debugging purposes |
| 646 | auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]); |
| 647 | LogDebug(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d", |
| 648 | colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "<unknown-addr>", |
| 649 | addr.ToStringAddrPort(), |
| 650 | m_tried_collisions.size()); |
| 651 | return false; |
| 652 | } else { |
| 653 | // move nId to the tried tables |
| 654 | MakeTried(info, nId); |
| 655 | const auto mapped_as{m_netgroupman.GetMappedAS(addr)}; |
| 656 | LogDebug(BCLog::ADDRMAN, "Moved %s%s to tried[%i][%i]\n", |
| 657 | addr.ToStringAddrPort(), (mapped_as ? strprintf(" mapped to AS%i", mapped_as) : ""), tried_bucket, tried_bucket_pos); |
| 658 | return true; |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | bool AddrManImpl::Add_(const std::vector<CAddress>& vAddr, const CNetAddr& source, std::chrono::seconds time_penalty) |
| 663 | { |
nothing calls this directly
no test coverage detected