aboutsummaryrefslogtreecommitdiff
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
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>
-rw-r--r--src/addrman.cpp38
-rw-r--r--src/addrman.h4
-rw-r--r--src/addrman_impl.h6
-rw-r--r--src/test/addrman_tests.cpp10
4 files changed, 29 insertions, 29 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
diff --git a/src/addrman.h b/src/addrman.h
index 4985fc764c..374996e501 100644
--- a/src/addrman.h
+++ b/src/addrman.h
@@ -146,11 +146,11 @@ public:
/**
* Choose an address to connect to.
*
- * @param[in] newOnly Whether to only select addresses from the new table.
+ * @param[in] new_only Whether to only select addresses from the new table.
* @return CAddress The record for the selected peer.
* seconds The last time we attempted to connect to that peer.
*/
- std::pair<CAddress, NodeSeconds> Select(bool newOnly = false) const;
+ std::pair<CAddress, NodeSeconds> Select(bool new_only = false) const;
/**
* Return all or many randomly selected addresses, optionally by network.
diff --git a/src/addrman_impl.h b/src/addrman_impl.h
index 5410c3342c..3cf3b838d6 100644
--- a/src/addrman_impl.h
+++ b/src/addrman_impl.h
@@ -90,7 +90,7 @@ public:
}
//! Calculate in which position of a bucket to store this entry.
- int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
+ int GetBucketPosition(const uint256 &nKey, bool fNew, int bucket) const;
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
bool IsTerrible(NodeSeconds now = Now<NodeSeconds>()) const;
@@ -127,7 +127,7 @@ public:
std::pair<CAddress, NodeSeconds> SelectTriedCollision() EXCLUSIVE_LOCKS_REQUIRED(!cs);
- std::pair<CAddress, NodeSeconds> Select(bool newOnly) const
+ std::pair<CAddress, NodeSeconds> Select(bool new_only) const
EXCLUSIVE_LOCKS_REQUIRED(!cs);
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
@@ -251,7 +251,7 @@ private:
void Attempt_(const CService& addr, bool fCountFailure, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
- std::pair<CAddress, NodeSeconds> Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
+ std::pair<CAddress, NodeSeconds> Select_(bool new_only) const EXCLUSIVE_LOCKS_REQUIRED(cs);
/** Helper to generalize looking up an addrman entry from either table.
*
diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp
index 758691cfde..ad59e123d2 100644
--- a/src/test/addrman_tests.cpp
+++ b/src/test/addrman_tests.cpp
@@ -127,8 +127,8 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
// the specified port to tried, but not the other.
addrman->Good(CAddress(addr1_port, NODE_NONE));
BOOST_CHECK_EQUAL(addrman->Size(), 2U);
- bool newOnly = true;
- auto addr_ret3 = addrman->Select(newOnly).first;
+ bool new_only = true;
+ auto addr_ret3 = addrman->Select(new_only).first;
BOOST_CHECK_EQUAL(addr_ret3.ToStringAddrPort(), "250.1.1.1:8333");
}
@@ -144,14 +144,14 @@ BOOST_AUTO_TEST_CASE(addrman_select)
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
- bool newOnly = true;
- auto addr_ret1 = addrman->Select(newOnly).first;
+ bool new_only = true;
+ auto addr_ret1 = addrman->Select(new_only).first;
BOOST_CHECK_EQUAL(addr_ret1.ToStringAddrPort(), "250.1.1.1:8333");
// Test: move addr to tried, select from new expected nothing returned.
BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE)));
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
- auto addr_ret2 = addrman->Select(newOnly).first;
+ auto addr_ret2 = addrman->Select(new_only).first;
BOOST_CHECK_EQUAL(addr_ret2.ToStringAddrPort(), "[::]:0");
auto addr_ret3 = addrman->Select().first;