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 139 subscribers to this newsletter and to those who decided to contribute with some sats to this project. It means the world to me!
Today we are going to continue our trip inside the initialization of Bitcoin Core.
Let’s start!
The user agent string is a message that contains information about client implementation, architecture and operative system. The need for this kind of information came from the will to separate protocol and client versioning1 and is known as BIP-0014.2
The program checks the string passed with the -uacomment
and controls that all the characters contained in the message are safe. In case they are not, the function returns an error, otherwise they are added to a vector. [Code Link]
// sanitize comments per BIP-0014, format user agent and check total size
std::vector<std::string> uacomments;
for (const std::string& cmt : args.GetArgs("-uacomment")) {
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
uacomments.push_back(cmt);
}
This vector is checked in order to find the name and the version of the client used, and returns an error in case the string length is too long.
strSubVersion = FormatSubVersion(UA_NAME, CLIENT_VERSION, uacomments);
if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) {
return InitError(strprintf(_("Total length of network version string (%i) exceeds maximum length (%i). Reduce the number or size of uacomments."),
strSubVersion.size(), MAX_SUBVERSION_LENGTH));
}
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: tuma@wallet.yakihonne.com
With the term protocol we refer to the general implementation of the Bitcoin protocol, while client refer to the specific implementation of the software (i.e. Bitcoin Core, Knots, etc.)