Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
Stochastical (IP) address manager. More...
#include <addrman.h>
Public Member Functions | |
template<typename Stream > | |
void | Serialize (Stream &s) const |
serialized format: More... | |
template<typename Stream > | |
void | Unserialize (Stream &s) |
void | Clear () |
CAddrMan (bool _discriminatePorts=false) | |
~CAddrMan () | |
size_t | size () const |
Return the number of (unique) addresses in all tables. More... | |
void | Check () |
Consistency check. More... | |
bool | Add (const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty=0) |
Add a single address. More... | |
bool | Add (const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0) |
Add multiple addresses. More... | |
void | Good (const CService &addr, int64_t nTime=GetAdjustedTime()) |
Mark an entry as accessible. More... | |
void | Attempt (const CService &addr, bool fCountFailure, int64_t nTime=GetAdjustedTime()) |
Mark an entry as connection attempted to. More... | |
CAddrInfo | Select (bool newOnly=false) |
Choose an address to connect to. More... | |
std::vector< CAddress > | GetAddr () |
Return a bunch of addresses, selected at random. More... | |
void | Connected (const CService &addr, int64_t nTime=GetAdjustedTime()) |
Mark an entry as currently-connected-to. More... | |
void | SetServices (const CService &addr, ServiceFlags nServices) |
CAddrInfo | GetAddressInfo (const CService &addr) |
Protected Member Functions | |
CAddrInfo * | Find (const CService &addr, int *pnId=nullptr) |
Find an entry. More... | |
CAddrInfo * | Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId=nullptr) |
find an entry, creating it if necessary. More... | |
void | SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) |
Swap two elements in vRandom. More... | |
void | MakeTried (CAddrInfo &info, int nId) |
Move an entry from the "new" table(s) to the "tried" table. More... | |
void | Delete (int nId) |
Delete an entry. It must not be in tried, and have refcount 0. More... | |
void | ClearNew (int nUBucket, int nUBucketPos) |
Clear a position in a "new" table. This is the only place where entries are actually deleted. More... | |
void | Good_ (const CService &addr, int64_t nTime) |
Mark an entry "good", possibly moving it from "new" to "tried". More... | |
bool | Add_ (const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty) |
Add an entry to the "new" table. More... | |
void | Attempt_ (const CService &addr, bool fCountFailure, int64_t nTime) |
Mark an entry as attempted to connect. More... | |
CAddrInfo | Select_ (bool newOnly) |
Select an address to connect to, if newOnly is set to true, only the new table is selected from. More... | |
virtual int | RandomInt (int nMax) |
Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic. More... | |
void | GetAddr_ (std::vector< CAddress > &vAddr) |
Select several addresses at once. More... | |
void | Connected_ (const CService &addr, int64_t nTime) |
Mark an entry as currently-connected-to. More... | |
void | SetServices_ (const CService &addr, ServiceFlags nServices) |
Update an entry's service bits. More... | |
CAddrInfo | GetAddressInfo_ (const CService &addr) |
Get address info for address. More... | |
Protected Attributes | |
uint256 | nKey |
secret key to randomize bucket select with More... | |
FastRandomContext | insecure_rand |
Source of random numbers for randomization in inner loops. More... | |
Private Attributes | |
CCriticalSection | cs |
critical section to protect the inner data structures More... | |
int | nIdCount |
last used nId More... | |
std::map< int, CAddrInfo > | mapInfo |
table with information about all nIds More... | |
std::map< CService, int > | mapAddr |
find an nId based on its network address More... | |
std::vector< int > | vRandom |
randomly-ordered vector of all nIds More... | |
int | nTried |
int | vvTried [ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] |
list of "tried" buckets More... | |
int | nNew |
number of (unique) "new" entries More... | |
int | vvNew [ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] |
list of "new" buckets More... | |
int64_t | nLastGood |
last time Good was called (memory only) More... | |
bool | discriminatePorts |
Detailed Description
Constructor & Destructor Documentation
◆ CAddrMan()
|
inline |
◆ ~CAddrMan()
|
inline |
Definition at line 492 of file addrman.h.
References nKey, and base_blob< BITS >::SetNull().
Member Function Documentation
◆ Add() [1/2]
|
inline |
Add a single address.
Definition at line 518 of file addrman.h.
References Add_(), BCLog::ADDRMAN, Check(), cs, LOCK, LogPrint, nNew, nTried, CNetAddr::ToString(), and CService::ToStringIPPort().
Referenced by CConnman::AddNewAddresses(), CConnman::ThreadDNSAddressSeed(), and CConnman::ThreadOpenConnections().
◆ Add() [2/2]
◆ Add_()
|
protected |
Add an entry to the "new" table.
Definition at line 259 of file addrman.cpp.
References ADDRMAN_NEW_BUCKETS_PER_ADDRESS, ClearNew(), Create(), Delete(), Find(), CAddrInfo::fInTried, GetAdjustedTime(), CAddrInfo::GetBucketPosition(), CAddrInfo::GetNewBucket(), CNetAddr::IsRoutable(), CAddrInfo::IsTerrible(), mapInfo, nKey, nNew, CAddrInfo::nRefCount, CAddress::nServices, CAddress::nTime, RandomInt(), and vvNew.
Referenced by Add().
◆ Attempt()
|
inline |
Mark an entry as connection attempted to.
Definition at line 556 of file addrman.h.
References Attempt_(), Check(), cs, and LOCK.
Referenced by CConnman::ConnectNode().
◆ Attempt_()
|
protected |
Mark an entry as attempted to connect.
Definition at line 332 of file addrman.cpp.
References Find(), CAddrInfo::nAttempts, CAddrInfo::nLastCountAttempt, nLastGood, and CAddrInfo::nLastTry.
Referenced by Attempt().
◆ Check()
|
inline |
Consistency check.
Definition at line 505 of file addrman.h.
References cs, LOCK, and LogPrintf.
Referenced by Add(), Attempt(), Connected(), GetAddr(), GetAddressInfo(), Good(), Select(), SetServices(), and Unserialize().
◆ Clear()
|
inline |
Definition at line 462 of file addrman.h.
References ADDRMAN_BUCKET_SIZE, ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT, cs, GetRandHash(), LOCK, mapAddr, mapInfo, nIdCount, nKey, nLastGood, nNew, nTried, vRandom, vvNew, and vvTried.
Referenced by CAddrMan(), CAddrDB::Read(), CConnman::Start(), and Unserialize().
◆ ClearNew()
|
protected |
Clear a position in a "new" table. This is the only place where entries are actually deleted.
Definition at line 142 of file addrman.cpp.
References Delete(), mapInfo, CAddrInfo::nRefCount, and vvNew.
Referenced by Add_(), and MakeTried().
◆ Connected()
|
inline |
Mark an entry as currently-connected-to.
Definition at line 593 of file addrman.h.
References Check(), Connected_(), cs, and LOCK.
Referenced by CConnman::DeleteNode().
◆ Connected_()
|
protected |
Mark an entry as currently-connected-to.
Definition at line 500 of file addrman.cpp.
References Find(), and CAddress::nTime.
Referenced by Connected().
◆ Create()
|
protected |
find an entry, creating it if necessary.
nTime and nServices of the found node are updated, if necessary.
Definition at line 86 of file addrman.cpp.
References discriminatePorts, mapAddr, mapInfo, nIdCount, CService::SetPort(), and vRandom.
Referenced by Add_().
◆ Delete()
|
protected |
Delete an entry. It must not be in tried, and have refcount 0.
Definition at line 123 of file addrman.cpp.
References discriminatePorts, mapAddr, mapInfo, nNew, CService::SetPort(), SwapRandom(), and vRandom.
Referenced by Add_(), ClearNew(), and Unserialize().
◆ Find()
Find an entry.
Definition at line 68 of file addrman.cpp.
References discriminatePorts, mapAddr, mapInfo, and CService::SetPort().
Referenced by Add_(), Attempt_(), Connected_(), GetAddressInfo_(), Good_(), and SetServices_().
◆ GetAddr()
|
inline |
Return a bunch of addresses, selected at random.
Definition at line 580 of file addrman.h.
References Check(), cs, GetAddr_(), and LOCK.
Referenced by CConnman::GetAddresses().
◆ GetAddr_()
|
protected |
Select several addresses at once.
Definition at line 479 of file addrman.cpp.
References ADDRMAN_GETADDR_MAX, ADDRMAN_GETADDR_MAX_PCT, mapInfo, RandomInt(), SwapRandom(), and vRandom.
Referenced by GetAddr().
◆ GetAddressInfo()
◆ GetAddressInfo_()
Get address info for address.
Definition at line 538 of file addrman.cpp.
References Find().
Referenced by GetAddressInfo().
◆ Good()
|
inline |
◆ Good_()
|
protected |
Mark an entry "good", possibly moving it from "new" to "tried".
Definition at line 205 of file addrman.cpp.
References BCLog::ADDRMAN, ADDRMAN_NEW_BUCKET_COUNT, Find(), CAddrInfo::fInTried, fLogIPs, CAddrInfo::GetBucketPosition(), LogPrint, MakeTried(), CAddrInfo::nAttempts, nKey, nLastGood, CAddrInfo::nLastSuccess, CAddrInfo::nLastTry, RandomInt(), CService::ToString(), and vvNew.
Referenced by Good().
◆ MakeTried()
|
protected |
Move an entry from the "new" table(s) to the "tried" table.
Definition at line 157 of file addrman.cpp.
References ADDRMAN_NEW_BUCKET_COUNT, ClearNew(), CAddrInfo::fInTried, CAddrInfo::GetBucketPosition(), CAddrInfo::GetTriedBucket(), mapInfo, nKey, nNew, CAddrInfo::nRefCount, nTried, vvNew, and vvTried.
Referenced by Good_().
◆ RandomInt()
|
protectedvirtual |
Wraps GetRandInt to allow tests to override RandomInt and make it determinismistic.
Definition at line 555 of file addrman.cpp.
References GetRandInt().
Referenced by Add_(), GetAddr_(), Good_(), and Select_().
◆ Select()
◆ Select_()
|
protected |
Select an address to connect to, if newOnly is set to true, only the new table is selected from.
Definition at line 354 of file addrman.cpp.
References ADDRMAN_BUCKET_SIZE, ADDRMAN_BUCKET_SIZE_LOG2, ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_NEW_BUCKET_COUNT_LOG2, ADDRMAN_TRIED_BUCKET_COUNT, ADDRMAN_TRIED_BUCKET_COUNT_LOG2, insecure_rand, mapInfo, nNew, nTried, FastRandomContext::randbits(), RandomInt(), size(), vvNew, and vvTried.
Referenced by Select().
◆ Serialize()
|
inline |
serialized format:
- version byte (currently 1)
- 0x20 + nKey (serialized as if it were a vector, for backward compatibility)
- nNew
- nTried
- number of "new" buckets XOR 2**30
- all nNew addrinfos in vvNew
- all nTried addrinfos in vvTried
- for each bucket:
- number of elements
- for each element: index
2**30 is xorred with the number of buckets to make addrman deserializer v0 detect it as incompatible. This is necessary because it did not check the version number on deserialization.
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_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 changes to the ADDRMAN_ parameters without breaking the on-disk structure.
We don't use ADD_SERIALIZE_METHODS since the serialization and deserialization code has very little in common.
Definition at line 307 of file addrman.h.
References ADDRMAN_BUCKET_SIZE, ADDRMAN_NEW_BUCKET_COUNT, cs, CAddrInfo::fInTried, LOCK, mapInfo, nKey, nNew, CAddrInfo::nRefCount, nTried, and vvNew.
◆ SetServices()
|
inline |
Definition at line 601 of file addrman.h.
References Check(), cs, LOCK, and SetServices_().
Referenced by CConnman::SetServices().
◆ SetServices_()
|
protected |
Update an entry's service bits.
Definition at line 520 of file addrman.cpp.
References Find(), and CAddress::nServices.
Referenced by SetServices().
◆ size()
|
inline |
Return the number of (unique) addresses in all tables.
Definition at line 498 of file addrman.h.
References cs, LOCK, and vRandom.
Referenced by CConnman::DumpAddresses(), CConnman::GetAddressCount(), Select_(), CConnman::Start(), CConnman::ThreadDNSAddressSeed(), and CConnman::ThreadOpenConnections().
◆ SwapRandom()
|
protected |
Swap two elements in vRandom.
Definition at line 103 of file addrman.cpp.
References mapInfo, and vRandom.
Referenced by Delete(), and GetAddr_().
◆ Unserialize()
|
inline |
Definition at line 357 of file addrman.h.
References BCLog::ADDRMAN, ADDRMAN_BUCKET_SIZE, ADDRMAN_NEW_BUCKET_COUNT, ADDRMAN_NEW_BUCKETS_PER_ADDRESS, ADDRMAN_TRIED_BUCKET_COUNT, Check(), Clear(), cs, Delete(), CAddrInfo::GetBucketPosition(), CAddrInfo::GetTriedBucket(), LOCK, LogPrint, mapAddr, mapInfo, nIdCount, nKey, nNew, CAddrInfo::nRefCount, nTried, vRandom, vvNew, and vvTried.
Member Data Documentation
◆ cs
|
mutableprivate |
critical section to protect the inner data structures
Definition at line 186 of file addrman.h.
Referenced by Add(), Attempt(), Check(), Clear(), Connected(), GetAddr(), GetAddressInfo(), Good(), Select(), Serialize(), SetServices(), size(), and Unserialize().
◆ discriminatePorts
|
private |
◆ insecure_rand
|
protected |
◆ mapAddr
|
private |
◆ mapInfo
|
private |
table with information about all nIds
Definition at line 192 of file addrman.h.
Referenced by Add_(), Clear(), ClearNew(), Create(), Delete(), Find(), GetAddr_(), MakeTried(), Select_(), Serialize(), SwapRandom(), and Unserialize().
◆ nIdCount
|
private |
last used nId
Definition at line 189 of file addrman.h.
Referenced by Clear(), Create(), and Unserialize().
◆ nKey
|
protected |
secret key to randomize bucket select with
Definition at line 220 of file addrman.h.
Referenced by Add_(), Clear(), CAddrInfo::GetNewBucket(), Good_(), MakeTried(), Serialize(), Unserialize(), and ~CAddrMan().
◆ nLastGood
|
private |
last time Good was called (memory only)
Definition at line 213 of file addrman.h.
Referenced by Attempt_(), Clear(), and Good_().
◆ nNew
|
private |
number of (unique) "new" entries
Definition at line 207 of file addrman.h.
Referenced by Add(), Add_(), Clear(), Delete(), MakeTried(), Select_(), Serialize(), and Unserialize().
◆ nTried
|
private |
Definition at line 201 of file addrman.h.
Referenced by Add(), Clear(), MakeTried(), Select_(), Serialize(), and Unserialize().
◆ vRandom
|
private |
randomly-ordered vector of all nIds
Definition at line 198 of file addrman.h.
Referenced by Clear(), Create(), Delete(), GetAddr_(), size(), SwapRandom(), and Unserialize().
◆ vvNew
|
private |
list of "new" buckets
Definition at line 210 of file addrman.h.
Referenced by Add_(), Clear(), ClearNew(), Good_(), MakeTried(), Select_(), Serialize(), and Unserialize().
◆ vvTried
|
private |
list of "tried" buckets
Definition at line 204 of file addrman.h.
Referenced by Clear(), MakeTried(), Select_(), and Unserialize().
The documentation for this class was generated from the following files:
- src/addrman.h
- src/addrman.cpp