mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
addrman: Introduce a test-only function to lookup addresses
Co-Authored-By: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
committed by
Martin Zumsande
parent
7551ae81e1
commit
dad5f76021
@@ -930,6 +930,29 @@ std::pair<CAddress, int64_t> AddrManImpl::SelectTriedCollision_()
|
||||
return {info_old, info_old.nLastTry};
|
||||
}
|
||||
|
||||
std::optional<AddressPosition> AddrManImpl::FindAddressEntry_(const CAddress& addr)
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
|
||||
AddrInfo* addr_info = Find(addr);
|
||||
|
||||
if (!addr_info) return std::nullopt;
|
||||
|
||||
if(addr_info->fInTried) {
|
||||
int bucket{addr_info->GetTriedBucket(nKey, m_asmap)};
|
||||
return AddressPosition(/*tried=*/true,
|
||||
/*multiplicity=*/1,
|
||||
/*bucket=*/bucket,
|
||||
/*position=*/addr_info->GetBucketPosition(nKey, false, bucket));
|
||||
} else {
|
||||
int bucket{addr_info->GetNewBucket(nKey, m_asmap)};
|
||||
return AddressPosition(/*tried=*/false,
|
||||
/*multiplicity=*/addr_info->nRefCount,
|
||||
/*bucket=*/bucket,
|
||||
/*position=*/addr_info->GetBucketPosition(nKey, true, bucket));
|
||||
}
|
||||
}
|
||||
|
||||
void AddrManImpl::Check() const
|
||||
{
|
||||
AssertLockHeld(cs);
|
||||
@@ -1116,6 +1139,15 @@ void AddrManImpl::SetServices(const CService& addr, ServiceFlags nServices)
|
||||
Check();
|
||||
}
|
||||
|
||||
std::optional<AddressPosition> AddrManImpl::FindAddressEntry(const CAddress& addr)
|
||||
{
|
||||
LOCK(cs);
|
||||
Check();
|
||||
auto entry = FindAddressEntry_(addr);
|
||||
Check();
|
||||
return entry;
|
||||
}
|
||||
|
||||
const std::vector<bool>& AddrManImpl::GetAsmap() const
|
||||
{
|
||||
return m_asmap;
|
||||
@@ -1201,3 +1233,8 @@ const std::vector<bool>& AddrMan::GetAsmap() const
|
||||
{
|
||||
return m_impl->GetAsmap();
|
||||
}
|
||||
|
||||
std::optional<AddressPosition> AddrMan::FindAddressEntry(const CAddress& addr)
|
||||
{
|
||||
return m_impl->FindAddressEntry(addr);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user