IBC#032: Bitcoin Core Initialization, Step 12: Special Permissions
Granting special permissions and some final checks
Hello everyone and welcome to this new episode of Inside Bitcoin Code.
We concluded the previous episode with discussing about the different connection options. Today, we continue our deep dive into step 12 of the initialization of Bitcoin Core, discussing about ports binding. [Code Link]
Let’s start!
-whitebind Input Argument
After checking the -bind input arguments, the code proceeds at retrieving user’s inputs set through the -whitebind argument. While in the first case the node is just listening on the designated ports, the latter argument allows to whitelist addresses and to grant them special permissions, such as bloomfilter (node will accept bloom filters requests), noban (peer will never be banned), forcerelay (node will always relay transactions from the peer even if they violates standard policies), relay (node will accept and relay transaction from peer, overriding -blocksonly), and mempool (Allows peer to query the node mempool).
The program iterates with a range-based for loop over all the -whitebind input arguments provided by the user, saving the address in the strBind string.
for (const std::string& strBind : args.GetArgs(”-whitebind”)) {
.
.
.
}
Then, a NetWhitebindPermissions object, which will store the address and the permissions granted, and a bilingual_str string, containing the error message, are declared.
NetWhitebindPermissions whitebind;
bilingual_str error;
The provided IP address is passed to the TryParse() function, which returns true if there is no issue with the user’s input.
If the function returns true, the NetWhitebindPermissions object is added to the vWhiteBinds vector, otherwise an InitError is returned.
if (!NetWhitebindPermissions::TryParse(strBind, whitebind, error))
return InitError(error);
connOptions.vWhiteBinds.push_back(whitebind);
Consider supporting this newsletter by using one of my affiliate links. These are not sponsorships, just products I use everyday. Thank you!
Final Checks
Then, the code makes some checks to understand if node should activate the default connections and to be sure that no “bad port” has been provided by mistake.
First of all, the program checks whether the user has provided any specific address. If not, the code will automatically trigger the default behavior by making the node listen on any port.
Thus, bind_on_any, a boolean value, is set to true only if both -bind and -whitebind inputs are empty().
// If the user did not specify -bind= or -whitebind= then we bind
// on any address - 0.0.0.0 (IPv4) and :: (IPv6).
connOptions.bind_on_any = args.GetArgs(”-bind”).empty() && args.GetArgs(
”-whitebind”).empty();
Then, in case bind_on_any resolves to true the -port arguments is checked. This user’s input is ignored in case any address has been provided either with -bind or
-whitebind.
Thus, the code checks that bind_on_any is true and that a -port input has been provided.
// Emit a warning if a bad port is given to -port= but only if -bind and -whitebind are not
// given, because if they are, then -port= is ignored.
if (connOptions.bind_on_any && args.IsArgSet(”-port”)) {
.
.
.
}
If so, the port number is stored in the port_arg variable. The port is checked against the “bad ports” list and in case it matches one of them a warning is launched using the lambda function discussed in IBC#31
const uint16_t port_arg = args.GetIntArg(”-port”, 0);
if (IsBadPort(port_arg)) {
InitWarning(BadPortWarning(”-port”, port_arg));
}
Hey Bitcoiner!
Inside Bitcoin Code is free for all to enjoy and will always be! If you want to support my work, consider zapping some sats via Lightning. ⚡
And remember: never trust, always verify!
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!