Skip to content

Commit fa21fc6

Browse files
author
MarcoFalke
committed
scripted-diff: Rename addrman time symbols
-BEGIN VERIFY SCRIPT- ren() { sed -i "s:\<$1\>:$2:g" $(git grep -l "\<$1\>" ./src ./test); } ren nLastTry m_last_try ren nLastSuccess m_last_success ren nLastGood m_last_good ren nLastCountAttempt m_last_count_attempt ren nSinceLastTry since_last_try ren nTimePenalty time_penalty ren nUpdateInterval update_interval ren fCurrentlyOnline currently_online -END VERIFY SCRIPT-
1 parent fa9284c commit fa21fc6

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

src/addrman.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int AddrInfo::GetBucketPosition(const uint256& nKey, bool fNew, int nBucket) con
6666

6767
bool AddrInfo::IsTerrible(int64_t nNow) const
6868
{
69-
if (nNow - nLastTry <= 60) { // never remove things tried in the last minute
69+
if (nNow - m_last_try <= 60) { // never remove things tried in the last minute
7070
return false;
7171
}
7272

@@ -77,10 +77,10 @@ bool AddrInfo::IsTerrible(int64_t nNow) const
7777
return true;
7878
}
7979

80-
if (nLastSuccess == 0 && nAttempts >= ADDRMAN_RETRIES) // tried N times and never a success
80+
if (m_last_success == 0 && nAttempts >= ADDRMAN_RETRIES) // tried N times and never a success
8181
return true;
8282

83-
if (nNow - nLastSuccess > ADDRMAN_MIN_FAIL_DAYS * 24 * 60 * 60 && nAttempts >= ADDRMAN_MAX_FAILURES) // N successive failures in the last week
83+
if (nNow - m_last_success > ADDRMAN_MIN_FAIL_DAYS * 24 * 60 * 60 && nAttempts >= ADDRMAN_MAX_FAILURES) // N successive failures in the last week
8484
return true;
8585

8686
return false;
@@ -91,7 +91,7 @@ double AddrInfo::GetChance(int64_t nNow) const
9191
double fChance = 1.0;
9292

9393
// deprioritize very recent attempts away
94-
if (nNow - nLastTry < 60 * 10) {
94+
if (nNow - m_last_try < 60 * 10) {
9595
fChance *= 0.01;
9696
}
9797

@@ -540,7 +540,7 @@ void AddrManImpl::MakeTried(AddrInfo& info, int nId)
540540
info.fInTried = true;
541541
}
542542

543-
bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty)
543+
bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_t time_penalty)
544544
{
545545
AssertLockHeld(cs);
546546

@@ -552,15 +552,15 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
552552

553553
// Do not set a penalty for a source's self-announcement
554554
if (addr == source) {
555-
nTimePenalty = 0;
555+
time_penalty = 0;
556556
}
557557

558558
if (pinfo) {
559559
// periodically update nTime
560-
bool fCurrentlyOnline = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
561-
int64_t nUpdateInterval = (fCurrentlyOnline ? 60 * 60 : 24 * 60 * 60);
562-
if (pinfo->nTime < addr.nTime - nUpdateInterval - nTimePenalty) {
563-
pinfo->nTime = std::max((int64_t)0, addr.nTime - nTimePenalty);
560+
bool currently_online = (GetAdjustedTime() - addr.nTime < 24 * 60 * 60);
561+
int64_t update_interval = (currently_online ? 60 * 60 : 24 * 60 * 60);
562+
if (pinfo->nTime < addr.nTime - update_interval - time_penalty) {
563+
pinfo->nTime = std::max((int64_t)0, addr.nTime - time_penalty);
564564
}
565565

566566
// add services
@@ -587,7 +587,7 @@ bool AddrManImpl::AddSingle(const CAddress& addr, const CNetAddr& source, int64_
587587
return false;
588588
} else {
589589
pinfo = Create(addr, source, &nId);
590-
pinfo->nTime = std::max((int64_t)0, (int64_t)pinfo->nTime - nTimePenalty);
590+
pinfo->nTime = std::max((int64_t)0, (int64_t)pinfo->nTime - time_penalty);
591591
nNew++;
592592
}
593593

@@ -623,7 +623,7 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
623623

624624
int nId;
625625

626-
nLastGood = nTime;
626+
m_last_good = nTime;
627627

628628
AddrInfo* pinfo = Find(addr, &nId);
629629

@@ -633,8 +633,8 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
633633
AddrInfo& info = *pinfo;
634634

635635
// update info
636-
info.nLastSuccess = nTime;
637-
info.nLastTry = nTime;
636+
info.m_last_success = nTime;
637+
info.m_last_try = nTime;
638638
info.nAttempts = 0;
639639
// nTime is not updated here, to avoid leaking information about
640640
// currently-connected peers.
@@ -671,11 +671,11 @@ bool AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
671671
}
672672
}
673673

674-
bool AddrManImpl::Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty)
674+
bool AddrManImpl::Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t time_penalty)
675675
{
676676
int added{0};
677677
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++) {
678-
added += AddSingle(*it, source, nTimePenalty) ? 1 : 0;
678+
added += AddSingle(*it, source, time_penalty) ? 1 : 0;
679679
}
680680
if (added > 0) {
681681
LogPrint(BCLog::ADDRMAN, "Added %i addresses (of %i) from %s: %i tried, %i new\n", added, vAddr.size(), source.ToString(), nTried, nNew);
@@ -696,9 +696,9 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, int64_t nTi
696696
AddrInfo& info = *pinfo;
697697

698698
// update info
699-
info.nLastTry = nTime;
700-
if (fCountFailure && info.nLastCountAttempt < nLastGood) {
701-
info.nLastCountAttempt = nTime;
699+
info.m_last_try = nTime;
700+
if (fCountFailure && info.m_last_count_attempt < m_last_good) {
701+
info.m_last_count_attempt = nTime;
702702
info.nAttempts++;
703703
}
704704
}
@@ -736,7 +736,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
736736
// With probability GetChance() * fChanceFactor, return the entry.
737737
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
738738
LogPrint(BCLog::ADDRMAN, "Selected %s from tried\n", info.ToString());
739-
return {info, info.nLastTry};
739+
return {info, info.m_last_try};
740740
}
741741
// Otherwise start over with a (likely) different bucket, and increased chance factor.
742742
fChanceFactor *= 1.2;
@@ -764,7 +764,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
764764
// With probability GetChance() * fChanceFactor, return the entry.
765765
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
766766
LogPrint(BCLog::ADDRMAN, "Selected %s from new\n", info.ToString());
767-
return {info, info.nLastTry};
767+
return {info, info.m_last_try};
768768
}
769769
// Otherwise start over with a (likely) different bucket, and increased chance factor.
770770
fChanceFactor *= 1.2;
@@ -823,8 +823,8 @@ void AddrManImpl::Connected_(const CService& addr, int64_t nTime)
823823
AddrInfo& info = *pinfo;
824824

825825
// update info
826-
int64_t nUpdateInterval = 20 * 60;
827-
if (nTime - info.nTime > nUpdateInterval)
826+
int64_t update_interval = 20 * 60;
827+
if (nTime - info.nTime > update_interval)
828828
info.nTime = nTime;
829829
}
830830

@@ -873,19 +873,19 @@ void AddrManImpl::ResolveCollisions_()
873873
const auto current_time{GetAdjustedTime()};
874874

875875
// Has successfully connected in last X hours
876-
if (current_time - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
876+
if (current_time - info_old.m_last_success < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
877877
erase_collision = true;
878-
} else if (current_time - info_old.nLastTry < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours
878+
} else if (current_time - info_old.m_last_try < ADDRMAN_REPLACEMENT_HOURS*(60*60)) { // attempted to connect and failed in last X hours
879879

880880
// Give address at least 60 seconds to successfully connect
881-
if (current_time - info_old.nLastTry > 60) {
881+
if (current_time - info_old.m_last_try > 60) {
882882
LogPrint(BCLog::ADDRMAN, "Replacing %s with %s in tried table\n", info_old.ToString(), info_new.ToString());
883883

884884
// Replaces an existing address already in the tried table with the new address
885885
Good_(info_new, false, current_time);
886886
erase_collision = true;
887887
}
888-
} else if (current_time - info_new.nLastSuccess > ADDRMAN_TEST_WINDOW) {
888+
} else if (current_time - info_new.m_last_success > ADDRMAN_TEST_WINDOW) {
889889
// If the collision hasn't resolved in some reasonable amount of time,
890890
// just evict the old entry -- we must not be able to
891891
// connect to it for some reason.
@@ -932,7 +932,7 @@ std::pair<CAddress, int64_t> AddrManImpl::SelectTriedCollision_()
932932
int tried_bucket_pos = newInfo.GetBucketPosition(nKey, false, tried_bucket);
933933

934934
const AddrInfo& info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
935-
return {info_old, info_old.nLastTry};
935+
return {info_old, info_old.m_last_try};
936936
}
937937

938938
std::optional<AddressPosition> AddrManImpl::FindAddressEntry_(const CAddress& addr)
@@ -990,7 +990,7 @@ int AddrManImpl::CheckAddrman() const
990990
int n = entry.first;
991991
const AddrInfo& info = entry.second;
992992
if (info.fInTried) {
993-
if (!info.nLastSuccess)
993+
if (!info.m_last_success)
994994
return -1;
995995
if (info.nRefCount)
996996
return -2;
@@ -1008,9 +1008,9 @@ int AddrManImpl::CheckAddrman() const
10081008
}
10091009
if (info.nRandomPos < 0 || (size_t)info.nRandomPos >= vRandom.size() || vRandom[info.nRandomPos] != n)
10101010
return -14;
1011-
if (info.nLastTry < 0)
1011+
if (info.m_last_try < 0)
10121012
return -6;
1013-
if (info.nLastSuccess < 0)
1013+
if (info.m_last_success < 0)
10141014
return -8;
10151015
}
10161016

@@ -1067,11 +1067,11 @@ size_t AddrManImpl::size() const
10671067
return vRandom.size();
10681068
}
10691069

