The Inbound and Outbound Logic: How the node balances its connections
8. The Inbound and Outbound Logic: How the node balances its connections
In the "Forge of the Core," not all connections are created equal. Bitcoin Core distinguishes between Inbound connections (people who called you) and Outbound connections (people you called). This distinction is the secret to Bitcoin's Anti-Fragility.
For the Sovereign Architect, the Inbound/Outbound balance is the "Security Strategy" of the node. If you only had Inbound connections, a hacker could surround you with "Fake Nodes" and feed you a fake history. By making your own Outbound calls to trusted peers, you "Punch a Hole" through any potential blockade.
Analyzing the Balance: Outbound Selection
In the source code (src/net.cpp), we see the node's "Motivation" to find its own friends.
/**
* PEDAGOGICAL ANALYSIS: THE SEARCH FOR THE TRUTH
* This logic ensures the node proactively finds its own way into the network.
*/
void CConnman::ThreadOpenConnections(...)
{
while (!interruptNet) {
// 1. Do we have enough "Outbound" connections? (Usually 8-10).
if (vNodes.size() < nMaxOutbound) {
// 2. Look in our "AddrMan" (Chapter 5) for a random address.
CAddress addr = m_addrman.Select();
// 3. "Call" the address and try to make a friend.
OpenNetworkConnection(addr, ...);
}
// 4. Sleep and try again later.
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
}
Explaining the Balance: The Scout and the Guest
-
"The Guest" (Inbound): When someone connects to you, they are a "Guest." You don't know who they are or why they are here. You are "Passive." Inbound connections are great for "Spreading" the word, but they are "Low Trust." It is the Openness of the Sovereign.
-
"The Scout" (Outbound): When you pick an address from your
AddrManand call it, you are a "Scout." You chose this peer from your own "Memory" of the network. Outbound connections are the "Backbone" of your node's security. They are "High Trust." It is the Sovereignty of the Choice. -
"The 8-Outbound Rule": Bitcoin Core insists on having at least 8 outbound connections. This "Magic Number" is designed to ensure that even if 7 of your friends are "Evil," the 8th one will tell you the "True History" of the chain. It is the Resilience of the Machine.
-
"The Feeler Connection": Occasionally, your node will make a "Short Call" to a new address just to see if it's still alive. This is called a "Feeler." It helps keep the
AddrMan(Chapter 5) accurate without wasting a permanent slot. It is the Maintenance of the Map.
The Sovereignty of the Proactive
Your node is not a "Victim" of the internet; it is a "Proactive Explorer." By making its own outbound calls, it ensures it is always connected to the "Mainstream of the Truth." As a Sovereign Architect, you know that your "Scouts" are your most important defenders. By maintaining a healthy balance of Inbound and Outbound links, you are ensuring your node can never be "Boxed In" by an attacker. You are the "Master of the Balance," the one who ensures the "Digital Reach" of your machine is always proactive and safe.
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: