Hello everyone and welcome to this new episode of Inside Bitcoin Code.
This is the first episode of the newsletter coming officially on Nostr!
Today we start diving into step 12 of the initialization of Bitcoin Core. [Code Link]
Let’s start!
NAT-PMP
First, the program tries to automatically forward the node listening port through your router using NAT-PMP, so other peers on the internet can reach you without manual port forwarding.
Briefly, NAT-PMP allows a software to ask the router to open a port and forward it back to the computer automatically. In simpler terms, your node will ask the router to forward every connection coming to the external router port to the node local port.
Thus, the code retrieves the value of the -natpmp argument, which can be either 0 or 1. The GetBoolArg() function transforms the integer number into a boolean value, which is then fed to the StartMapPort(). In case the bool resolves to true, the function will launch the automatic port-forwarding process.
// Map ports with NAT-PMP
StartMapPort(args.GetBoolArg(”-natpmp”, DEFAULT_NATPMP));
Consider supporting this newsletter by using one of my affiliate links. These are not sponsorships, just products I use everyday. Thank you!
Connection Manager Options
Then, the software initializes a CConnman::Options object. connOptions holds all the settings needed by the connection manager.
CConnman::Options connOptions;
Here is the list:
-
m_local_services: It advertises what services this node offers, contained ing_local_services, discussed in IBC#024.connOptions.m_local_services = g_local_services; -
m_max_automatic_connections: It sets the max amount of peers that can be automatically connected at once. This is set through the-maxconnectionsinput argument.connOptions.m_max_automatic_connections = nMaxConnections; -
uiInterface: A pointer to theCClientUIInterfaceobject to allow the connection manager to send updates to the UI.connOptions.uiInterface = &uiInterface; -
m_banman: A pointer to the ban manager, so that connection manager can deal with banned peers.connOptions.m_banman = node.banman.get(); -
m_msgproc: A pointer to the interface handling messages,NetEventsInterface.connOptions.m_msgproc = node.peerman.get(); -
nSendBufferMaxSize: It sets per-peer send buffer limits in bytes, a defined by the input argument-maxsendbuffer.connOptions.nSendBufferMaxSize = 1000 * args.GetIntArg(”-maxsendbuffer”, DEFAULT_MAXSENDBUFFER); -
nReceiveFloodSize: It sets per-peer receive buffer limits in bytes, a defined by the input argument-maxreceivebuffer.connOptions.nReceiveFloodSize = 1000 * args.GetIntArg(”-maxreceivebuffer”, DEFAULT_MAXRECEIVEBUFFER); -
m_added_node: Astd::vectorof IP addresses of nodes to connect to defined by the-addonodeinput argument.connOptions.m_added_nodes = args.GetArgs(”-addnode”); -
nMaxOutboundLimit: It sets the limit to outbound traffic as defined by the
-maxuploadtargetinput argument.connOptions.nMaxOutboundLimit = *opt_max_upload; -
m_peer_contact_timeout: It specifies the amount of time a peer may be inactive before the connection to it is dropped, as defined by the
-peertimeoutinput argument.connOptions.m_peer_connect_timeout = peer_connect_timeout; -
whitelist_forcerelay: It forces the node to accept relayed transactions received from whitelisted peers. This is set tofalseby default, since the-whitelistforcerelayconfiguration parameter has been removed in v0.20.0.connOptions.whitelist_forcerelay = args.GetBoolArg(”-whitelistforcerelay”, DEFAULT_WHITELISTFORCERELAY); -
whitelist_relay: It sets whether accepting relayed transactions received from whitelisted peers even when not relaying transactions, as defined by the
-whitelistrelayinput argument.connOptions.whitelist_relay = args.GetBoolArg(”-whitelistrelay”, DEFAULT_WHITELISTRELAY);
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.
- Zap me a coffee and leave me a message!