IBC#035: Bitcoin Core Initialization, Step 12: Setting Outgoing Connections
IBC-035-Bitcoin-Core-Initialization-Step-12-Setting-Outgoing-Connections-zbxtzk
tuma
Bitcoin, Freedom and my personal pursuit of Happiness Open-source Writer FOSS Reporter @ npub1z6dx97fxn94j3z9c3pvgsellnywqgakmj82d7rrr3jdlgy2nqgnq5uf7n9 Contributor @ npub1hkuk45c6c6h3y0rks0z4wa0wyyud5ru0qy0rn9x4dgnjwrnfy46s5a432p Tech Editor @ npub10pensatlcfwktnvjjw2dtem38n6rvw8g6fv73h84cuacxn4c28eqyfn34f Sometimes Photographer @ npub1m85lkfcs73qgpdmm5l5zsjr0wd2khccum6vl8u39v7dvt407tcdq6uxjkj
4 min read
Hello everyone and welcome to this new episode of Inside Bitcoin Code on Nostr!
We concluded the previous episode with discussing about whitelisting peers. Today, we continue our deep dive into step 12 of the initialization of Bitcoin Core, discussing about the -connect input argument. [Code Link]
-seednode and -connect
First of all, the code retrieves the -seednode input argument. This allows to connect directly to specific trusted nodes, defined by their IP address, to gather initial peer address when the node starts up:
seednode=192.168.0.1
Since, the input can be defined multiple times with different IP addresses, the GetArgs() function will return a vector.
connOptions.vSeedNodes = args.GetArgs("-seednode");
Then, the -connect input argument is retrieved. This allows a user to specify to which peers the node must connect to. No other connection will be opened.
const auto connect = args.GetArgs("-connect");
Consider supporting this newsletter by using one of my affiliate links. These are not sponsorships, just products I use everyday. Thank you!
Specify Outgoing Connections
After that, the code enters an if statement. The program checks whether the connect vector is not empty() — no -connect input as been provided — or the argument was originally passed as a negated option — -noconnect.
if (!connect.empty() || args.IsArgNegated("-connect")) {
.
.
.
}
If the clause resolves to true, the node is instructed to not initiate any other outgoing connection when connecting to trusted nodes, disabling the automatic peers discovery system.
connOptions.m_use_addrman_outgoing = false;
Then, the program checks that the connect vector has more than 1 element (remember, it cannot be 0, since we checked that it is not empty!), and that the first element of the provided input is not “0” (which means no connections at all).
If the clause resolves to true, connect is stored inside the m_specified_outgoing vector.
if (connect.size() != 1 || connect[0] != "0") {
connOptions.m_specified_outgoing = connect;
}
Warnings
When defining inputs for the node, we can have some arguments conflicting with others. Thus, there are some checks that make sure that only the correct ones are used.
Here, the programs checks if both -connect and -seednode have been defined. If so,
-seednode will be ignored, informing the user about this automatic decision. This is done because we explicitly defined which nodes to connect to, so, there is no need for seed nodes to bootstrap peer discovery.
if (!connOptions.m_specified_outgoing.empty()
&&!connOptions.vSeedNodes.empty()) {
LogInfo("-seednode is ignored when -connect is used");
}
The same happens in case -dnsseed is set, but at the same time both -connect and
-proxy are specified. If so, -dnseed will be ignored, informing the user about this automatic decision. This is done because the node is already configured to use explicit outgoing connections and a proxy, making automatic DNS-based discovery unnecessary or conflicting.
if (args.IsArgSet("-dnsseed")
&& args.GetBoolArg("-dnsseed", DEFAULT_DNSSEED)
&& args.IsArgSet("-proxy")) {
LogInfo("-dnsseed is ignored when -connect is used and -proxy is specified");
}
Affiliate Program
Ready to Lead the Change*? If you are looking to professionalize your journey in the Bitcoin ecosystem, the Plan B Network provides the ultimate educational framework. Whether you are aiming to build the next major startup or dive deep into the protocol’s code, they have a Master track for you. Use my code* SS_Varese at checkout to receive 15% OFF on both the Business and Developers tracks!
---
Let’s keep in touch:
-
Check out my writings on btc++ insider edition
-
Try my new app Sats Tracker, an expense tracker app for people living in the Bitcoin standard. Available on Zapstore!Affiliate Program
Ready to Lead the Change*? If you are looking to professionalize your journey in the Bitcoin ecosystem, the Plan B Network provides the ultimate educational framework. Whether you are aiming to build the next major startup or dive deep into the protocol’s code, they have a Master track for you. Use my code* SS_Varese at checkout to receive 15% OFF on both the Business and Developers tracks!
Let’s keep in touch:
Follow me on Nostr and X Check out my writings on btc++ insider edition Try my new app Sats Tracker, an expense tracker app for people living in the Bitcoin standard. Available on Zapstore!
Help keep these ideas circulating
This is an independent project. If you'd like to help support it, you can make a contribution. But there's no obligation at all. Reading, sharing, and coming back is already a form of support.
Read also
1
The onion service target and the Tor control thread

2
Default ports and "-bind" input argument

3
Granting special permissions and some final checks

Want to publish here too? No sign-up, and the text stays yours. Learn how to start
Replies (0)
Loading…
