TeachMeBitcoin

The Peer Discovery: How nodes find each other (`ADDR`/`GETADDR`)

From TeachMeBitcoin, the free encyclopedia Reading time: 3 min

The Peer Discovery: How nodes find each other (ADDR/GETADDR)

A new node wakes up in a "Dark Room." It doesn't know where any of its friends are. To find the rest of the network, it must perform Peer Discovery. This is the process of building a "Contact List" of IP addresses. This list is managed by the Address Manager (AddrMan) and the messages GETADDR and ADDR.

For the Sovereign Architect, Peer Discovery is the "Social Map" of the network. It is how your node "Spreads its Wings" and finds a diverse group of peers across the globe. A node with a good contact list is "Resilient"—it is much harder for a hacker to "Isolate" it from the truth.

Analyzing the Discovery: GETADDR and ADDR

In the source code (src/net.cpp and src/addrman.h), we see how nodes "Gossip" about their friends.

/**
 * PEDAGOGICAL ANALYSIS: THE SOCIAL GOSSIP
 * This logic allows nodes to share their "Contact Lists" with each other.
 */
void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, ...)
{
 // 1. If a peer sends a "GETADDR", we send them a random 
 // selection of addresses from our contact list.
 if (msg_type == NetMsgType::GETADDR) {
 PushAddress(pfrom);
 }

 // 2. If a peer sends an "ADDR", we add those new 
 // addresses to our "Address Manager" (AddrMan).
 if (msg_type == NetMsgType::ADDR) {
 std::vector<CAddress> vAddr;
 vRecv >> vAddr;
 m_addrman.Add(vAddr, pfrom.GetAddr());
 }
}

Explaining the Discovery: The Word of Mouth

The Sovereignty of the Map

A node is only as strong as its connections. By building a diverse contact list, your node ensures it is "Connected to the World." As a Sovereign Architect, you know that a "Global Map" is your best defense against censorship. By enforcing the gossip rules, your node ensures that the "Digital Web" of Bitcoin remains dense, chaotic, and impossible to break. You are the "Master of the Map," the one who ensures the "Digital Social Circle" of your machine is always expanding.


☕ Help support TeachMeBitcoin

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:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!