1070-
bool AddrManImpl::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
1070+
bool AddrManImpl::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t time_penalty)
10711071
{
10721072
LOCK(cs);
10731073
Check();
1074-
auto ret = Add_(vAddr, source, nTimePenalty);
1074+
auto ret = Add_(vAddr, source, time_penalty);
10751075
Check();
10761076
return ret;
10771077
}
@@ -1184,9 +1184,9 @@ size_t AddrMan::size() const
11841184
return m_impl->size();
11851185
}
11861186

1187-
bool AddrMan::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
1187+
bool AddrMan::Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t time_penalty)
11881188
{
1189-
return m_impl->Add(vAddr, source, nTimePenalty);
1189+
return m_impl->Add(vAddr, source, time_penalty);
11901190
}
11911191

11921192
bool AddrMan::Good(const CService& addr, int64_t nTime)

src/addrman.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ class AddrMan
107107
*
108108
* @param[in] vAddr Address records to attempt to add.
109109
* @param[in] source The address of the node that sent us these addr records.
110-
* @param[in] nTimePenalty A "time penalty" to apply to the address record's nTime. If a peer
110+
* @param[in] time_penalty A "time penalty" to apply to the address record's nTime. If a peer
111111
* sends us an address record with nTime=n, then we'll add it to our
112-
* addrman with nTime=(n - nTimePenalty).
112+
* addrman with nTime=(n - time_penalty).
113113
* @return true if at least one address is successfully added. */
114-
bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty = 0);
114+
bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t time_penalty = 0);
115115

