Beispiel #1
0
int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src) const
{
    std::vector<unsigned char> vchSourceGroupKey = src.GetGroup();
    uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup() << vchSourceGroupKey).GetHash().GetCheapHash();
    uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << vchSourceGroupKey << (hash1 % ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP)).GetHash().GetCheapHash();
    return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
}
int CAddrInfo::GetTriedBucket(const uint256 &nKey) const {
    uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey())
                         .GetHash()
                         .GetCheapHash();
    uint64_t hash2 =
        (CHashWriter(SER_GETHASH, 0)
         << nKey << GetGroup() << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP))
            .GetHash()
            .GetCheapHash();
    return hash2 % ADDRMAN_TRIED_BUCKET_COUNT;
}
int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew,
                                 int nBucket) const {
    uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? 'N' : 'K')
                                                  << nBucket << GetKey())
                         .GetHash()
                         .GetCheapHash();
    return hash1 % ADDRMAN_BUCKET_SIZE;
}
 int RandomInt(int nMax) {
     state = (CHashWriter(SER_GETHASH, 0) << state).GetHash().GetCheapHash();
     return (unsigned int)(state % nMax);
 }