Skip to content

Commit 26c3bf1

Browse files
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 <[email protected]>
1 parent 4880641 commit 26c3bf1

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/addrman.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const NetGr
5858
return hash2 % ADDRMAN_NEW_BUCKET_COUNT;
5959
}
6060

61-
int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) const
61+
int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int bucket) const
6262
{
63-
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
63+
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << bucket << GetKey()).GetCheapHash();
6464
return hash1 % ADDRMAN_BUCKET_SIZE;
6565
}
6666

@@ -714,19 +714,19 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, NodeSeconds
714714
}
715715
}
716716

717-
std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
717+
std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool new_only) const
718718
{
719719
AssertLockHeld(cs);
720720

721721
if (vRandom.empty()) return {};
722-
if (newOnly && nNew == 0) return {};
722+
if (new_only && nNew == 0) return {};
723723

724724
// Decide if we are going to search the new or tried table
725725
bool search_tried;
726726
int bucket_count;
727727

728728
// Use a 50% chance for choosing between tried and new table entries.
729-
if (!newOnly &&
729+
if (!new_only &&
730730
(nTried > 0 &&
731731
(nNew == 0 || insecure_rand.randbool() == 0))) {
732732
search_tried = true;
@@ -736,39 +736,39 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::Select_(bool newOnly) const
736736
bucket_count = ADDRMAN_NEW_BUCKET_COUNT;
737737
}
738738

739-
double fChanceFactor = 1.0;
739+
double chance_factor = 1.0;
740740
while (1) {
741741
// Pick a bucket, and an initial position in that bucket.
742-
int nBucket = insecure_rand.randrange(bucket_count);
743-
int nBucketPos = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
742+
int bucket = insecure_rand.randrange(bucket_count);
743+
int initial_position = insecure_rand.randrange(ADDRMAN_BUCKET_SIZE);
744744

745745
// Iterate over the positions of that bucket, starting at the initial one,
746746
// and looping around.
747747
int i;
748748
for (i = 0; i < ADDRMAN_BUCKET_SIZE; ++i) {
749-
int position = (nBucketPos + i) % ADDRMAN_BUCKET_SIZE;
750-
int node_id = GetEntry(search_tried, nBucket, position);
749+
int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
750+
int node_id = GetEntry(search_tried, bucket, position);
751751
if (node_id != -1) break;
752752
}
753753

754754
// If the bucket is entirely empty, start over with a (likely) different one.
755755
if (i == ADDRMAN_BUCKET_SIZE) continue;
756756

757757
// Find the entry to return.
758-
int position = (nBucketPos + i) % ADDRMAN_BUCKET_SIZE;
759-
int nId = GetEntry(search_tried, nBucket, position);
758+
int position = (initial_position + i) % ADDRMAN_BUCKET_SIZE;
759+
int nId = GetEntry(search_tried, bucket, position);
760760
const auto it_found{mapInfo.find(nId)};
761761
assert(it_found != mapInfo.end());
762762
const AddrInfo& info{it_found->second};
763763

764-
// With probability GetChance() * fChanceFactor, return the entry.
765-
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
764+
// With probability GetChance() * chance_factor, return the entry.
765+
if (insecure_rand.randbits(30) < chance_factor * info.GetChance() * (1 << 30)) {
766766
LogPrint(BCLog::ADDRMAN, "Selected %s from %s\n", info.ToStringAddrPort(), search_tried ? "tried" : "new");
767767
return {info, info.m_last_try};
768768
}
769769

770770
// Otherwise start over with a (likely) different bucket, and increased chance factor.
771-
fChanceFactor *= 1.2;
771+
chance_factor *= 1.2;
772772
}
773773
}
774774

@@ -1168,11 +1168,11 @@ std::pair<CAddress, NodeSeconds> AddrManImpl::SelectTriedCollision()
11681168
return ret;
11691169
}
11701170

1171-
std::pair<CAddress, NodeSeconds> AddrManImpl::Select(bool newOnly) const
1171+
std::pair<CAddress, NodeSeconds> AddrManImpl::Select(bool new_only) const
11721172
{
11731173
LOCK(cs);
11741174
Check();
1175-
auto addrRet = Select_(newOnly);
1175+
auto addrRet = Select_(new_only);
11761176
Check();
11771177
return addrRet;
11781178
}
@@ -1266,9 +1266,9 @@ std::pair<CAddress, NodeSeconds> AddrMan::SelectTriedCollision()
12661266
return m_impl->SelectTriedCollision();
12671267
}
12681268

