[#AddrMan]
= AddrMan
:mrdocs:

Stochastic address manager

== Synopsis

Declared in `&lt;addrman&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class AddrMan;
----

== Description

Design goals&colon; &ast; Keep the address tables in&hyphen;memory, and asynchronously dump the entire table to peers&period;dat&period; &ast; Make sure no (localized) attacker can fill the entire table with his nodes&sol;addresses&period;

To that end&colon; &ast; Addresses are organized into buckets that can each store up to 64 entries&period; &ast; Addresses to which our node has not successfully connected go into 1024 &quot;new&quot; buckets&period; &ast; Based on the address range (&sol;16 for IPv4) of the source of information, or if an asmap is provided, the AS it belongs to (for IPv4&sol;IPv6), 64 buckets are selected at random&period; &ast; The actual bucket is chosen from one of these, based on the range in which the address itself is located&period; &ast; The position in the bucket is chosen based on the full address&period; &ast; One single address can occur in up to 8 different buckets to increase selection chances for addresses that are seen frequently&period; The chance for increasing this multiplicity decreases exponentially&period; &ast; 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&apos;t meet one of several quality criteria (see IsTerrible for exact criteria)&period; &ast; Addresses of nodes that are known to be accessible go into 256 &quot;tried&quot; buckets&period; &ast; Each address range selects at random 8 of these buckets&period; &ast; The actual bucket is chosen from one of these, based on the full address&period; &ast; When adding a new good address to an occupied position of a bucket, a FEELER connection to the old address is attempted&period; The old entry is only replaced and moved back to the &quot;new&quot; buckets if this attempt was unsuccessful&period; &ast; Bucket selection is based on cryptographic hashing, using a randomly&hyphen;generated 256&hyphen;bit key, which should not be observable by adversaries&period; &ast; Several indexes are kept for high performance&period; Setting m&lowbar;consistency&lowbar;check&lowbar;ratio with the &hyphen;checkaddrman configuration option will introduce (expensive) consistency checks for the entire data structure&period;

== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:AddrMan/2constructor.adoc[`AddrMan`]         [.small]#[constructor]#
| Constructs an address manager over the given network group mapping&period;
| xref:AddrMan/2destructor.adoc[`&#126;AddrMan`] [.small]#[destructor]#
| Destroys the address manager and its underlying tables&period;
| xref:AddrMan/Add.adoc[`Add`] 
| Attempt to add one or more addresses to addrman&apos;s new table&period; If an address already exists in addrman, the existing entry may be updated (e&period;g&period; adding additional service flags)&period; If the existing entry is in the new table, it may be added to more buckets, improving the probability of selection&period;
| xref:AddrMan/Attempt.adoc[`Attempt`] 
| Mark an entry as connection attempted to&period;
| xref:AddrMan/Connected.adoc[`Connected`] 
| We have successfully connected to this peer&period; Calling this function updates the CAddress&apos;s nTime, which is used in our IsTerrible() decisions and gossiped to peers&period; Callers should be careful that updating this information doesn&apos;t leak topology information to network spies&period;
| xref:AddrMan/FindAddressEntry.adoc[`FindAddressEntry`] 
| Test&hyphen;only function Find the address record in AddrMan and return information about its position&period;
| xref:AddrMan/GetAddr.adoc[`GetAddr`] 
| Return all or many randomly selected addresses, optionally by network&period;
| xref:AddrMan/GetEntries.adoc[`GetEntries`] 
| Returns an information&hyphen;location pair for all addresses in the selected addrman table&period; If an address appears multiple times in the new table, an information&hyphen;location pair is returned for each occurrence&period; Addresses only ever appear once in the tried table&period;
| xref:AddrMan/Good.adoc[`Good`] 
| Mark an address record as accessible and attempt to move it to addrman&apos;s tried table&period;
| xref:AddrMan/ResolveCollisions.adoc[`ResolveCollisions`] 
| See if any to&hyphen;be&hyphen;evicted tried table entries have been tested and if so resolve the collisions&period;
| xref:AddrMan/Select.adoc[`Select`] 
| Choose an address to connect to&period;
| xref:AddrMan/SelectTriedCollision.adoc[`SelectTriedCollision`] 
| Randomly select an address in the tried table that another address is attempting to evict&period;
| xref:AddrMan/Serialize.adoc[`Serialize`] 
| Serializes the entire address manager state to a stream&period;
| xref:AddrMan/SetServices.adoc[`SetServices`] 
| Update an entry&apos;s service bits&period;
| xref:AddrMan/Size.adoc[`Size`] 
| Return size information about addrman&period;
| xref:AddrMan/Unserialize.adoc[`Unserialize`] 
| Deserializes the address manager state from a stream&period;
|===


== Protected Data Members

[cols="1,4"]
|===
| Name| Description
| xref:AddrMan/m_impl.adoc[`m&lowbar;impl`] 
| Owning pointer to the private implementation holding the address tables&period;
|===


== Non-Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:EnsureAddrman.adoc[`EnsureAddrman`]
| Get the address manager from a node context, asserting it is present&period;
| xref:EnsureAnyAddrman.adoc[`EnsureAnyAddrman`]
| Get the address manager from an opaque RPC context, asserting it is present&period;
| xref:ReadFromStream.adoc[`ReadFromStream`]
| Reads peer addresses from a stream into the address manager&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
