diff options
| author | Pieter Wuille <[email protected]> | 2015-03-19 08:50:04 -0700 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-06-27 14:15:32 +0000 |
| commit | a56e94f913ead0097608968900381542b91b8afe (patch) | |
| tree | d5e0081d782c288a4163c43c52ed1f84b15fba58 /src/addrman.cpp | |
| parent | Make addrman's bucket placement deterministic. (diff) | |
| download | discoin-a56e94f913ead0097608968900381542b91b8afe.tar.xz discoin-a56e94f913ead0097608968900381542b91b8afe.zip | |
Simplify hashing code
Conflicts:
src/addrman.cpp
Rebased-From: a8ff7c62edc63c7c94bc91c30b80995539ed7477
Github-Pull: #5941
Diffstat (limited to 'src/addrman.cpp')
| -rw-r--r-- | src/addrman.cpp | 26 |
1 files changed, 5 insertions, 21 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp index e8c8a4e38..ffaf1c8c2 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -11,38 +11,22 @@ using namespace std; int CAddrInfo::GetTriedBucket(const uint256& nKey) const { - CDataStream ss1(SER_GETHASH, 0); - std::vector<unsigned char> vchKey = GetKey(); - ss1 << nKey << vchKey; - uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64(); - - CDataStream ss2(SER_GETHASH, 0); - std::vector<unsigned char> vchGroupKey = GetGroup(); - ss2 << nKey << vchGroupKey << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP); - uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetHash().GetLow64(); + uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetHash().GetLow64(); return hash2 % ADDRMAN_TRIED_BUCKET_COUNT; } int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src) const { - CDataStream ss1(SER_GETHASH, 0); - std::vector<unsigned char> vchGroupKey = GetGroup(); std::vector<unsigned char> vchSourceGroupKey = src.GetGroup(); - ss1 << nKey << vchGroupKey << vchSourceGroupKey; - uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64(); - - CDataStream ss2(SER_GETHASH, 0); - ss2 << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP); - uint64_t hash2 = Hash(ss2.begin(), ss2.end()).GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetLow64(); + uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetLow64(); return hash2 % ADDRMAN_NEW_BUCKET_COUNT; } int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const { - CDataStream ss1(SER_GETHASH, 0); - std::vector<unsigned char> vchKey = GetKey(); - ss1 << nKey << (fNew ? 'N' : 'K') << nBucket << vchKey; - uint64_t hash1 = Hash(ss1.begin(), ss1.end()).GetLow64(); + uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? 'N' : 'K') << nBucket << GetKey()).GetHash().GetLow64(); return hash1 % ADDRMAN_BUCKET_SIZE; } |