Skip to content

Commit 3757503

Browse files
committed
scripted-diff: Rename CAddrInfo to AddrInfo
-BEGIN VERIFY SCRIPT- git grep -l CAddrInfo src/ | xargs sed -i 's/CAddrInfo/AddrInfo/g' -END VERIFY SCRIPT-
1 parent dd8f7f2 commit 3757503

File tree

5 files changed

+77
-77
lines changed

5 files changed

+77
-77
lines changed

src/addrman.cpp

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static constexpr size_t ADDRMAN_SET_TRIED_COLLISION_SIZE{10};
4141
/** The maximum time we'll spend trying to resolve a tried table collision, in seconds */
4242
static constexpr int64_t ADDRMAN_TEST_WINDOW{40*60}; // 40 minutes
4343

44-
int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
44+
int AddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asmap) const
4545
{
4646
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetKey()).GetCheapHash();
4747
uint64_t hash2 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << (hash1 % ADDRMAN_TRIED_BUCKETS_PER_GROUP)).GetCheapHash();
@@ -51,7 +51,7 @@ int CAddrInfo::GetTriedBucket(const uint256& nKey, const std::vector<bool> &asma
5151
return tried_bucket;
5252
}
5353

54-
int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector<bool> &asmap) const
54+
int AddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std::vector<bool> &asmap) const
5555
{
5656
std::vector<unsigned char> vchSourceGroupKey = src.GetGroup(asmap);
5757
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << GetGroup(asmap) << vchSourceGroupKey).GetCheapHash();
@@ -62,13 +62,13 @@ int CAddrInfo::GetNewBucket(const uint256& nKey, const CNetAddr& src, const std:
6262
return new_bucket;
6363
}
6464

65-
int CAddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
65+
int AddrInfo::GetBucketPosition(const uint256 &nKey, bool fNew, int nBucket) const
6666
{
6767
uint64_t hash1 = (CHashWriter(SER_GETHASH, 0) << nKey << (fNew ? uint8_t{'N'} : uint8_t{'K'}) << nBucket << GetKey()).GetCheapHash();
6868
return hash1 % ADDRMAN_BUCKET_SIZE;
6969
}
7070

71-
bool CAddrInfo::IsTerrible(int64_t nNow) const
71+
bool AddrInfo::IsTerrible(int64_t nNow) const
7272
{
7373
if (nLastTry && nLastTry >= nNow - 60) // never remove things tried in the last minute
7474
return false;
@@ -88,7 +88,7 @@ bool CAddrInfo::IsTerrible(int64_t nNow) const
8888
return false;
8989
}
9090

