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 143 subscribers of this newsletter and to those who decided to contribute with some sats to this project. It means the world to me!
Last episode was focused on Onion proxy configuration. Today we are going to continue our trip inside the initialization of Bitcoin Core with the external IP. [Code Link]
Let’s start!
External IP
The following code snippet starts with a for
loop that iterates on all the arguments that are passed with the -externalip
input. This property tells the node what is its public IP address. In other words, it shows the “outside” world what is the IP address needed to connect to it.
for (const std::string& strAddr : args.GetArgs("-externalip")) {
Each input argument is stored inside the strAddr
string. The address is resolved by using the Lookup()
function, which takes as input strAddr
, the port returned by the GetListenPort()
function, and fNameLookup
, a previously set bool
that controls DNS resolution behavior. The function returns a std::optional<CService>
object which contains a value in case of successful lookup or it is empty otherwise.
const std::optional<CService> addrLocal{Lookup(strAddr, GetListenPort(), fNameLookup)};
The addrLocal
variable validity is checked to evaluate if it contains a value AND if the value is actually valid. These conditions must be true at the same time. If so, the AddLocal()
function is called, which signals the node the fact that it is now reachable from the outside with the specific strAddr
.
if (addrLocal.has_value() && addrLocal->IsValid())
AddLocal(addrLocal.value(), LOCAL_MANUAL);
else
return InitError(ResolveErrMsg("externalip", strAddr));
}
If the conditions resolves to false
, the else
clause is hit and an error is returned. This can happen in case a wrong IP is passed as an argument.
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.
Zap me a coffee and leave me a message: tuma@wallet.yakihonne.com