The Network Address Manager: Understanding `AddrMan`
14. The Network Address Manager: Understanding AddrMan
We have seen how nodes "Gossip" about addresses (Chapter 5). But where do those addresses live when the node is sleeping? They live in the Network Address Manager (AddrMan). This is the "Long-Term Memory" of the networking layer. It is a sophisticated database that keeps track of thousands of potential peers and "Ranks" them based on their reliability.
For the Sovereign Architect, AddrMan is the "Map of the Universe." A healthy AddrMan contains addresses from every corner of the planet, every type of network (IPv4, IPv6, Tor, I2P), and every level of "Age." This diversity is what prevents your node from being "Isolated."
Analyzing the Memory: AddrMan
In the source code (src/addrman.h), we see how the node organizes its contacts into "Buckets" to prevent a single attacker from filling the entire list.
/**
* PEDAGOGICAL ANALYSIS: THE MAP OF THE UNIVERSE
* This logic organizes thousands of addresses into "Buckets" to ensure diversity.
*/
class AddrMan
{
public:
// The "New" bucket: Peers we have heard about but NEVER talked to.
// The "Tried" bucket: Peers we have SUCCESSFULLY connected to.
// This function adds a new address to the manager.
void Add(const std::vector<CAddress>& vAddr, const CNetAddr& source, ...);
// This function selects a random address for us to call (Outbound).
CAddress Select();
// This function "Rewards" a peer for being alive.
void Good(const CService& addr, ...);
};
Explaining the Memory: The Librarian’s Sorting
-
"The Buckets": Imagine a room with 1024 "Boxes." When a new address arrives, the node uses a "Hash" of its IP address and the person who told you about it to decide which box to put it in. This "Random Sorting" ensures that a hacker cannot "Predict" where their fake addresses will end up. It is the Entropy of the Sovereign.
-
"New" vs "Tried": When you first hear about an address, it goes in the "New" box. It stays there until you successfully connect to it. Once you have "Tried" it and it works, it is "Promoted" to the "Tried" box. The node favors "Tried" peers because they are proven to be real. It is the Meritocracy of the neighborhood.
-
Good(): Every time a peer answers your "Ping," the node callsGood(). This "Updates the Clock" for that address. Addresses that haven't been "Good" in months are eventually "Evicted" (Chapter 9) to make room for fresh blood. It is the Pruning of the Memory. -
"The Anchor File" (
anchors.dat): When you shut down your node, it saves a small list of its "Best Friends" in a special file. When you start back up, it calls these friends first to get a "Quick Start." It is the Warmth of the Welcome.
The Sovereignty of the Map
Your AddrMan is your "Security Perimeter." By maintaining a diverse and healthy list of peers, you are making it impossible for a central authority to "Censor" your connection to the blockchain. As a Sovereign Architect, you are the "Master of the Map," the one who ensures the "Digital Memory" of your machine is always rich, diverse, and accurate. You are the "Guardian of the Neighborhood."
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: