Bitcoin Core  22.99.0
P2P Digital Currency
Classes | Variables
addrman.h File Reference
#include <fs.h>
#include <logging.h>
#include <netaddress.h>
#include <protocol.h>
#include <sync.h>
#include <timedata.h>
#include <cstdint>
#include <optional>
#include <set>
#include <unordered_map>
#include <vector>
Include dependency graph for addrman.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CAddrInfo
 Extended statistics about a CAddress. More...
 
class  CAddrMan
 Stochastical (IP) address manager. More...
 

Variables

static constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS {0}
 Default for -checkaddrman. More...
 
static constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2 {8}
 Stochastic address manager. More...
 
static constexpr int ADDRMAN_TRIED_BUCKET_COUNT {1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2}
 
static constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2 {10}
 Total number of buckets for new addresses. More...
 
static constexpr int ADDRMAN_NEW_BUCKET_COUNT {1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2}
 
static constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2 {6}
 Maximum allowed number of entries in buckets for new and tried addresses. More...
 
static constexpr int ADDRMAN_BUCKET_SIZE {1 << ADDRMAN_BUCKET_SIZE_LOG2}
 

Variable Documentation

◆ ADDRMAN_BUCKET_SIZE

constexpr int ADDRMAN_BUCKET_SIZE {1 << ADDRMAN_BUCKET_SIZE_LOG2}
staticconstexpr

Definition at line 137 of file addrman.h.

◆ ADDRMAN_BUCKET_SIZE_LOG2

constexpr int32_t ADDRMAN_BUCKET_SIZE_LOG2 {6}
staticconstexpr

Maximum allowed number of entries in buckets for new and tried addresses.

Definition at line 136 of file addrman.h.

◆ ADDRMAN_NEW_BUCKET_COUNT

constexpr int ADDRMAN_NEW_BUCKET_COUNT {1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2}
staticconstexpr

Definition at line 133 of file addrman.h.

◆ ADDRMAN_NEW_BUCKET_COUNT_LOG2

constexpr int32_t ADDRMAN_NEW_BUCKET_COUNT_LOG2 {10}
staticconstexpr

Total number of buckets for new addresses.

Definition at line 132 of file addrman.h.

◆ ADDRMAN_TRIED_BUCKET_COUNT

constexpr int ADDRMAN_TRIED_BUCKET_COUNT {1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2}
staticconstexpr

Definition at line 129 of file addrman.h.

◆ ADDRMAN_TRIED_BUCKET_COUNT_LOG2

constexpr int32_t ADDRMAN_TRIED_BUCKET_COUNT_LOG2 {8}
staticconstexpr

Stochastic address manager.

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. Total number of buckets for tried addresses

Definition at line 128 of file addrman.h.

◆ DEFAULT_ADDRMAN_CONSISTENCY_CHECKS

constexpr int32_t DEFAULT_ADDRMAN_CONSISTENCY_CHECKS {0}
staticconstexpr

Default for -checkaddrman.

Definition at line 23 of file addrman.h.