MCPcopy Create free account
hub / github.com/ElementsProject/elements / MakeTried

Method MakeTried

src/addrman.cpp:487–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485}
486
487void AddrManImpl::MakeTried(AddrInfo& info, nid_type nId)
488{
489 AssertLockHeld(cs);
490
491 // remove the entry from all new buckets
492 const int start_bucket{info.GetNewBucket(nKey, m_asmap)};
493 for (int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; ++n) {
494 const int bucket{(start_bucket + n) % ADDRMAN_NEW_BUCKET_COUNT};
495 const int pos{info.GetBucketPosition(nKey, true, bucket)};
496 if (vvNew[bucket][pos] == nId) {
497 vvNew[bucket][pos] = -1;
498 info.nRefCount--;
499 if (info.nRefCount == 0) break;
500 }
501 }
502 nNew--;
503
504 assert(info.nRefCount == 0);
505
506 // which tried bucket to move the entry to
507 int nKBucket = info.GetTriedBucket(nKey, m_asmap);
508 int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket);
509
510 // first make space to add it (the existing tried entry there is moved to new, deleting whatever is there).
511 if (vvTried[nKBucket][nKBucketPos] != -1) {
512 // find an item to evict
513 nid_type nIdEvict = vvTried[nKBucket][nKBucketPos];
514 assert(mapInfo.count(nIdEvict) == 1);
515 AddrInfo& infoOld = mapInfo[nIdEvict];
516
517 // Remove the to-be-evicted item from the tried set.
518 infoOld.fInTried = false;
519 vvTried[nKBucket][nKBucketPos] = -1;
520 nTried--;
521
522 // find which new bucket it belongs to
523 int nUBucket = infoOld.GetNewBucket(nKey, m_asmap);
524 int nUBucketPos = infoOld.GetBucketPosition(nKey, true, nUBucket);
525 ClearNew(nUBucket, nUBucketPos);
526 assert(vvNew[nUBucket][nUBucketPos] == -1);
527
528 // Enter it into the new set again.
529 infoOld.nRefCount = 1;
530 vvNew[nUBucket][nUBucketPos] = nIdEvict;
531 nNew++;
532 LogPrint(BCLog::ADDRMAN, "Moved %s from tried[%i][%i] to new[%i][%i] to make space\n",
533 infoOld.ToString(), nKBucket, nKBucketPos, nUBucket, nUBucketPos);
534 }
535 assert(vvTried[nKBucket][nKBucketPos] == -1);
536
537 vvTried[nKBucket][nKBucketPos] = nId;
538 nTried++;
539 info.fInTried = true;
540}
541
542bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
543{

Callers

nothing calls this directly

Calls 5

GetBucketPositionMethod · 0.80
GetTriedBucketMethod · 0.80
countMethod · 0.80
GetNewBucketMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected