aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorAmiti Uttarwar <amiti@uttarwar.org>2023-02-19 10:09:28 -0700
committerAmiti Uttarwar <amiti@uttarwar.org>2023-03-17 17:59:02 -0700
commit26c3bf11e2487ed0ac578fb92619c148336003cb (patch)
tree9e54581d78cc858038a43e9218e5dbf347fa7b4e /src/addrman.cpp
parent48806412e2bcd023b78fc05f6c9ce092360d1db1 (diff)
downloadbitcoin-26c3bf11e2487ed0ac578fb92619c148336003cb.tar.xz
scripted-diff: rename local variables to match modern conventions
-BEGIN VERIFY SCRIPT- sed -i 's/fChanceFactor/chance_factor/g' src/addrman.cpp sed -i 's/nBucketPos/initial_position/g' src/addrman.cpp sed -i 's/nBucket/bucket/g' src/addrman.cpp src/addrman_impl.h sed -i 's/newOnly/new_only/g' src/addrman.cpp src/addrman_impl.h src/addrman.h src/test/addrman_tests.cpp -END VERIFY SCRIPT- Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index 69ad13a912..fe4a79b2e6 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -58,9 +58,9 @@ int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const NetGr
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
}
-int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) const
+int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int bucket) const
{
- uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
+ uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << bucket << GetKey()).GetCheapHash();
return hash1 % ADDRMAN_BUCKET_SIZE;
}
@@ -714,19 +714,19 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, NodeSeconds
}
}
-std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
+std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only) const
{
AssertLockHeld(cs);
if (vRandom.empty()) return {};
- if (newOnly && nNew == 0) return {};
+ if (new_only && nNew == 0) return {};
// Decide if we are going to search the new or tried table
bool search_tried;
int bucket_count;
// Use a 50% chance for choosing between tried and new table entries.
- if (!newOnly &&
+ if (!new_only &&
(nTried > 0 &&
(nNew == 0 || insecure_rand.randbool() == 0))) {
search_tried = true;
@@ -736,18 +736,18 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
bucket_count = ADDRMAN_NEW_BUCKET_COUNT;
}
- double fChanceFactor = 1.0;
+ double chance_factor = 1.0;
while (1) {
// Pick a bucket, and an initial position in that bucket.
- int nBucket = insecure_rand.randrange(bucket_count);
- int nBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
+ int bucket = insecure_rand.randrange(bucket_count);
+ int initial_position = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
// Iterate over the positions of that bucket, starting at the initial one,
// and looping around.
int i;
for (i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
- int position = (nBucketPos + i) % ADDRMAN_BUCKET_SIZE;
- int node_id = GetEntry(search_tried, nBucket, position);
+ int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
+ int node_id = GetEntry(search_tried, bucket, position);
if (node_id != -1) break;
}
@@ -755,20 +755,20 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
if (i == ADDRMAN_BUCKET_SIZE) continue;
// Find the entry to return.
- int position = (nBucketPos + i) % ADDRMAN_BUCKET_SIZE;
- int nId = GetEntry(search_tried, nBucket, position);
+ int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
+ int nId = GetEntry(search_tried, bucket, position);
const auto it_found{mapInfo.find(nId)};
assert(it_found != mapInfo.end());
const AddrInfo& info{it_found->second};
- // With probability GetChance() * fChanceFactor, return the entry.
- if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
+ // With probability GetChance() * chance_factor, return the entry.
+ if (insecure_rand.randbits(30) < chance_factor * info.GetChance() * (1 << 30)) {
LogPrint(BCLog::ADDRMAN, "Selected %s from %s\n", info.ToStringAddrPort(), search_tried ? "tried" : "new");
return {info, info.m_last_try};
}
// Otherwise start over with a (likely) different bucket, and increased chance factor.
- fChanceFactor *= 1.2;
+ chance_factor *= 1.2;
}
}
@@ -1168,11 +1168,11 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::SelectTriedCollision()
return ret;
}
-std::pair<CAddress, NodeSeconds> AddrManImpl::Select(bool newOnly) const
+std::pair<CAddress, NodeSeconds> AddrManImpl::Select(bool new_only) const
{
LOCK(cs);
Check();
- auto addrRet = Select_(newOnly);
+ auto addrRet = Select_(new_only);
Check();
return addrRet;
}
@@ -1266,9 +1266,9 @@ std::pair<CAddress, NodeSeconds> AddrMan::SelectTriedCollision()
return m_impl->SelectTriedCollision();
}
-std::pair<CAddress, NodeSeconds> AddrMan::Select(bool newOnly) const
+std::pair<CAddress, NodeSeconds> AddrMan::Select(bool new_only) const
{
- return m_impl->Select(newOnly);
+ return m_impl->Select(new_only);
}
std::vector<CAddress> AddrMan::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const