Stochastical (IP) address manager.
More...
#include <addrman.h>
|
| template<typename Stream > |
| void | Serialize (Stream &s_) const |
| | Serialized format. More...
|
| |
| template<typename Stream > |
| void | Unserialize (Stream &s_) |
| |
| void | Clear () |
| |
| | CAddrMan () |
| |
| | ~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, bool test_before_evict=true, 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...
|
| |
| void | ResolveCollisions () |
| | See if any to-be-evicted tried table entries have been tested and if so resolve the collisions. More...
|
| |
| CAddrInfo | SelectTriedCollision () |
| | Randomly select an address in tried that another address is attempting to evict. More...
|
| |
| CAddrInfo | Select (bool newOnly=false) |
| | Choose an address to connect to. More...
|
| |
| std::vector< CAddress > | GetAddr (size_t max_addresses, size_t max_pct) |
| | 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 * | Find (const CNetAddr &addr, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Find an entry. More...
|
| |
| CAddrInfo * | Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | find an entry, creating it if necessary. More...
|
| |
| void | SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Swap two elements in vRandom. More...
|
| |
| void | MakeTried (CAddrInfo &info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Move an entry from the "new" table(s) to the "tried" table. More...
|
| |
| void | Delete (int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Delete an entry. It must not be in tried, and have refcount 0. More...
|
| |
| void | ClearNew (int nUBucket, int nUBucketPos) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Clear a position in a "new" table. This is the only place where entries are actually deleted. More...
|
| |
| void | Good_ (const CService &addr, bool test_before_evict, int64_t time) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Mark an entry "good", possibly moving it from "new" to "tried". More...
|
| |
| bool | Add_ (const CAddress &addr, const CNetAddr &source, int64_t nTimePenalty) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Add an entry to the "new" table. More...
|
| |
| void | Attempt_ (const CService &addr, bool fCountFailure, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Mark an entry as attempted to connect. More...
|
| |
| CAddrInfo | Select_ (bool newOnly) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Select an address to connect to, if newOnly is set to true, only the new table is selected from. More...
|
| |
| void | ResolveCollisions_ () EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | See if any to-be-evicted tried table entries have been tested and if so resolve the collisions. More...
|
| |
| CAddrInfo | SelectTriedCollision_ () EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Return a random to-be-evicted tried table address. More...
|
| |
| void | GetAddr_ (std::vector< CAddress > &vAddr, size_t max_addresses, size_t max_pct) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Select several addresses at once. More...
|
| |
| void | Connected_ (const CService &addr, int64_t nTime) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Mark an entry as currently-connected-to. More...
|
| |
| void | SetServices_ (const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| | Update an entry's service bits. More...
|
| |
|
| std::set< int > | m_tried_collisions |
| | Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions. More...
|
| |
|
| static constexpr Format | FILE_FORMAT = Format::V3_BIP155 |
| | The maximum format this software knows it can unserialize. More...
|
| |
| static constexpr uint8_t | INCOMPATIBILITY_BASE = 32 |
| | The initial value of a field that is incremented every time an incompatible format change is made (such that old software versions would not be able to parse and understand the new file format). More...
|
| |
Stochastical (IP) address manager.
Definition at line 172 of file addrman.h.
Serialization versions.
| Enumerator |
|---|
| V0_HISTORICAL |
historic format, before commit e6b343d88
|
| V1_DETERMINISTIC |
for pre-asmap files
|
| V2_ASMAP |
for files including asmap version
|
| V3_BIP155 |
same as V2_ASMAP plus addresses are in BIP155 format
|
Definition at line 181 of file addrman.h.
| bool CAddrMan::Add |
( |
const CAddress & |
addr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty = 0 |
|
) |
| |
|
inline |
Add a single address.
Definition at line 611 of file addrman.h.
| bool CAddrMan::Add |
( |
const std::vector< CAddress > & |
vAddr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty = 0 |
|
) |
| |
|
inline |
Add multiple addresses.
Definition at line 625 of file addrman.h.
| bool CAddrMan::Add_ |
( |
const CAddress & |
addr, |
|
|
const CNetAddr & |
source, |
|
|
int64_t |
nTimePenalty |
|
) |
| |
|
protected |
Add an entry to the "new" table.
Definition at line 262 of file addrman.cpp.
Mark an entry as connection attempted to.
Definition at line 649 of file addrman.h.
| void CAddrMan::Attempt_ |
( |
const CService & |
addr, |
|
|
bool |
fCountFailure, |
|
|
int64_t |
nTime |
|
) |
| |
|
protected |
Mark an entry as attempted to connect.
Definition at line 335 of file addrman.cpp.
Consistency check.
Definition at line 598 of file addrman.h.
| void CAddrMan::ClearNew |
( |
int |
nUBucket, |
|
|
int |
nUBucketPos |
|
) |
| |
|
protected |
Clear a position in a "new" table. This is the only place where entries are actually deleted.
Definition at line 133 of file addrman.cpp.
Mark an entry as currently-connected-to.
Definition at line 708 of file addrman.h.
| void CAddrMan::Connected_ |
( |
const CService & |
addr, |
|
|
int64_t |
nTime |
|
) |
| |
|
protected |
Mark an entry as currently-connected-to.
Definition at line 507 of file addrman.cpp.
find an entry, creating it if necessary.
nTime and nServices of the found node are updated, if necessary.
Definition at line 87 of file addrman.cpp.
| std::vector< bool > CAddrMan::DecodeAsmap |
( |
fs::path |
path | ) |
|
|
static |
| void CAddrMan::Delete |
( |
int |
nId | ) |
|
|
protected |
Delete an entry. It must not be in tried, and have refcount 0.
Definition at line 119 of file addrman.cpp.
| std::vector<CAddress> CAddrMan::GetAddr |
( |
size_t |
max_addresses, |
|
|
size_t |
max_pct |
|
) |
| |
|
inline |
Return a bunch of addresses, selected at random.
Definition at line 695 of file addrman.h.
| void CAddrMan::GetAddr_ |
( |
std::vector< CAddress > & |
vAddr, |
|
|
size_t |
max_addresses, |
|
|
size_t |
max_pct |
|
) |
| |
|
protected |
Select several addresses at once.
Definition at line 482 of file addrman.cpp.
Mark an entry as accessible.
Definition at line 640 of file addrman.h.
| void CAddrMan::Good_ |
( |
const CService & |
addr, |
|
|
bool |
test_before_evict, |
|
|
int64_t |
time |
|
) |
| |
|
protected |
Mark an entry "good", possibly moving it from "new" to "tried".
Definition at line 196 of file addrman.cpp.
| int nIdCount CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
| std::map<int, CAddrInfo> mapInfo CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
table with information about all nIds
| std::map<CNetAddr, int> mapAddr CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
find an nId based on its network address
| std::vector<int> vRandom CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
randomly-ordered vector of all nIds
| int nTried CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
| int nNew CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
number of (unique) "new" entries
| int64_t nLastGood CAddrMan::GUARDED_BY |
( |
cs |
| ) |
|
|
private |
last time Good was called (memory only)
| void CAddrMan::MakeTried |
( |
CAddrInfo & |
info, |
|
|
int |
nId |
|
) |
| |
|
protected |
Move an entry from the "new" table(s) to the "tried" table.
Definition at line 148 of file addrman.cpp.
| void CAddrMan::ResolveCollisions |
( |
| ) |
|
|
inline |
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
Definition at line 658 of file addrman.h.
| void CAddrMan::ResolveCollisions_ |
( |
| ) |
|
|
protected |
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
Definition at line 545 of file addrman.cpp.
| CAddrInfo CAddrMan::Select |
( |
bool |
newOnly = false | ) |
|
|
inline |
Choose an address to connect to.
Definition at line 682 of file addrman.h.
Select an address to connect to, if newOnly is set to true, only the new table is selected from.
Definition at line 357 of file addrman.cpp.
Randomly select an address in tried that another address is attempting to evict.
Definition at line 667 of file addrman.h.
| CAddrInfo CAddrMan::SelectTriedCollision_ |
( |
| ) |
|
|
protected |
Return a random to-be-evicted tried table address.
Definition at line 604 of file addrman.cpp.
template<typename Stream >
| void CAddrMan::Serialize |
( |
Stream & |
s_ | ) |
const |
|
inline |
Serialized format.
- format version byte (
- See also
Format)
- lowest compatible format version byte. This is used to help old software decide whether to parse the file. For example:
- Bitcoin Core version N knows how to parse up to format=3. If a new format=4 is introduced in version N+1 that is compatible with format=3 and it is known that version N will be able to parse it, then version N+1 will write (format=4, lowest_compatible=3) in the first two bytes of the file, and so version N will still try to parse it.
- Bitcoin Core version N+2 introduces a new incompatible format=5. It will write (format=5, lowest_compatible=5) and so any versions that do not know how to parse format=5 will not try to read the file.
- nKey
- 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 SERIALIZE_METHODS since the serialization and deserialization code has very little in common.
Definition at line 351 of file addrman.h.
Update an entry's service bits.
Definition at line 527 of file addrman.cpp.
| size_t CAddrMan::size |
( |
| ) |
const |
|
inline |
Return the number of (unique) addresses in all tables.
Definition at line 591 of file addrman.h.
| void CAddrMan::SwapRandom |
( |
unsigned int |
nRandomPos1, |
|
|
unsigned int |
nRandomPos2 |
|
) |
| |
|
protected |
Swap two elements in vRandom.
Definition at line 99 of file addrman.cpp.
template<typename Stream >
| void CAddrMan::Unserialize |
( |
Stream & |
s_ | ) |
|
|
inline |
| friend class CAddrManTest |
|
friend |
critical section to protect the inner data structures
Definition at line 177 of file addrman.h.
| constexpr Format CAddrMan::FILE_FORMAT = Format::V3_BIP155 |
|
staticprivate |
The maximum format this software knows it can unserialize.
Also, we always serialize in this format. The format (first byte in the serialized stream) can be higher than this and still this software may be able to unserialize the file - if the second byte (see lowest_compatible in Unserialize()) is less or equal to this.
Definition at line 193 of file addrman.h.
| constexpr uint8_t CAddrMan::INCOMPATIBILITY_BASE = 32 |
|
staticprivate |
The initial value of a field that is incremented every time an incompatible format change is made (such that old software versions would not be able to parse and understand the new file format).
This is 32 because we overtook the "key size" field which was 32 historically.
- Note
- Don't increment this. Increment
lowest_compatible in Serialize() instead.
Definition at line 200 of file addrman.h.
Source of random numbers for randomization in inner loops.
Definition at line 237 of file addrman.h.
| std::vector<bool> CAddrMan::m_asmap |
| std::set<int> CAddrMan::m_tried_collisions |
|
private |
Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions.
Definition at line 230 of file addrman.h.
secret key to randomize bucket select with
Definition at line 234 of file addrman.h.
The documentation for this class was generated from the following files: