Bitcoin Core  22.99.0
P2P Digital Currency
Public Member Functions | Private Attributes | Friends | List of all members
AddrMan Class Reference

Stochastic address manager. More...

#include <addrman.h>

Inheritance diagram for AddrMan:
[legend]

Public Member Functions

 AddrMan (std::vector< bool > asmap, bool deterministic, int32_t consistency_check_ratio)
 
 ~AddrMan ()
 
template<typename Stream >
void Serialize (Stream &s_) const
 
template<typename Stream >
void Unserialize (Stream &s_)
 
size_t size () const
 Return the number of (unique) addresses in all tables. More...
 
bool Add (const std::vector< CAddress > &vAddr, const CNetAddr &source, int64_t nTimePenalty=0)
 Add addresses to addrman's new table. More...
 
void Good (const CService &addr, int64_t nTime=GetAdjustedTime())
 Mark an entry as accessible, possibly moving it from "new" to "tried". More...
 
void Attempt (const CService &addr, bool fCountFailure, int64_t nTime=GetAdjustedTime())
 Mark an entry as connection attempted to. More...
 
void ResolveCollisions ()
 See if any to-be-evicted tried table entries have been tested and if so resolve the collisions. More...
 
std::pair< CAddress, int64_t > SelectTriedCollision ()
 Randomly select an address in the tried table that another address is attempting to evict. More...
 
std::pair< CAddress, int64_t > Select (bool newOnly=false) const
 Choose an address to connect to. More...
 
std::vector< CAddressGetAddr (size_t max_addresses, size_t max_pct, std::optional< Network > network) const
 Return all or many randomly selected addresses, optionally by network. More...
 
void Connected (const CService &addr, int64_t nTime=GetAdjustedTime())
 We have successfully connected to this peer. More...
 
void SetServices (const CService &addr, ServiceFlags nServices)
 Update an entry's service bits. More...
 
const std::vector< bool > & GetAsmap () const
 

Private Attributes

const std::unique_ptr< AddrManImplm_impl
 

Friends

class AddrManTest
 
class AddrManDeterministic
 

Detailed Description

Stochastic address manager.

Design goals:

To that end:

Definition at line 54 of file addrman.h.

Constructor & Destructor Documentation

◆ AddrMan()

AddrMan::AddrMan ( std::vector< bool >  asmap,
bool  deterministic,
int32_t  consistency_check_ratio 
)
explicit

Definition at line 1113 of file addrman.cpp.

◆ ~AddrMan()

AddrMan::~AddrMan ( )
default

Member Function Documentation

◆ Add()

bool AddrMan::Add ( const std::vector< CAddress > &  vAddr,
const CNetAddr source,
int64_t  nTimePenalty = 0 
)

Add addresses to addrman's new table.

Definition at line 1144 of file addrman.cpp.

Here is the caller graph for this function:

◆ Attempt()

void AddrMan::Attempt ( const CService addr,
bool  fCountFailure,
int64_t  nTime = GetAdjustedTime() 
)

Mark an entry as connection attempted to.

Definition at line 1154 of file addrman.cpp.

Here is the caller graph for this function:

◆ Connected()

void AddrMan::Connected ( const CService addr,
int64_t  nTime = GetAdjustedTime() 
)

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.

net_processing calls this function when it disconnects from a peer to not leak information about currently connected peers.

Parameters
[in]addrThe address of the peer we were connected to
[in]nTimeThe time that we were last connected to this peer

Definition at line 1179 of file addrman.cpp.

Here is the caller graph for this function:

◆ GetAddr()

std::vector< CAddress > AddrMan::GetAddr ( size_t  max_addresses,
size_t  max_pct,
std::optional< Network network 
) const

Return all or many randomly selected addresses, optionally by network.

Parameters
[in]max_addressesMaximum number of addresses to return (0 = all).
[in]max_pctMaximum percentage of addresses to return (0 = all).
[in]networkSelect only addresses of this network (nullopt = all).
Returns
A vector of randomly selected addresses from vRandom.

Definition at line 1174 of file addrman.cpp.

Here is the caller graph for this function:

◆ GetAsmap()

const std::vector< bool > & AddrMan::GetAsmap ( ) const

Definition at line 1189 of file addrman.cpp.

Here is the caller graph for this function:

◆ Good()

void AddrMan::Good ( const CService addr,
int64_t  nTime = GetAdjustedTime() 
)

Mark an entry as accessible, possibly moving it from "new" to "tried".

Definition at line 1149 of file addrman.cpp.

Here is the caller graph for this function:

◆ ResolveCollisions()

void AddrMan::ResolveCollisions ( )

See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.

Definition at line 1159 of file addrman.cpp.

Here is the caller graph for this function:

◆ Select()

std::pair< CAddress, int64_t > AddrMan::Select ( bool  newOnly = false) const

Choose an address to connect to.

Parameters
[in]newOnlyWhether to only select addresses from the new table.
Returns
CAddress The record for the selected peer. int64_t The last time we attempted to connect to that peer.

Definition at line 1169 of file addrman.cpp.

Here is the caller graph for this function:

◆ SelectTriedCollision()

std::pair< CAddress, int64_t > AddrMan::SelectTriedCollision ( )

Randomly select an address in the tried table that another address is attempting to evict.

Returns
CAddress The record for the selected tried peer. int64_t The last time we attempted to connect to that peer.

Definition at line 1164 of file addrman.cpp.

Here is the caller graph for this function:

◆ Serialize()

template<typename Stream >
template void AddrMan::Serialize ( Stream &  s_) const

Definition at line 1119 of file addrman.cpp.

Here is the caller graph for this function:

◆ SetServices()

void AddrMan::SetServices ( const CService addr,
ServiceFlags  nServices 
)

Update an entry's service bits.

Definition at line 1184 of file addrman.cpp.

Here is the caller graph for this function:

◆ size()

size_t AddrMan::size ( ) const

Return the number of (unique) addresses in all tables.

Definition at line 1139 of file addrman.cpp.

Here is the caller graph for this function:

◆ Unserialize()

template<typename Stream >
template void AddrMan::Unserialize ( Stream &  s_)

Definition at line 1125 of file addrman.cpp.

Friends And Related Function Documentation

◆ AddrManDeterministic

friend class AddrManDeterministic
friend

Definition at line 132 of file addrman.h.

◆ AddrManTest

friend class AddrManTest
friend

Definition at line 131 of file addrman.h.

Member Data Documentation

◆ m_impl

const std::unique_ptr<AddrManImpl> AddrMan::m_impl
private

Definition at line 56 of file addrman.h.


The documentation for this class was generated from the following files: