Bitcoin Core  0.20.99
P2P Digital Currency
Classes | Macros | Variables
addrman.h File Reference
#include <clientversion.h>
#include <netaddress.h>
#include <protocol.h>
#include <random.h>
#include <sync.h>
#include <timedata.h>
#include <util/system.h>
#include <fs.h>
#include <hash.h>
#include <iostream>
#include <map>
#include <set>
#include <stdint.h>
#include <streams.h>
#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...
 

Macros

#define ADDRMAN_TRIED_BUCKET_COUNT_LOG2   8
 Stochastic address manager. More...
 
#define ADDRMAN_NEW_BUCKET_COUNT_LOG2   10
 total number of buckets for new addresses More...
 
#define ADDRMAN_BUCKET_SIZE_LOG2   6
 maximum allowed number of entries in buckets for new and tried addresses More...
 
#define ADDRMAN_TRIED_BUCKETS_PER_GROUP   8
 over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread More...
 
#define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP   64
 over how many buckets entries with new addresses originating from a single group are spread More...
 
#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS   8
 in how many buckets for entries with new addresses a single address may occur More...
 
#define ADDRMAN_HORIZON_DAYS   30
 how old addresses can maximally be More...
 
#define ADDRMAN_RETRIES   3
 after how many failed attempts we give up on a new node More...
 
#define ADDRMAN_MAX_FAILURES   10
 how many successive failures are allowed ... More...
 
#define ADDRMAN_MIN_FAIL_DAYS   7
 ... in at least this many days More...
 
#define ADDRMAN_REPLACEMENT_HOURS   4
 how recent a successful connection should be before we allow an address to be evicted from tried More...
 
#define ADDRMAN_GETADDR_MAX_PCT   23
 the maximum percentage of nodes to return in a getaddr call More...
 
#define ADDRMAN_GETADDR_MAX   2500
 the maximum number of nodes to return in a getaddr call More...
 
#define ADDRMAN_TRIED_BUCKET_COUNT   (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2)
 Convenience. More...
 
#define ADDRMAN_NEW_BUCKET_COUNT   (1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2)
 
#define ADDRMAN_BUCKET_SIZE   (1 << ADDRMAN_BUCKET_SIZE_LOG2)
 
#define ADDRMAN_SET_TRIED_COLLISION_SIZE   10
 the maximum number of tried addr collisions to store More...
 

Variables

static const int64_t ADDRMAN_TEST_WINDOW = 40*60
 the maximum time we'll spend trying to resolve a tried table collision, in seconds More...
 

Macro Definition Documentation

◆ ADDRMAN_BUCKET_SIZE

#define ADDRMAN_BUCKET_SIZE   (1 << ADDRMAN_BUCKET_SIZE_LOG2)

Definition at line 165 of file addrman.h.

◆ ADDRMAN_BUCKET_SIZE_LOG2

#define ADDRMAN_BUCKET_SIZE_LOG2   6

maximum allowed number of entries in buckets for new and tried addresses

Definition at line 130 of file addrman.h.

◆ ADDRMAN_GETADDR_MAX

#define ADDRMAN_GETADDR_MAX   2500

the maximum number of nodes to return in a getaddr call

Definition at line 160 of file addrman.h.

◆ ADDRMAN_GETADDR_MAX_PCT

#define ADDRMAN_GETADDR_MAX_PCT   23

the maximum percentage of nodes to return in a getaddr call

Definition at line 157 of file addrman.h.

◆ ADDRMAN_HORIZON_DAYS

#define ADDRMAN_HORIZON_DAYS   30

how old addresses can maximally be

Definition at line 142 of file addrman.h.

◆ ADDRMAN_MAX_FAILURES

#define ADDRMAN_MAX_FAILURES   10

how many successive failures are allowed ...

Definition at line 148 of file addrman.h.

◆ ADDRMAN_MIN_FAIL_DAYS

#define ADDRMAN_MIN_FAIL_DAYS   7

... in at least this many days

Definition at line 151 of file addrman.h.

◆ ADDRMAN_NEW_BUCKET_COUNT

#define ADDRMAN_NEW_BUCKET_COUNT   (1 << ADDRMAN_NEW_BUCKET_COUNT_LOG2)

Definition at line 164 of file addrman.h.

◆ ADDRMAN_NEW_BUCKET_COUNT_LOG2

#define ADDRMAN_NEW_BUCKET_COUNT_LOG2   10

total number of buckets for new addresses

Definition at line 127 of file addrman.h.

◆ ADDRMAN_NEW_BUCKETS_PER_ADDRESS

#define ADDRMAN_NEW_BUCKETS_PER_ADDRESS   8

in how many buckets for entries with new addresses a single address may occur

Definition at line 139 of file addrman.h.

◆ ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP

#define ADDRMAN_NEW_BUCKETS_PER_SOURCE_GROUP   64

over how many buckets entries with new addresses originating from a single group are spread

Definition at line 136 of file addrman.h.

◆ ADDRMAN_REPLACEMENT_HOURS

#define ADDRMAN_REPLACEMENT_HOURS   4

how recent a successful connection should be before we allow an address to be evicted from tried

Definition at line 154 of file addrman.h.

◆ ADDRMAN_RETRIES

#define ADDRMAN_RETRIES   3

after how many failed attempts we give up on a new node

Definition at line 145 of file addrman.h.

◆ ADDRMAN_SET_TRIED_COLLISION_SIZE

#define ADDRMAN_SET_TRIED_COLLISION_SIZE   10

the maximum number of tried addr collisions to store

Definition at line 168 of file addrman.h.

◆ ADDRMAN_TRIED_BUCKET_COUNT

#define ADDRMAN_TRIED_BUCKET_COUNT   (1 << ADDRMAN_TRIED_BUCKET_COUNT_LOG2)

Convenience.

Definition at line 163 of file addrman.h.

◆ ADDRMAN_TRIED_BUCKET_COUNT_LOG2

#define ADDRMAN_TRIED_BUCKET_COUNT_LOG2   8

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.
    • Addresses that have not yet been tried go into 1024 "new" buckets.
      • Based on the address range (/16 for IPv4) of the source of information, 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.
      • 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 a full bucket, a randomly chosen entry (with a bias favoring less recently seen ones) is removed from it first.
    • 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 a full bucket, a randomly chosen entry (with a bias favoring less recently tried ones) is evicted from it, back to the "new" buckets.
    • 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. Defining DEBUG_ADDRMAN will introduce frequent (and expensive) consistency checks for the entire data structure.total number of buckets for tried addresses

Definition at line 124 of file addrman.h.

◆ ADDRMAN_TRIED_BUCKETS_PER_GROUP

#define ADDRMAN_TRIED_BUCKETS_PER_GROUP   8

over how many buckets entries with tried addresses from a single group (/16 for IPv4) are spread

Definition at line 133 of file addrman.h.

Variable Documentation

◆ ADDRMAN_TEST_WINDOW

const int64_t ADDRMAN_TEST_WINDOW = 40*60
static

the maximum time we'll spend trying to resolve a tried table collision, in seconds

Definition at line 171 of file addrman.h.