116116
/**
117117
* Mark an address record as accessible and attempt to move it to addrman's tried table.

src/addrman_impl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ class AddrInfo : public CAddress
3838
{
3939
public:
4040
//! last try whatsoever by us (memory only)
41-
int64_t nLastTry{0};
41+
int64_t m_last_try{0};
4242

4343
//! last counted attempt (memory only)
44-
int64_t nLastCountAttempt{0};
44+
int64_t m_last_count_attempt{0};
4545

4646
//! where knowledge about this address first came from
4747
CNetAddr source;
4848

4949
//! last successful connection by us
50-
int64_t nLastSuccess{0};
50+
int64_t m_last_success{0};
5151

5252
//! connection attempts since last successful attempt
5353
int nAttempts{0};
@@ -64,7 +64,7 @@ class AddrInfo : public CAddress
6464
SERIALIZE_METHODS(AddrInfo, obj)
6565
{
6666
READWRITEAS(CAddress, obj);
67-
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
67+
READWRITE(obj.source, obj.m_last_success, obj.nAttempts);
6868
}
6969

7070
AddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
@@ -112,7 +112,7 @@ class AddrManImpl
112112

113113
size_t size() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
114114

115-
bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t nTimePenalty)
115+
bool Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, int64_t time_penalty)
116116
EXCLUSIVE_LOCKS_REQUIRED(!cs);
117117

118118
bool Good(const CService& addr, int64_t nTime)
@@ -202,7 +202,7 @@ class AddrManImpl
202202
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] GUARDED_BY(cs);
203203

204204
//! last time Good was called (memory only). Initially set to 1 so that "never" is strictly worse.
205-
int64_t nLastGood GUARDED_BY(cs){1};
205+
int64_t m_last_good GUARDED_BY(cs){1};
206206

207207
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
208208
std::set<int> m_tried_collisions;
@@ -233,11 +233,11 @@ class AddrManImpl
233233

234234
/** Attempt to add a single address to addrman's new table.
235235
* @see AddrMan::Add() for parameters. */
236-
bool AddSingle(const CAddress& addr, const CNetAddr& source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
236+
bool AddSingle(const CAddress& addr, const CNetAddr& source, int64_t time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
237237

238238
bool Good_(const CService& addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
239239

240-
bool Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
240+
bool Add_(const std::vector<CAddress> &vAddr, const CNetAddr& source, int64_t time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs);
241241

242242
void Attempt_(const CService& addr, bool fCountFailure, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs);
243243

src/test/fuzz/addrman.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class AddrManDeterministic : public AddrMan
161161
CSipHasher hasher(0, 0);
162162
auto addr_key = a.GetKey();
163163
auto source_key = a.source.GetAddrBytes();
164-
hasher.Write(a.nLastSuccess);
164+
hasher.Write(a.m_last_success);
165165
hasher.Write(a.nAttempts);
166166
hasher.Write(a.nRefCount);
167167
hasher.Write(a.fInTried);
@@ -175,8 +175,8 @@ class AddrManDeterministic : public AddrMan
175175
};
176176

177177
auto addrinfo_eq = [](const AddrInfo& lhs, const AddrInfo& rhs) {
178-
return std::tie(static_cast<const CService&>(lhs), lhs.source, lhs.nLastSuccess, lhs.nAttempts, lhs.nRefCount, lhs.fInTried) ==
179-
std::tie(static_cast<const CService&>(rhs), rhs.source, rhs.nLastSuccess, rhs.nAttempts, rhs.nRefCount, rhs.fInTried);
178+
return std::tie(static_cast<const CService&>(lhs), lhs.source, lhs.m_last_success, lhs.nAttempts, lhs.nRefCount, lhs.fInTried) ==
179+
std::tie(static_cast<const CService&>(rhs), rhs.source, rhs.m_last_success, rhs.nAttempts, rhs.nRefCount, rhs.fInTried);
180180
};
181181

182182
using Addresses = std::unordered_set<AddrInfo, decltype(addrinfo_hasher), decltype(addrinfo_eq)>;

0 commit comments

Comments
 (0)