Skip to content

Commit

Permalink
addrman.h: CAddrInfo inline members default values, plus several typo…
Browse files Browse the repository at this point in the history
…s corrected.
  • Loading branch information
furszy committed Jul 28, 2021
1 parent a7b9fd9 commit d2a8baf
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,31 @@
*/
class CAddrInfo : public CAddress
{


public:
//! last try whatsoever by us (memory only)
int64_t nLastTry;
int64_t nLastTry{0};

//! last counted attempt (memory only)
int64_t nLastCountAttempt;
int64_t nLastCountAttempt{0};

private:
//! where knowledge about this address first came from
CNetAddr source;

//! last successful connection by us
int64_t nLastSuccess;
int64_t nLastSuccess{0};

//! connection attempts since last successful attempt
int nAttempts;
int nAttempts{0};

//! reference count in new sets (memory only)
int nRefCount;
int nRefCount{0};

//! in tried set? (memory only)
bool fInTried;
bool fInTried{false};

//! position in vRandom
int nRandomPos;
int nRandomPos{-1};

friend class CAddrMan;

Expand All @@ -62,25 +60,12 @@ class CAddrInfo : public CAddress
READWRITE(obj.source, obj.nLastSuccess, obj.nAttempts);
}

void Init()
{
nLastSuccess = 0;
nLastTry = 0;
nLastCountAttempt = 0;
nAttempts = 0;
nRefCount = 0;
fInTried = false;
nRandomPos = -1;
}

CAddrInfo(const CAddress& addrIn, const CNetAddr& addrSource) : CAddress(addrIn), source(addrSource)
{
Init();
}

CAddrInfo() : CAddress(), source()
{
Init();
}

//! Calculate in which "tried" bucket this entry belongs
Expand Down Expand Up @@ -108,15 +93,15 @@ class CAddrInfo : public CAddress
/** Stochastic address manager
*
* Design goals:
* * Keep the address tables in-memory, and asynchronously dump the entire to able in peers.dat.
* * Keep the address tables in-memory, and asynchronously dump the entire table to peers.dat.
* * Make sure no (localized) attacker can fill the entire table with his nodes/addresses.
*
* To that end:
* * Addresses are organized into buckets.
* * Address that have not yet been tried go into 1024 "new" buckets.
* * Based on the address range (/16 for IPv4) of source of the information, 64 buckets are selected at random
* * The actual bucket is chosen from one of these, based on the range the address itself is located.
* * One single address can occur in up to 8 different buckets, to increase selection chances for addresses that
* * Addresses that have not yet been tried go into 1024 "new" buckets.
* * Based on the address range (/16 for IPv4) of the source of information, 64 buckets are selected at random.
* * The actual bucket is chosen from one of these, based on the range in which the address itself is located.
* * One single address can occur in up to 8 different buckets to increase selection chances for addresses that
* are seen frequently. The chance for increasing this multiplicity decreases exponentially.
* * When adding a new address to a full bucket, a randomly chosen entry (with a bias favoring less recently seen
* ones) is removed from it first.
Expand Down Expand Up @@ -218,7 +203,7 @@ class CAddrMan
//! last time Good was called (memory only)
int64_t nLastGood GUARDED_BY(cs);

//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discpline used to resolve these collisions.
//! Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
std::set<int> m_tried_collisions;

protected:
Expand Down Expand Up @@ -300,7 +285,7 @@ class CAddrMan
* Notice that vvTried, mapAddr and vVector are never encoded explicitly;
* they are instead reconstructed from the other information.
*
* vvNew is serialized, but only used if ADDRMAN_UNKOWN_BUCKET_COUNT didn't change,
* vvNew is serialized, but only used if ADDRMAN_UNKNOWN_BUCKET_COUNT didn't change,
* otherwise it is reconstructed as well.
*
* This format is more complex, but significantly smaller (at most 1.5 MiB), and supports
Expand All @@ -327,7 +312,7 @@ class CAddrMan
int nIds = 0;
for (const auto& entry : mapInfo) {
mapUnkIds[entry.first] = nIds;
const CAddrInfo &info = entry.second;
const CAddrInfo& info = entry.second;
if (info.nRefCount) {
assert(nIds != nNew); // this means nNew was wrong, oh ow
s << info;
Expand All @@ -336,7 +321,7 @@ class CAddrMan
}
nIds = 0;
for (const auto& entry : mapInfo) {
const CAddrInfo &info = entry.second;
const CAddrInfo& info = entry.second;
if (info.fInTried) {
assert(nIds != nTried); // this means nTried was wrong, oh ow
s << info;
Expand Down Expand Up @@ -457,7 +442,6 @@ class CAddrMan
Check();
}


void Clear()
{
LOCK(cs);
Expand Down Expand Up @@ -489,7 +473,7 @@ class CAddrMan

~CAddrMan()
{
nKey = uint256();
nKey.SetNull();
}

//! Return the number of (unique) addresses in all tables.
Expand Down Expand Up @@ -520,8 +504,9 @@ class CAddrMan
Check();
fRet |= Add_(addr, source, nTimePenalty);
Check();
if (fRet)
if (fRet) {
LogPrint(BCLog::ADDRMAN, "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
}
return fRet;
}

Expand All @@ -534,8 +519,9 @@ class CAddrMan
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
Check();
if (nAdd)
if (nAdd) {
LogPrint(BCLog::ADDRMAN, "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
}
return nAdd > 0;
}

Expand Down Expand Up @@ -624,6 +610,7 @@ class CAddrMan
SetServices_(addr, nServices);
Check();
}

};

#endif // BITCOIN_ADDRMAN_H

0 comments on commit d2a8baf

Please sign in to comment.