91-
double CAddrInfo::GetChance(int64_t nNow) const
91+
double AddrInfo::GetChance(int64_t nNow) const
9292
{
9393
double fChance = 1.0;
9494
int64_t nSinceLastTry = std::max<int64_t>(nNow - nLastTry, 0);
@@ -190,7 +190,7 @@ void AddrManImpl::Serialize(Stream& s_) const
190190
int nIds = 0;
191191
for (const auto& entry : mapInfo) {
192192
mapUnkIds[entry.first] = nIds;
193-
const CAddrInfo &info = entry.second;
193+
const AddrInfo &info = entry.second;
194194
if (info.nRefCount) {
195195
assert(nIds != nNew); // this means nNew was wrong, oh ow
196196
s << info;
@@ -199,7 +199,7 @@ void AddrManImpl::Serialize(Stream& s_) const
199199
}
200200
nIds = 0;
201201
for (const auto& entry : mapInfo) {
202-
const CAddrInfo &info = entry.second;
202+
const AddrInfo &info = entry.second;
203203
if (info.fInTried) {
204204
assert(nIds != nTried); // this means nTried was wrong, oh ow
205205
s << info;
@@ -283,7 +283,7 @@ void AddrManImpl::Unserialize(Stream& s_)
283283

284284
// Deserialize entries from the new table.
285285
for (int n = 0; n < nNew; n++) {
286-
CAddrInfo &info = mapInfo[n];
286+
AddrInfo &info = mapInfo[n];
287287
s >> info;
288288
mapAddr[info] = n;
289289
info.nRandomPos = vRandom.size();
@@ -294,7 +294,7 @@ void AddrManImpl::Unserialize(Stream& s_)
294294
// Deserialize entries from the tried table.
295295
int nLost = 0;
296296
for (int n = 0; n < nTried; n++) {
297-
CAddrInfo info;
297+
AddrInfo info;
298298
s >> info;
299299
int nKBucket = info.GetTriedBucket(nKey, m_asmap);
300300
int nKBucketPos = info.GetBucketPosition(nKey, false, nKBucket);
@@ -351,7 +351,7 @@ void AddrManImpl::Unserialize(Stream& s_)
351351
for (auto bucket_entry : bucket_entries) {
352352
int bucket{bucket_entry.first};
353353
const int entry_index{bucket_entry.second};
354-
CAddrInfo& info = mapInfo[entry_index];
354+
AddrInfo& info = mapInfo[entry_index];
355355

356356
// Don't store the entry in the new bucket if it's not a valid address for our addrman
357357
if (!info.IsValid()) continue;
@@ -401,7 +401,7 @@ void AddrManImpl::Unserialize(Stream& s_)
401401
}
402402
}
403403

404-
CAddrInfo* AddrManImpl::Find(const CNetAddr& addr, int* pnId)
404+
AddrInfo* AddrManImpl::Find(const CNetAddr& addr, int* pnId)
405405
{
406406
AssertLockHeld(cs);
407407

@@ -416,12 +416,12 @@ CAddrInfo* AddrManImpl::Find(const CNetAddr& addr, int* pnId)
416416
return nullptr;
417417
}
418418

419-
CAddrInfo* AddrManImpl::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
419+
AddrInfo* AddrManImpl::Create(const CAddress& addr, const CNetAddr& addrSource, int* pnId)
420420
{
421421
AssertLockHeld(cs);
422422

423423
int nId = nIdCount++;
424-
mapInfo[nId] = CAddrInfo(addr, addrSource);
424+
mapInfo[nId] = AddrInfo(addr, addrSource);
425425
mapAddr[addr] = nId;
426426
mapInfo[nId].nRandomPos = vRandom.size();
427427
vRandom.push_back(nId);
@@ -459,7 +459,7 @@ void AddrManImpl::Delete(int nId)
459459
AssertLockHeld(cs);
460460

461461
assert(mapInfo.count(nId) != 0);
462-
CAddrInfo& info = mapInfo[nId];
462+
AddrInfo& info = mapInfo[nId];
463463
assert(!info.fInTried);
464464
assert(info.nRefCount == 0);
465465

@@ -477,7 +477,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
477477
// if there is an entry in the specified bucket, delete it.
478478
if (vvNew[nUBucket][nUBucketPos] != -1) {
479479
int nIdDelete = vvNew[nUBucket][nUBucketPos];
480-
CAddrInfo& infoDelete = mapInfo[nIdDelete];
480+
AddrInfo& infoDelete = mapInfo[nIdDelete];
481481
assert(infoDelete.nRefCount > 0);
482482
infoDelete.nRefCount--;
483483
vvNew[nUBucket][nUBucketPos] = -1;
@@ -487,7 +487,7 @@ void AddrManImpl::ClearNew(int nUBucket, int nUBucketPos)
487487
}
488488
}
489489

490-
void AddrManImpl::MakeTried(CAddrInfo& info, int nId)
490+
void AddrManImpl::MakeTried(AddrInfo& info, int nId)
491491
{
492492
AssertLockHeld(cs);
493493

@@ -515,7 +515,7 @@ void AddrManImpl::MakeTried(CAddrInfo& info, int nId)
515515
// find an item to evict
516516
int nIdEvict = vvTried[nKBucket][nKBucketPos];
517517
assert(mapInfo.count(nIdEvict) == 1);
518-
CAddrInfo& infoOld = mapInfo[nIdEvict];
518+
AddrInfo& infoOld = mapInfo[nIdEvict];
519519

520520
// Remove the to-be-evicted item from the tried set.
521521
infoOld.fInTried = false;
@@ -548,13 +548,13 @@ void AddrManImpl::Good_(const CService& addr, bool test_before_evict, int64_t nT
548548

549549
nLastGood = nTime;
550550

551-
CAddrInfo* pinfo = Find(addr, &nId);
551+
AddrInfo* pinfo = Find(addr, &nId);
552552

553553
// if not found, bail out
554554
if (!pinfo)
555555
return;
556556

557-
CAddrInfo& info = *pinfo;
557+
AddrInfo& info = *pinfo;
558558

559559
// check whether we are talking about the exact same CService (including same port)
560560
if (info != addr)
@@ -605,7 +605,7 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
605605

606606
bool fNew = false;
607607
int nId;
608-
CAddrInfo* pinfo = Find(addr, &nId);
608+
AddrInfo* pinfo = Find(addr, &nId);
609609

610610
// Do not set a penalty for a source's self-announcement
611611
if (addr == source) {
@@ -652,7 +652,7 @@ bool AddrManImpl::Add_(const CAddress& addr, const CNetAddr& source, int64_t nTi
652652
if (vvNew[nUBucket][nUBucketPos] != nId) {
653653
bool fInsert = vvNew[nUBucket][nUBucketPos] == -1;
654654
if (!fInsert) {
655-
CAddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
655+
AddrInfo& infoExisting = mapInfo[vvNew[nUBucket][nUBucketPos]];
656656
if (infoExisting.IsTerrible() || (infoExisting.nRefCount > 1 && pinfo->nRefCount == 0)) {
657657
// Overwrite the existing new table entry.
658658
fInsert = true;
@@ -675,13 +675,13 @@ void AddrManImpl::Attempt_(const CService& addr, bool fCountFailure, int64_t nTi
675675
{
676676
AssertLockHeld(cs);
677677

678-
CAddrInfo* pinfo = Find(addr);
678+
AddrInfo* pinfo = Find(addr);
679679

680680
// if not found, bail out
681681
if (!pinfo)
682682
return;
683683

684-
CAddrInfo& info = *pinfo;
684+
AddrInfo& info = *pinfo;
685685

686686
// check whether we are talking about the exact same CService (including same port)
687687
if (info != addr)
@@ -718,7 +718,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
718718
int nId = vvTried[nKBucket][nKBucketPos];
719719
const auto it_found{mapInfo.find(nId)};
720720
assert(it_found != mapInfo.end());
721-
const CAddrInfo& info{it_found->second};
721+
const AddrInfo& info{it_found->second};
722722
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
723723
return {info, info.nLastTry};
724724
}
@@ -737,7 +737,7 @@ std::pair<CAddress, int64_t> AddrManImpl::Select_(bool newOnly) const
737737
int nId = vvNew[nUBucket][nUBucketPos];
738738
const auto it_found{mapInfo.find(nId)};
739739
assert(it_found != mapInfo.end());
740-
const CAddrInfo& info{it_found->second};
740+
const AddrInfo& info{it_found->second};
741741
if (insecure_rand.randbits(30) < fChanceFactor * info.GetChance() * (1 << 30)) {
742742
return {info, info.nLastTry};
743743
}
@@ -770,7 +770,7 @@ std::vector<CAddress> AddrManImpl::GetAddr_(size_t max_addresses, size_t max_pct
770770
const auto it{mapInfo.find(vRandom[n])};
771771
assert(it != mapInfo.end());
772772

773-
const CAddrInfo& ai{it->second};
773+
const AddrInfo& ai{it->second};
774774

775775
// Filter by network (optional)
776776
if (network != std::nullopt && ai.GetNetClass() != network) continue;
@@ -788,13 +788,13 @@ void AddrManImpl::Connected_(const CService& addr, int64_t nTime)
788788
{
789789
AssertLockHeld(cs);
790790

791-
CAddrInfo* pinfo = Find(addr);
791+
AddrInfo* pinfo = Find(addr);
792792

793793
// if not found, bail out
794794
if (!pinfo)
795795
return;
796796

797-
CAddrInfo& info = *pinfo;
797+
AddrInfo& info = *pinfo;
798798

799799
// check whether we are talking about the exact same CService (including same port)
800800
if (info != addr)
@@ -810,13 +810,13 @@ void AddrManImpl::SetServices_(const CService& addr, ServiceFlags nServices)
810810
{
811811
AssertLockHeld(cs);
812812

813-
CAddrInfo* pinfo = Find(addr);
813+
AddrInfo* pinfo = Find(addr);
814814

815815
// if not found, bail out
816816
if (!pinfo)
817817
return;
818818

819-
CAddrInfo& info = *pinfo;
819+
AddrInfo& info = *pinfo;
820820

821821
// check whether we are talking about the exact same CService (including same port)
822822
if (info != addr)
@@ -839,7 +839,7 @@ void AddrManImpl::ResolveCollisions_()
839839
if (mapInfo.count(id_new) != 1) {
840840
erase_collision = true;
841841
} else {
842-
CAddrInfo& info_new = mapInfo[id_new];
842+
AddrInfo& info_new = mapInfo[id_new];
843843

844844
// Which tried bucket to move the entry to.
845845
int tried_bucket = info_new.GetTriedBucket(nKey, m_asmap);
@@ -850,7 +850,7 @@ void AddrManImpl::ResolveCollisions_()
850850

851851
// Get the to-be-evicted address that is being tested
852852
int id_old = vvTried[tried_bucket][tried_bucket_pos];
853-
CAddrInfo& info_old = mapInfo[id_old];
853+
AddrInfo& info_old = mapInfo[id_old];
854854

855855
// Has successfully connected in last X hours
856856
if (GetAdjustedTime() - info_old.nLastSuccess < ADDRMAN_REPLACEMENT_HOURS*(60*60)) {
@@ -905,13 +905,13 @@ std::pair<CAddress, int64_t> AddrManImpl::SelectTriedCollision_()
905905
return {};
906906
}
907907

908-
const CAddrInfo& newInfo = mapInfo[id_new];
908+
const AddrInfo& newInfo = mapInfo[id_new];
909909

910910
// which tried bucket to move the entry to
911911
int tried_bucket = newInfo.GetTriedBucket(nKey, m_asmap);
912912
int tried_bucket_pos = newInfo.GetBucketPosition(nKey, false, tried_bucket);
913913

914-
const CAddrInfo& info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
914+
const AddrInfo& info_old = mapInfo[vvTried[tried_bucket][tried_bucket_pos]];
915915
return {info_old, info_old.nLastTry};
916916
}
917917

@@ -944,7 +944,7 @@ int AddrManImpl::ForceCheckAddrman() const
944944

945945
for (const auto& entry : mapInfo) {
946946
int n = entry.first;
947-
const CAddrInfo& info = entry.second;
947+
const AddrInfo& info = entry.second;
948948
if (info.fInTried) {
949949
if (!info.nLastSuccess)
950950
return -1;

src/addrman_impl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2};
3333
/**
3434
* Extended statistics about a CAddress
3535
*/
36-
class CAddrInfo : public CAddress
36+
class AddrInfo : public CAddress
3737
{
3838
public:
3939
//! last try whatsoever by us (memory only)
@@ -60,17 +60,17 @@ class CAddrInfo : public CAddress
6060
//! position in vRandom
6161
mutable int nRandomPos{-1};
6262

63-
SERIALIZE_METHODS(CAddrInfo, obj)
63+
SERIALIZE_METHODS(AddrInfo, obj)
6464
{
6565
READWRITEAS(CAddress, obj);
6666
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
6767
}
6868

69-
CAddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
69+
AddrInfo(const CAddress &addrIn, const CNetAddr &addrSource) : CAddress(addrIn), source(addrSource)
7070
{
7171
}
7272

73-
CAddrInfo() : CAddress(), source()
73+
AddrInfo() : CAddress(), source()
7474
{
7575
}
7676

@@ -177,7 +177,7 @@ class AddrManImpl
177177
int nIdCount GUARDED_BY(cs){0};
178178

179179
//! table with information about all nIds
180-
std::unordered_map<int, CAddrInfo> mapInfo GUARDED_BY(cs);
180+
std::unordered_map<int, AddrInfo> mapInfo GUARDED_BY(cs);
181181

182182
//! find an nId based on its network address
183183
std::unordered_map<CNetAddr, int, CNetAddrHash> mapAddr GUARDED_BY(cs);
@@ -225,10 +225,10 @@ class AddrManImpl
225225
const std::vector<bool> m_asmap;
226226

227227
//! Find an entry.
228-
CAddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
228+
AddrInfo* Find(const CNetAddr& addr, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
229229

230230
//! Create a new entry and add it to the internal data structures mapInfo, mapAddr and vRandom.
231-
CAddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
231+
AddrInfo* Create(const CAddress &addr, const CNetAddr &addrSource, int *pnId = nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs);
232232

233233
//! Swap two elements in vRandom.
234234
void SwapRandom(unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs);
@@ -240,7 +240,7 @@ class AddrManImpl
240240
void ClearNew(int nUBucket, int nUBucketPos) EXCLUSIVE_LOCKS_REQUIRED(cs);
241241

242242
//! Move an entry from the "new" table(s) to the "tried" table
243-
void MakeTried(CAddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
243+
void MakeTried(AddrInfo& info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs);
244244

245245
void Good_(const CService &addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs);
246246

0 commit comments

Comments
 (0)