mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-08 10:31:50 -05:00
refactor: Use HashWriter over legacy CHashWriter
This commit is contained in:
parent
c9273f68f6
commit
5555aa2d0d
2 changed files with 13 additions and 13 deletions
|
@ -45,22 +45,22 @@ static constexpr auto ADDRMAN_TEST_WINDOW{40min};
|
||||||
|
|
||||||
int AddrInfo::GetTriedBucket(const uint256& nKey, const NetGroupManager& netgroupman) const
|
int AddrInfo::GetTriedBucket(const uint256& nKey, const NetGroupManager& netgroupman) const
|
||||||
{
|
{
|
||||||
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetCheapHash();
|
uint64_t hash1 = (HashWriter{} << nKey << GetKey()).GetCheapHash();
|
||||||
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << netgroupman.GetGroup(*this) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash();
|
uint64_t hash2 = (HashWriter{} << nKey << netgroupman.GetGroup(*this) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash();
|
||||||
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
|
return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const NetGroupManager& netgroupman) const
|
int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const NetGroupManager& netgroupman) const
|
||||||
{
|
{
|
||||||
std::vector<unsigned char> vchSourceGroupKey = netgroupman.GetGroup(src);
|
std::vector<unsigned char> vchSourceGroupKey = netgroupman.GetGroup(src);
|
||||||
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << netgroupman.GetGroup(*this) << vchSourceGroupKey).GetCheapHash();
|
uint64_t hash1 = (HashWriter{} << nKey << netgroupman.GetGroup(*this) << vchSourceGroupKey).GetCheapHash();
|
||||||
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetCheapHash();
|
uint64_t hash2 = (HashWriter{} << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetCheapHash();
|
||||||
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
|
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int bucket) const
|
int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int bucket) const
|
||||||
{
|
{
|
||||||
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << bucket << GetKey()).GetCheapHash();
|
uint64_t hash1 = (HashWriter{} << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << bucket << GetKey()).GetCheapHash();
|
||||||
return hash1 % ADDRMAN_BUCKET_SIZE;
|
return hash1 % ADDRMAN_BUCKET_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -440,8 +440,8 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy)
|
||||||
|
|
||||||
AddrInfo info1 = AddrInfo(addr1, source1);
|
AddrInfo info1 = AddrInfo(addr1, source1);
|
||||||
|
|
||||||
uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
|
uint256 nKey1 = (HashWriter{} << 1).GetHash();
|
||||||
uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
|
uint256 nKey2 = (HashWriter{} << 2).GetHash();
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN), 40);
|
BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, EMPTY_NETGROUPMAN), 40);
|
||||||
|
|
||||||
|
@ -490,8 +490,8 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy)
|
||||||
|
|
||||||
AddrInfo info1 = AddrInfo(addr1, source1);
|
AddrInfo info1 = AddrInfo(addr1, source1);
|
||||||
|
|
||||||
uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
|
uint256 nKey1 = (HashWriter{} << 1).GetHash();
|
||||||
uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
|
uint256 nKey2 = (HashWriter{} << 2).GetHash();
|
||||||
|
|
||||||
// Test: Make sure the buckets are what we expect
|
// Test: Make sure the buckets are what we expect
|
||||||
BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN), 786);
|
BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, EMPTY_NETGROUPMAN), 786);
|
||||||
|
@ -568,8 +568,8 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket)
|
||||||
|
|
||||||
AddrInfo info1 = AddrInfo(addr1, source1);
|
AddrInfo info1 = AddrInfo(addr1, source1);
|
||||||
|
|
||||||
uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
|
uint256 nKey1 = (HashWriter{} << 1).GetHash();
|
||||||
uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
|
uint256 nKey2 = (HashWriter{} << 2).GetHash();
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, ngm_asmap), 236);
|
BOOST_CHECK_EQUAL(info1.GetTriedBucket(nKey1, ngm_asmap), 236);
|
||||||
|
|
||||||
|
@ -621,8 +621,8 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket)
|
||||||
|
|
||||||
AddrInfo info1 = AddrInfo(addr1, source1);
|
AddrInfo info1 = AddrInfo(addr1, source1);
|
||||||
|
|
||||||
uint256 nKey1 = (uint256)(CHashWriter(SER_GETHASH, 0) << 1).GetHash();
|
uint256 nKey1 = (HashWriter{} << 1).GetHash();
|
||||||
uint256 nKey2 = (uint256)(CHashWriter(SER_GETHASH, 0) << 2).GetHash();
|
uint256 nKey2 = (HashWriter{} << 2).GetHash();
|
||||||
|
|
||||||
// Test: Make sure the buckets are what we expect
|
// Test: Make sure the buckets are what we expect
|
||||||
BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, ngm_asmap), 795);
|
BOOST_CHECK_EQUAL(info1.GetNewBucket(nKey1, ngm_asmap), 795);
|
||||||
|
|
Loading…
Add table
Reference in a new issue