1269-
std::pair<CAddress, NodeSeconds> AddrMan::Select(bool newOnly) const
1269+
std::pair<CAddress, NodeSeconds> AddrMan::Select(bool new_only) const
12701270
{
1271-
return m_impl->Select(newOnly);
1271+
return m_impl->Select(new_only);
12721272
}
12731273

12741274
std::vector<CAddress> AddrMan::GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const

src/addrman.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ class AddrMan
146146
/**
147147
* Choose an address to connect to.
148148
*
149-
* @param[in] newOnly Whether to only select addresses from the new table.
149+
* @param[in] new_only Whether to only select addresses from the new table.
150150
* @return CAddress The record for the selected peer.
151151
* seconds The last time we attempted to connect to that peer.
152152
*/
153-
std::pair<CAddress, NodeSeconds> Select(bool newOnly = false) const;
153+
std::pair<CAddress, NodeSeconds> Select(bool new_only = false) const;
154154

155155
/**
156156
* Return all or many randomly selected addresses, optionally by network.

src/addrman_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class AddrInfo : public CAddress
9090
}
9191

9292
//! Calculate in which position of a bucket to store this entry.
93-
int GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const;
93+
int GetBucketPosition(const uint256 &nKey, bool fNew, int bucket) const;
9494

9595
//! Determine whether the statistics about this entry are bad enough so that it can just be deleted
9696
bool IsTerrible(NodeSeconds now = Now<NodeSeconds>()) const;
@@ -127,7 +127,7 @@ class AddrManImpl
127127

128128
std::pair<CAddress, NodeSeconds> SelectTriedCollision() EXCLUSIVE_LOCKS_REQUIRED(!cs);
129129

130-
std::pair<CAddress, NodeSeconds> Select(bool newOnly) const
130+
std::pair<CAddress, NodeSeconds> Select(bool new_only) const
131131
EXCLUSIVE_LOCKS_REQUIRED(!cs);
132132

133133
std::vector<CAddress> GetAddr(size_t max_addresses, size_t max_pct, std::optional<Network> network) const
@@ -251,7 +251,7 @@ class AddrManImpl
251251

252252
void Attempt_(const CService& addr, bool fCountFailure, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs);
253253

254-
std::pair<CAddress, NodeSeconds> Select_(bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs);
254+
std::pair<CAddress, NodeSeconds> Select_(bool new_only) const EXCLUSIVE_LOCKS_REQUIRED(cs);
255255

256256
/** Helper to generalize looking up an addrman entry from either table.
257257
*

src/test/addrman_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
127127
// the specified port to tried, but not the other.
128128
addrman->Good(CAddress(addr1_port, NODE_NONE));
129129
BOOST_CHECK_EQUAL(addrman->Size(), 2U);
130-
bool newOnly = true;
131-
auto addr_ret3 = addrman->Select(newOnly).first;
130+
bool new_only = true;
131+
auto addr_ret3 = addrman->Select(new_only).first;
132132
BOOST_CHECK_EQUAL(addr_ret3.ToStringAddrPort(), "250.1.1.1:8333");
133133
}
134134

@@ -144,14 +144,14 @@ BOOST_AUTO_TEST_CASE(addrman_select)
144144
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
145145
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
146146

147-
bool newOnly = true;
148-
auto addr_ret1 = addrman->Select(newOnly).first;
147+
bool new_only = true;
148+
auto addr_ret1 = addrman->Select(new_only).first;
149149
BOOST_CHECK_EQUAL(addr_ret1.ToStringAddrPort(), "250.1.1.1:8333");
150150

151151
// Test: move addr to tried, select from new expected nothing returned.
152152
BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE)));
153153
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
154-
auto addr_ret2 = addrman->Select(newOnly).first;
154+
auto addr_ret2 = addrman->Select(new_only).first;
155155
BOOST_CHECK_EQUAL(addr_ret2.ToStringAddrPort(), "[::]:0");
156156

157157
auto addr_ret3 = addrman->Select().first;

0 commit comments

Comments
 (0)