![]() |
Bitcoin Core 32.99.0
P2P Digital Currency
|
#include <addrman_impl.h>
Classes | |
| struct | NewTriedCount |
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 | |
| FastRandomContext insecure_rand | GUARDED_BY (cs) |
| Source of random numbers for randomization in inner loops. | |
| nid_type nIdCount | GUARDED_BY (cs) |
| last used nId | |
| std::unordered_map< nid_type, AddrInfo > mapInfo | GUARDED_BY (cs) |
| table with information about all nIds | |
| std::unordered_map< CService, nid_type, CServiceHash > mapAddr | GUARDED_BY (cs) |
| find an nId based on its network address and port. | |
| std::vector< nid_type > 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) |
| nid_type 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 | |
| nid_type 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). Initially set to 1 so that "never" is strictly worse. | |
| std::unordered_map< Network, NewTriedCount > m_network_counts | GUARDED_BY (cs) |
| Number of entries in addrman per network and new/tried table. | |
| AddrInfo * | Find (const CService &addr, nid_type *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| Find an entry. | |
| AddrInfo * | Create (const CAddress &addr, const CNetAddr &addrSource, nid_type *pnId=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| Create a new entry and add it to the internal data structures mapInfo, mapAddr and vRandom. | |
| void | SwapRandom (unsigned int nRandomPos1, unsigned int nRandomPos2) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
| Swap two elements in vRandom. | |
| void | Delete (nid_type 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. This is the only place where entries are actually deleted. | |
| void | MakeTried (AddrInfo &info, nid_type 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. | |
| bool | 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 new_only, const std::unordered_set< Network > &networks) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
| nid_type | GetEntry (bool use_tried, size_t bucket, size_t position) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
| Helper to generalize looking up an addrman entry from either table. | |
| std::vector< CAddress > | GetAddr_ (size_t max_addresses, size_t max_pct, std::optional< Network > network, bool filtered=true) const EXCLUSIVE_LOCKS_REQUIRED(cs) |
| std::vector< std::pair< AddrInfo, AddressPosition > > | GetEntries_ (bool from_tried) 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) |
| std::optional< AddressPosition > | FindAddressEntry_ (const CAddress &addr) EXCLUSIVE_LOCKS_REQUIRED(cs) |
| size_t | Size_ (std::optional< Network > net, std::optional< bool > in_new) const 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. | |
| uint256 | nKey |
| secret key to randomize bucket select with | |
| std::set< nid_type > | m_tried_collisions |
| Holds addrs inserted into tried table that collide with existing entries. Test-before-evict discipline used to resolve these collisions. | |
| const int32_t | m_consistency_check_ratio |
| Perform consistency checks every m_consistency_check_ratio operations (if non-zero). | |
| const NetGroupManager & | m_netgroupman |
| Reference to the netgroup manager. | |
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 | AddrManDeterministic |
Definition at line 107 of file addrman_impl.h.
|
private |
Serialization versions.
Definition at line 166 of file addrman_impl.h.
| AddrManImpl::AddrManImpl | ( | const NetGroupManager & | netgroupman, |
| bool | deterministic, | ||
| int32_t | consistency_check_ratio | ||
| ) |
| AddrManImpl::~AddrManImpl | ( | ) |
|
private |
Definition at line 662 of file addrman.cpp.
|
private |
Attempt to add a single address to addrman's new table.
Definition at line 531 of file addrman.cpp.
| void AddrManImpl::Attempt | ( | const CService & | addr, |
| bool | fCountFailure, | ||
| NodeSeconds | time | ||
| ) |
|
private |
Definition at line 674 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 1037 of file addrman.cpp.
|
private |
Perform consistency check, regardless of m_consistency_check_ratio.
Definition at line 1052 of file addrman.cpp.
Clear a position in a "new" table. This is the only place where entries are actually deleted.
Definition at line 454 of file addrman.cpp.
| void AddrManImpl::Connected | ( | const CService & | addr, |
| NodeSeconds | time | ||
| ) |
|
private |
Definition at line 865 of file addrman.cpp.
|
private |
Create a new entry and add it to the internal data structures mapInfo, mapAddr and vRandom.
Definition at line 397 of file addrman.cpp.
Delete an entry. It must not be in tried, and have refcount 0.
Definition at line 437 of file addrman.cpp.
Find an entry.
Definition at line 382 of file addrman.cpp.
| std::optional< AddressPosition > AddrManImpl::FindAddressEntry | ( | const CAddress & | addr | ) |
|
private |
Definition at line 992 of file addrman.cpp.
|
private |
Definition at line 800 of file addrman.cpp.
| std::vector< std::pair< AddrInfo, AddressPosition > > AddrManImpl::GetEntries | ( | bool | from_tried | ) | const |
|
private |
Definition at line 841 of file addrman.cpp.
Helper to generalize looking up an addrman entry from either table.
Definition at line 783 of file addrman.cpp.
| bool AddrManImpl::Good | ( | const CService & | addr, |
| NodeSeconds | time | ||
| ) |
|
private |
Definition at line 607 of file addrman.cpp.
|
mutableprivate |
Source of random numbers for randomization in inner loops.
last used nId
Definition at line 189 of file addrman_impl.h.
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.
Definition at line 203 of file addrman_impl.h.
|
private |
list of "tried" buckets
number of (unique) "new" entries
Definition at line 209 of file addrman_impl.h.
|
private |
list of "new" buckets
|
inlineprivate |
last time Good was called (memory only). Initially set to 1 so that "never" is strictly worse.
Definition at line 215 of file addrman_impl.h.
|
private |
Number of entries in addrman per network and new/tried table.
Move an entry from the "new" table(s) to the "tried" table.
Definition at line 472 of file addrman.cpp.
| void AddrManImpl::ResolveCollisions | ( | ) |
|
private |
Definition at line 900 of file addrman.cpp.
| std::pair< CAddress, NodeSeconds > AddrManImpl::Select | ( | bool | new_only, |
| const std::unordered_set< Network > & | networks | ||
| ) | const |
|
private |
Definition at line 694 of file addrman.cpp.
| std::pair< CAddress, NodeSeconds > AddrManImpl::SelectTriedCollision | ( | ) |
|
private |
Definition at line 963 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 114 of file addrman.cpp.
| void AddrManImpl::SetServices | ( | const CService & | addr, |
| ServiceFlags | nServices | ||
| ) |
|
private |
Definition at line 884 of file addrman.cpp.
|
private |
Definition at line 1015 of file addrman.cpp.
Swap two elements in vRandom.
Definition at line 413 of file addrman.cpp.
|
friend |
Definition at line 153 of file addrman_impl.h.
|
mutableprivate |
A mutex to protect the inner data structures.
Definition at line 157 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 179 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 186 of file addrman_impl.h.
|
private |
Perform consistency checks every m_consistency_check_ratio operations (if non-zero).
Definition at line 221 of file addrman_impl.h.
|
private |
Reference to the netgroup manager.
netgroupman must be constructed before addrman and destructed after.
Definition at line 224 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 218 of file addrman_impl.h.
|
private |
secret key to randomize bucket select with
Definition at line 163 of file addrman_impl.h.