|
|
@ -217,7 +217,7 @@ void CAddrMan::Good_(const CService& addr, bool test_before_evict, int64_t nTime
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// find a bucket it is in now
|
|
|
|
// find a bucket it is in now
|
|
|
|
int nRnd = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
|
|
|
|
int nRnd = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT);
|
|
|
|
int nUBucket = -1;
|
|
|
|
int nUBucket = -1;
|
|
|
|
for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
|
|
|
|
for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
|
|
|
|
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
|
|
|
|
int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
|
|
|
@ -291,7 +291,7 @@ bool CAddrMan::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTimeP
|
|
|
|
int nFactor = 1;
|
|
|
|
int nFactor = 1;
|
|
|
|
for (int n = 0; n < pinfo->nRefCount; n++)
|
|
|
|
for (int n = 0; n < pinfo->nRefCount; n++)
|
|
|
|
nFactor *= 2;
|
|
|
|
nFactor *= 2;
|
|
|
|
if (nFactor > 1 && (RandomInt(nFactor) != 0))
|
|
|
|
if (nFactor > 1 && (insecure_rand.randrange(nFactor) != 0))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
pinfo = Create(addr, source, &nId);
|
|
|
|
pinfo = Create(addr, source, &nId);
|
|
|
@ -356,12 +356,12 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|
|
|
|
|
|
|
|
|
|
|
// Use a 50% chance for choosing between tried and new table entries.
|
|
|
|
// Use a 50% chance for choosing between tried and new table entries.
|
|
|
|
if (!newOnly &&
|
|
|
|
if (!newOnly &&
|
|
|
|
(nTried > 0 && (nNew == 0 || RandomInt(2) == 0))) {
|
|
|
|
(nTried > 0 && (nNew == 0 || insecure_rand.randbool() == 0))) {
|
|
|
|
// use a tried node
|
|
|
|
// use a tried node
|
|
|
|
double fChanceFactor = 1.0;
|
|
|
|
double fChanceFactor = 1.0;
|
|
|
|
while (1) {
|
|
|
|
while (1) {
|
|
|
|
int nKBucket = RandomInt(ADDRMAN_TRIED_BUCKET_COUNT);
|
|
|
|
int nKBucket = insecure_rand.randrange(ADDRMAN_TRIED_BUCKET_COUNT);
|
|
|
|
int nKBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
|
|
|
|
int nKBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
|
|
|
|
while (vvTried[nKBucket][nKBucketPos] == -1) {
|
|
|
|
while (vvTried[nKBucket][nKBucketPos] == -1) {
|
|
|
|
nKBucket = (nKBucket + insecure_rand.randbits(ADDRMAN_TRIED_BUCKET_COUNT_LOG2)) % ADDRMAN_TRIED_BUCKET_COUNT;
|
|
|
|
nKBucket = (nKBucket + insecure_rand.randbits(ADDRMAN_TRIED_BUCKET_COUNT_LOG2)) % ADDRMAN_TRIED_BUCKET_COUNT;
|
|
|
|
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
|
|
|
nKBucketPos = (nKBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
|
|
@ -369,7 +369,7 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|
|
|
int nId = vvTried[nKBucket][nKBucketPos];
|
|
|
|
int nId = vvTried[nKBucket][nKBucketPos];
|
|
|
|
assert(mapInfo.count(nId) == 1);
|
|
|
|
assert(mapInfo.count(nId) == 1);
|
|
|
|
CAddrInfo& info = mapInfo[nId];
|
|
|
|
CAddrInfo& info = mapInfo[nId];
|
|
|
|
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
|
|
|
|
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
|
|
|
return info;
|
|
|
|
return info;
|
|
|
|
fChanceFactor *= 1.2;
|
|
|
|
fChanceFactor *= 1.2;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -377,8 +377,8 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|
|
|
// use a new node
|
|
|
|
// use a new node
|
|
|
|
double fChanceFactor = 1.0;
|
|
|
|
double fChanceFactor = 1.0;
|
|
|
|
while (1) {
|
|
|
|
while (1) {
|
|
|
|
int nUBucket = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
|
|
|
|
int nUBucket = insecure_rand.randrange(ADDRMAN_NEW_BUCKET_COUNT);
|
|
|
|
int nUBucketPos = RandomInt(ADDRMAN_BUCKET_SIZE);
|
|
|
|
int nUBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
|
|
|
|
while (vvNew[nUBucket][nUBucketPos] == -1) {
|
|
|
|
while (vvNew[nUBucket][nUBucketPos] == -1) {
|
|
|
|
nUBucket = (nUBucket + insecure_rand.randbits(ADDRMAN_NEW_BUCKET_COUNT_LOG2)) % ADDRMAN_NEW_BUCKET_COUNT;
|
|
|
|
nUBucket = (nUBucket + insecure_rand.randbits(ADDRMAN_NEW_BUCKET_COUNT_LOG2)) % ADDRMAN_NEW_BUCKET_COUNT;
|
|
|
|
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
|
|
|
nUBucketPos = (nUBucketPos + insecure_rand.randbits(ADDRMAN_BUCKET_SIZE_LOG2)) % ADDRMAN_BUCKET_SIZE;
|
|
|
@ -386,7 +386,7 @@ CAddrInfo CAddrMan::Select_(bool newOnly)
|
|
|
|
int nId = vvNew[nUBucket][nUBucketPos];
|
|
|
|
int nId = vvNew[nUBucket][nUBucketPos];
|
|
|
|
assert(mapInfo.count(nId) == 1);
|
|
|
|
assert(mapInfo.count(nId) == 1);
|
|
|
|
CAddrInfo& info = mapInfo[nId];
|
|
|
|
CAddrInfo& info = mapInfo[nId];
|
|
|
|
if (RandomInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
|
|
|
|
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30))
|
|
|
|
return info;
|
|
|
|
return info;
|
|
|
|
fChanceFactor *= 1.2;
|
|
|
|
fChanceFactor *= 1.2;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -482,7 +482,7 @@ void CAddrMan::GetAddr_(std::vector<CAddress>& vAddr)
|
|
|
|
if (vAddr.size() >= nNodes)
|
|
|
|
if (vAddr.size() >= nNodes)
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
int nRndPos = RandomInt(vRandom.size() - n) + n;
|
|
|
|
int nRndPos = insecure_rand.randrange(vRandom.size() - n) + n;
|
|
|
|
SwapRandom(n, nRndPos);
|
|
|
|
SwapRandom(n, nRndPos);
|
|
|
|
assert(mapInfo.count(vRandom[n]) == 1);
|
|
|
|
assert(mapInfo.count(vRandom[n]) == 1);
|
|
|
|
|
|
|
|
|
|
|
@ -530,10 +530,6 @@ void CAddrMan::SetServices_(const CService& addr, ServiceFlags nServices)
|
|
|
|
info.nServices = nServices;
|
|
|
|
info.nServices = nServices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CAddrMan::RandomInt(int nMax){
|
|
|
|
|
|
|
|
return GetRandInt(nMax);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CAddrMan::ResolveCollisions_()
|
|
|
|
void CAddrMan::ResolveCollisions_()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
|
|
|
|
for (std::set<int>::iterator it = m_tried_collisions.begin(); it != m_tried_collisions.end();) {
|
|
|
@ -593,7 +589,7 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
|
|
|
|
std::set<int>::iterator it = m_tried_collisions.begin();
|
|
|
|
std::set<int>::iterator it = m_tried_collisions.begin();
|
|
|
|
|
|
|
|
|
|
|
|
// Selects a random element from m_tried_collisions
|
|
|
|
// Selects a random element from m_tried_collisions
|
|
|
|
std::advance(it, GetRandInt(m_tried_collisions.size()));
|
|
|
|
std::advance(it, insecure_rand.randrange(m_tried_collisions.size()));
|
|
|
|
int id_new = *it;
|
|
|
|
int id_new = *it;
|
|
|
|
|
|
|
|
|
|
|
|
// If id_new not found in mapInfo remove it from m_tried_collisions
|
|
|
|
// If id_new not found in mapInfo remove it from m_tried_collisions
|
|
|
|