Bitcoin ABC 0.26.3
P2P Digital Currency
|
#include <addrman_impl.h>
Private Types | |
enum | Format : uint8_t { V0_HISTORICAL = 0 , V1_DETERMINISTIC = 1 , V2_ASMAP = 2 , V3_BIP155 = 3 , V4_MULTIPORT = 4 } |
Serialization versions. More... | |
Private Member Functions | |
int nIdCount | GUARDED_BY (cs) |
last used nId | |
std::unordered_map< int, AddrInfo > mapInfo | GUARDED_BY (cs) |
table with information about all nIds | |
std::unordered_map< CService, int, CServiceHash > mapAddr | GUARDED_BY (cs) |
find an nId based on its network address and port. | |
std::vector< int > vRandom | GUARDED_BY (cs) |
randomly-ordered vector of all nIds This is mutable because it is unobservable outside the class, so any changes to it (even in const methods) are also unobservable. | |
int nTried | GUARDED_BY (cs) |
int vvTried[ADDRMAN_TRIED_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] | GUARDED_BY (cs) |
list of "tried" buckets | |
int nNew | GUARDED_BY (cs) |
number of (unique) "new" entries | |
int vvNew[ADDRMAN_NEW_BUCKET_COUNT][ADDRMAN_BUCKET_SIZE] | GUARDED_BY (cs) |
list of "new" buckets | |
NodeSeconds m_last_good | GUARDED_BY (cs) |
last time Good was called (memory only) | |
AddrInfo * | Find (const CService &addr, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
Find an entry. | |
AddrInfo * | Create (const CAddress &addr, const CNetAddr &addrSource, int *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
find an entry, creating it if necessary. | |
void | SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Swap two elements in vRandom. | |
void | Delete (int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) |
Delete an entry. It must not be in tried, and have refcount 0. | |
void | ClearNew (int nUBucket, int nUBucketPos) EXCLUSIVE_LOCKS_REQUIRED(cs) |
Clear a position in a "new" table. | |
void | MakeTried (AddrInfo &info, int nId) EXCLUSIVE_LOCKS_REQUIRED(cs) |
Move an entry from the "new" table(s) to the "tried" table. | |
bool | AddSingle (const CAddress &addr, const CNetAddr &source, std::chrono::seconds time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs) |
Attempt to add a single address to addrman's new table. | |
void | Good_ (const CService &addr, bool test_before_evict, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs) |
bool | Add_ (const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty) EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | Attempt_ (const CService &addr, bool fCountFailure, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs) |
std::pair< CAddress, NodeSeconds > | Select_ (bool newOnly) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
std::vector< CAddress > | GetAddr_ (size_t max_addresses, size_t max_pct, std::optional< Network > network) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | Connected_ (const CService &addr, NodeSeconds time) EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | SetServices_ (const CService &addr, ServiceFlags nServices) EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | ResolveCollisions_ () EXCLUSIVE_LOCKS_REQUIRED(cs) |
std::pair< CAddress, NodeSeconds > | SelectTriedCollision_ () EXCLUSIVE_LOCKS_REQUIRED(cs) |
void | Check () const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Consistency check, taking into account m_consistency_check_ratio. | |
int | CheckAddrman () const EXCLUSIVE_LOCKS_REQUIRED(cs) |
Perform consistency check, regardless of m_consistency_check_ratio. | |
Private Attributes | |
Mutex | cs |
A mutex to protect the inner data structures. | |
FastRandomContext | insecure_rand |
Source of random numbers for randomization in inner loops. | |
uint256 | nKey |
secret key to randomize bucket select with | |
std::set< int > | m_tried_collisions |
Holds addrs inserted into tried table that collide with existing entries. | |
const int32_t | m_consistency_check_ratio |
Perform consistency checks every m_consistency_check_ratio operations (if non-zero). | |
const std::vector< bool > | m_asmap |
bool | deterministic = false |
Use deterministic bucket selection and inner loops randomization. | |
Static Private Attributes | |
static constexpr Format | FILE_FORMAT = Format::V4_MULTIPORT |
The maximum format this software knows it can unserialize. | |
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). | |
Friends | |
class | AddrManTest |
class | AddrManCorrupted |
Definition at line 109 of file addrman_impl.h.
|
private |
Serialization versions.
Definition at line 170 of file addrman_impl.h.
Definition at line 132 of file addrman.cpp.
AddrManImpl::~AddrManImpl | ( | ) |
|
private |
Definition at line 727 of file addrman.cpp.
|
private |
Attempt to add a single address to addrman's new table.
Definition at line 581 of file addrman.cpp.
void AddrManImpl::Attempt | ( | const CService & | addr, |
bool | fCountFailure, | ||
NodeSeconds | time | ||
) |
|
private |
Definition at line 743 of file addrman.cpp.
|
private |
Consistency check, taking into account m_consistency_check_ratio.
Will std::abort if an inconsistency is detected.
Definition at line 1046 of file addrman.cpp.
|
private |
Perform consistency check, regardless of m_consistency_check_ratio.
Definition at line 1064 of file addrman.cpp.
void AddrManImpl::Clear | ( | ) |
Definition at line 1255 of file addrman.cpp.
Clear a position in a "new" table.
This is the only place where entries are actually deleted.
Definition at line 504 of file addrman.cpp.
void AddrManImpl::Connected | ( | const CService & | addr, |
NodeSeconds | time | ||
) |
|
private |
Definition at line 900 of file addrman.cpp.
|
private |
find an entry, creating it if necessary.
nTime and nServices of the found node are updated, if necessary.
Definition at line 449 of file addrman.cpp.
Delete an entry. It must not be in tried, and have refcount 0.
Definition at line 489 of file addrman.cpp.
Find an entry.
Definition at line 432 of file addrman.cpp.
|
private |
Definition at line 856 of file addrman.cpp.
const std::vector< bool > & AddrManImpl::GetAsmap | ( | ) | const |
Definition at line 1251 of file addrman.cpp.
void AddrManImpl::Good | ( | const CService & | addr, |
bool | test_before_evict, | ||
NodeSeconds | time | ||
) |
|
private |
Definition at line 665 of file addrman.cpp.
table with information about all nIds
|
private |
find an nId based on its network address and port.
randomly-ordered vector of all nIds This is mutable because it is unobservable outside the class, so any changes to it (even in const methods) are also unobservable.
|
private |
list of "tried" buckets
|
private |
list of "new" buckets
|
private |
last time Good was called (memory only)
void AddrManImpl::MakeDeterministic | ( | ) |
Move an entry from the "new" table(s) to the "tried" table.
Definition at line 522 of file addrman.cpp.
void AddrManImpl::ResolveCollisions | ( | ) |
|
private |
Definition at line 935 of file addrman.cpp.
std::pair< CAddress, NodeSeconds > AddrManImpl::Select | ( | bool | newOnly | ) | const |
|
private |
Definition at line 764 of file addrman.cpp.
std::pair< CAddress, NodeSeconds > AddrManImpl::SelectTriedCollision | ( | ) |
|
private |
Definition at line 1016 of file addrman.cpp.
Serialized format.
Format
)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.
vvNew, vvTried, mapInfo, mapAddr and vRandom are never encoded explicitly; they are instead reconstructed from the other information.
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 141 of file addrman.cpp.
void AddrManImpl::SetServices | ( | const CService & | addr, |
ServiceFlags | nServices | ||
) |
|
private |
Definition at line 919 of file addrman.cpp.
size_t AddrManImpl::size | ( | ) | const |
Swap two elements in vRandom.
Definition at line 464 of file addrman.cpp.
Definition at line 157 of file addrman_impl.h.
Definition at line 156 of file addrman_impl.h.
|
mutableprivate |
A mutex to protect the inner data structures.
Definition at line 161 of file addrman_impl.h.
Use deterministic bucket selection and inner loops randomization.
For testing purpose only.
Definition at line 255 of file addrman_impl.h.
|
staticconstexprprivate |
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 188 of file addrman_impl.h.
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.
lowest_compatible
in Serialize()
instead. Definition at line 196 of file addrman_impl.h.
|
mutableprivate |
Source of random numbers for randomization in inner loops.
Definition at line 164 of file addrman_impl.h.
|
private |
Definition at line 251 of file addrman_impl.h.
|
private |
Perform consistency checks every m_consistency_check_ratio operations (if non-zero).
Definition at line 235 of file addrman_impl.h.
|
private |
Holds addrs inserted into tried table that collide with existing entries.
Test-before-evict discipline used to resolve these collisions.
Definition at line 229 of file addrman_impl.h.
|
private |
secret key to randomize bucket select with
Definition at line 167 of file addrman_impl.h.