IBC#035: Bitcoin Core Initialization, Step 12: Setting Outgoing Connections
The -connect input argument
Hello everyone and welcome to this new episode of Inside Bitcoin Code.
A special welcome to the new people that recently subscribed to this newsletter, I hope that you will enjoy what I write. A small suggestion for you: if you know nothing about coding, start reading the posts from Learn2Code to get some basic knowledge before diving in the real deal.
A huge thanks to each of the 212 subscribers of this newsletter and to those who decided to contribute with some sats to this project. It means the world to me!
We concluded the previous episode with discussing about port bindings. Today, we continue our deep dive into step 12 of the initialization of Bitcoin Core, discussing about the .connect input argument. [Code Link]
Let’s start!
-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.1Since, 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");Hey Bitcoiner!
If you are here with me diving into the Bitcoin code, consider tipping some sats via Lightning to support the series. ⚡
And remember: never trust, always verify!
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.



