diff --git a/src/init.cpp b/src/init.cpp index 2572f9d78c..d7b33b6471 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -632,6 +632,7 @@ void SetupServerArgs(ArgsManager& argsman) Ticks(DEFAULT_MAX_TIP_AGE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-printpriority", strprintf("Log transaction fee rate in " + CURRENCY_UNIT + "/kvB when mining blocks (default: %u)", DEFAULT_PRINT_MODIFIED_FEE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST); + argsman.AddArg("-uaappend=", "Append literal to the user agent string (should only be used for software embedding)", ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); argsman.AddArg("-uacomment=", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); SetupChainParamsBaseOptions(argsman); @@ -1362,6 +1363,10 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) uacomments.push_back(cmt); } strSubVersion = FormatSubVersion(CLIENT_NAME, CLIENT_VERSION, uacomments); + for (auto append : gArgs.GetArgs("-uaappend")) { + if (append.back() != '/') append += '/'; + strSubVersion += append; + } 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)); diff --git a/test/functional/feature_uacomment.py b/test/functional/feature_uacomment.py index fc372f543d..b4bcb787b5 100755 --- a/test/functional/feature_uacomment.py +++ b/test/functional/feature_uacomment.py @@ -35,6 +35,13 @@ class UacommentTest(BitcoinTestFramework): expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters." self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX) + self.log.info("test -uaappend") + self.restart_node(0, ["-uaappend=foo:0"]) + assert_equal(self.nodes[0].getnetworkinfo()["subversion"][-7:], '/foo:0/') + + self.restart_node(0, ["-uaappend=foo:9/"]) + assert_equal(self.nodes[0].getnetworkinfo()["subversion"][-7:], '/foo:9/') + if __name__ == '__main__': UacommentTest(__file__).main()