Bitcoin Core 28.99.0
P2P Digital Currency
|
Stochastic address manager. More...
#include <addrman.h>
Public Member Functions | |
AddrMan (const NetGroupManager &netgroupman, 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 (std::optional< Network > net=std::nullopt, std::optional< bool > in_new=std::nullopt) const |
Return size information about addrman. More... | |
bool | Add (const std::vector< CAddress > &vAddr, const CNetAddr &source, std::chrono::seconds time_penalty=0s) |
Attempt to add one or more addresses to addrman's new table. More... | |
bool | Good (const CService &addr, NodeSeconds time=Now< NodeSeconds >()) |
Mark an address record as accessible and attempt to move it to addrman's tried table. More... | |
void | Attempt (const CService &addr, bool fCountFailure, NodeSeconds time=Now< NodeSeconds >()) |
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, NodeSeconds > | SelectTriedCollision () |
Randomly select an address in the tried table that another address is attempting to evict. More... | |
std::pair< CAddress, NodeSeconds > | Select (bool new_only=false, const std::unordered_set< Network > &networks={}) const |
Choose an address to connect to. More... | |
std::vector< CAddress > | GetAddr (size_t max_addresses, size_t max_pct, std::optional< Network > network, const bool filtered=true) const |
Return all or many randomly selected addresses, optionally by network. More... | |
std::vector< std::pair< AddrInfo, AddressPosition > > | GetEntries (bool from_tried) const |
Returns an information-location pair for all addresses in the selected addrman table. More... | |
void | Connected (const CService &addr, NodeSeconds time=Now< NodeSeconds >()) |
We have successfully connected to this peer. More... | |
void | SetServices (const CService &addr, ServiceFlags nServices) |
Update an entry's service bits. More... | |
std::optional< AddressPosition > | FindAddressEntry (const CAddress &addr) |
Test-only function Find the address record in AddrMan and return information about its position. More... | |
Protected Attributes | |
const std::unique_ptr< AddrManImpl > | m_impl |
Stochastic address manager.
Design goals:
To that end:
|
explicit |
Definition at line 1272 of file addrman.cpp.
|
default |
bool AddrMan::Add | ( | const std::vector< CAddress > & | vAddr, |
const CNetAddr & | source, | ||
std::chrono::seconds | time_penalty = 0s |
||
) |
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.
[in] | vAddr | Address records to attempt to add. |
[in] | source | The address of the node that sent us these addr records. |
[in] | time_penalty | A "time penalty" to apply to the address record's nTime. If a peer sends us an address record with nTime=n, then we'll add it to our addrman with nTime=(n - time_penalty). |
Definition at line 1302 of file addrman.cpp.
void AddrMan::Attempt | ( | const CService & | addr, |
bool | fCountFailure, | ||
NodeSeconds | time = Now<NodeSeconds>() |
||
) |
Mark an entry as connection attempted to.
Definition at line 1312 of file addrman.cpp.
void AddrMan::Connected | ( | const CService & | addr, |
NodeSeconds | time = Now<NodeSeconds>() |
||
) |
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.
[in] | addr | The address of the peer we were connected to |
[in] | time | The time that we were last connected to this peer |
Definition at line 1342 of file addrman.cpp.
std::optional< AddressPosition > AddrMan::FindAddressEntry | ( | const CAddress & | addr | ) |
Test-only function Find the address record in AddrMan and return information about its position.
[in] | addr | The address record to look up. |
Definition at line 1352 of file addrman.cpp.
std::vector< CAddress > AddrMan::GetAddr | ( | size_t | max_addresses, |
size_t | max_pct, | ||
std::optional< Network > | network, | ||
const bool | filtered = true |
||
) | const |
Return all or many randomly selected addresses, optionally by network.
[in] | max_addresses | Maximum number of addresses to return (0 = all). |
[in] | max_pct | Maximum percentage of addresses to return (0 = all). Value must be from 0 to 100. |
[in] | network | Select only addresses of this network (nullopt = all). |
[in] | filtered | Select only addresses that are considered good quality (false = all). |
Definition at line 1332 of file addrman.cpp.
std::vector< std::pair< AddrInfo, AddressPosition > > AddrMan::GetEntries | ( | bool | from_tried | ) | const |
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.
[in] | from_tried | Selects which table to return entries from. |
Definition at line 1337 of file addrman.cpp.
bool AddrMan::Good | ( | const CService & | addr, |
NodeSeconds | time = Now<NodeSeconds>() |
||
) |
Mark an address record as accessible and attempt to move it to addrman's tried table.
[in] | addr | Address record to attempt to move to tried table. |
[in] | time | The time that we were last connected to this peer. |
Definition at line 1307 of file addrman.cpp.
void AddrMan::ResolveCollisions | ( | ) |
See if any to-be-evicted tried table entries have been tested and if so resolve the collisions.
Definition at line 1317 of file addrman.cpp.
std::pair< CAddress, NodeSeconds > AddrMan::Select | ( | bool | new_only = false , |
const std::unordered_set< Network > & | networks = {} |
||
) | const |
Choose an address to connect to.
[in] | new_only | Whether to only select addresses from the new table. Passing true returns an address from the new table or an empty pair. Passing false will return an empty pair or an address from either the new or tried table (it does not guarantee a tried entry). |
[in] | networks | Select only addresses of these networks (empty = all). Passing networks may slow down the search. |
Definition at line 1327 of file addrman.cpp.
std::pair< CAddress, NodeSeconds > AddrMan::SelectTriedCollision | ( | ) |
Randomly select an address in the tried table that another address is attempting to evict.
Definition at line 1322 of file addrman.cpp.
template void AddrMan::Serialize | ( | Stream & | s_ | ) | const |
Definition at line 1278 of file addrman.cpp.
void AddrMan::SetServices | ( | const CService & | addr, |
ServiceFlags | nServices | ||
) |
Update an entry's service bits.
Definition at line 1347 of file addrman.cpp.
size_t AddrMan::Size | ( | std::optional< Network > | net = std::nullopt , |
std::optional< bool > | in_new = std::nullopt |
||
) | const |
Return size information about addrman.
[in] | net | Select addresses only from specified network (nullopt = all) |
[in] | in_new | Select addresses only from one table (true = new, false = tried, nullopt = both) |
Definition at line 1297 of file addrman.cpp.
template void AddrMan::Unserialize | ( | Stream & | s_ | ) |
Definition at line 1284 of file addrman.cpp.
|
protected |