MCPcopy Create free account
hub / github.com/LUX-Core/lux / Select_

Method Select_

src/addrman.cpp:329–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327}
328
329CAddress CAddrMan::Select_()
330{
331 if (size() == 0)
332 return CAddress();
333
334 // Use a 50% chance for choosing between tried and new table entries.
335 if (nTried > 0 && (nNew == 0 || GetRandInt(2) == 0)) {
336 // use a tried node
337 double fChanceFactor = 1.0;
338 while (1) {
339 int nKBucket = GetRandInt(ADDRMAN_TRIED_BUCKET_COUNT);
340 int nKBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
341 if (vvTried[nKBucket][nKBucketPos] == -1)
342 continue;
343 int nId = vvTried[nKBucket][nKBucketPos];
344 assert(mapInfo.count(nId) == 1);
345 CAddrInfo& info = mapInfo[nId];
346 if (GetRandInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
347 return info;
348 fChanceFactor *= 1.2;
349 }
350 } else {
351 // use a new node
352 double fChanceFactor = 1.0;
353 while (1) {
354 int nUBucket = GetRandInt(ADDRMAN_NEW_BUCKET_COUNT);
355 int nUBucketPos = GetRandInt(ADDRMAN_BUCKET_SIZE);
356 if (vvNew[nUBucket][nUBucketPos] == -1)
357 continue;
358 int nId = vvNew[nUBucket][nUBucketPos];
359 assert(mapInfo.count(nId) == 1);
360 CAddrInfo& info = mapInfo[nId];
361 if (GetRandInt(1 << 30) < fChanceFactor * info.GetChance() * (1 << 30))
362 return info;
363 fChanceFactor *= 1.2;
364 }
365 }
366}
367
368#ifdef DEBUG_ADDRMAN
369int CAddrMan::Check_()

Callers

nothing calls this directly

Calls 5

sizeFunction · 0.85
GetRandIntFunction · 0.85
GetChanceMethod · 0.80
CAddressClass · 0.70
countMethod · 0.45

Tested by

no test coverage detected