Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 3,069 Lines • ▼ Show 20 Lines | |||||
std::string userAgent(const Config &config) { | std::string userAgent(const Config &config) { | ||||
// format excessive blocksize value | // format excessive blocksize value | ||||
std::string eb = getSubVersionEB(config.GetMaxBlockSize()); | std::string eb = getSubVersionEB(config.GetMaxBlockSize()); | ||||
std::vector<std::string> uacomments; | std::vector<std::string> uacomments; | ||||
uacomments.push_back("EB" + eb); | uacomments.push_back("EB" + eb); | ||||
// sanitize comments per BIP-0014, format user agent and check total size | // sanitize comments per BIP-0014, format user agent and check total size | ||||
for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { | for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { | ||||
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { | const std::string sanitized = | ||||
SanitizeString(cmt, SAFE_CHARS_UA_COMMENT); | |||||
if (cmt != sanitized) { | |||||
LogPrintf( | LogPrintf( | ||||
"User Agent comment (%s) contains unsafe characters. " | "User Agent comment (%s) contains unsafe characters. " | ||||
"We are going to use a sanitize version of the comment.\n", | "We are going to use a sanitize version of the comment.\n", | ||||
cmt); | cmt); | ||||
} | } | ||||
uacomments.push_back(cmt); | uacomments.push_back(sanitized); | ||||
} | } | ||||
std::string subversion = | std::string subversion = | ||||
FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments); | FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments); | ||||
if (subversion.size() > MAX_SUBVERSION_LENGTH) { | if (subversion.size() > MAX_SUBVERSION_LENGTH) { | ||||
LogPrintf("Total length of network version string (%i) exceeds maximum " | LogPrintf("Total length of network version string (%i) exceeds maximum " | ||||
"length (%i). Reduce the number or size of uacomments. " | "length (%i). Reduce the number or size of uacomments. " | ||||
"String has been resized to the max length allowed.\n", | "String has been resized to the max length allowed.\n", | ||||
subversion.size(), MAX_SUBVERSION_LENGTH); | subversion.size(), MAX_SUBVERSION_LENGTH); | ||||
subversion.resize(MAX_SUBVERSION_LENGTH - 2); | subversion.resize(MAX_SUBVERSION_LENGTH - 2); | ||||
subversion.append(")/"); | subversion.append(")/"); | ||||
LogPrintf("Current network string has been set to: %s\n", subversion); | LogPrintf("Current network string has been set to: %s\n", subversion); | ||||
} | } | ||||
return subversion; | return subversion; | ||||
} | } |