Stochastic address manager
Declared in <addrman.h>
class AddrMan;
Design goals: * 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 that can each store up to 64 entries. * Addresses to which our node has not successfully connected go into 1024 "new" buckets. * Based on the address range (/16 for IPv4) of the source of information, or if an asmap is provided, the AS it belongs to (for IPv4/IPv6), 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. * The position in the bucket is chosen based on the full address. * 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 an occupied position of a bucket, it will not replace the existing entry unless that address is also stored in another bucket or it doesn't meet one of several quality criteria (see IsTerrible for exact criteria). * Addresses of nodes that are known to be accessible go into 256 "tried" buckets. * Each address range selects at random 8 of these buckets. * The actual bucket is chosen from one of these, based on the full address. * When adding a new good address to an occupied position of a bucket, a FEELER connection to the old address is attempted. The old entry is only replaced and moved back to the "new" buckets if this attempt was unsuccessful. * Bucket selection is based on cryptographic hashing, using a randomly-generated 256-bit key, which should not be observable by adversaries. * Several indexes are kept for high performance. Setting m_consistency_check_ratio with the -checkaddrman configuration option will introduce (expensive) consistency checks for the entire data structure.
| Name | Description |
|---|---|
AddrMan [constructor] | Constructs an address manager over the given network group mapping. |
~AddrMan [destructor] | Destroys the address manager and its underlying tables. |
Add | Attempt to add one or more addresses to addrman's new table. If an address already exists in addrman, the existing entry may be updated (e.g. adding additional service flags). If the existing entry is in the new table, it may be added to more buckets, improving the probability of selection. |
Attempt | Mark an entry as connection attempted to. |
Connected | We have successfully connected to this peer. Calling this function updates the CAddress's nTime, which is used in our IsTerrible() decisions and gossiped to peers. Callers should be careful that updating this information doesn't leak topology information to network spies. |
FindAddressEntry | Test-only function Find the address record in AddrMan and return information about its position. |
GetAddr | Return all or many randomly selected addresses, optionally by network. |
GetEntries | Returns an information-location pair for all addresses in the selected addrman table. If an address appears multiple times in the new table, an information-location pair is returned for each occurrence. Addresses only ever appear once in the tried table. |
Good | Mark an address record as accessible and attempt to move it to addrman's tried table. |
ResolveCollisions | See if any to-be-evicted tried table entries have been tested and if so resolve the collisions. |
Select | Choose an address to connect to. |
SelectTriedCollision | Randomly select an address in the tried table that another address is attempting to evict. |
Serialize | Serializes the entire address manager state to a stream. |
SetServices | Update an entry's service bits. |
Size | Return size information about addrman. |
Unserialize | Deserializes the address manager state from a stream. |
| Name | Description |
|---|---|
m_impl | Owning pointer to the private implementation holding the address tables. |
| Name | Description |
|---|---|
EnsureAddrman | Get the address manager from a node context, asserting it is present. |
EnsureAnyAddrman | Get the address manager from an opaque RPC context, asserting it is present. |
ReadFromStream | Reads peer addresses from a stream into the address manager. |