diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 5a19637ac425e..e05f7dba25301 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -210,7 +210,7 @@ static bool InitHTTPAllowList() rpc_allow_subnets.emplace_back(localv4, 8); // always allow IPv4 local subnet rpc_allow_subnets.emplace_back(localv6); // always allow IPv6 localhost if (mapMultiArgs.count("-rpcallowip")) { - const std::vector& vAllow = mapMultiArgs["-rpcallowip"]; + const std::vector& vAllow = mapMultiArgs.at("-rpcallowip"); for (std::string strAllow : vAllow) { CSubNet subnet; LookupSubNet(strAllow.c_str(), subnet); @@ -331,8 +331,8 @@ static bool HTTPBindAddresses(struct evhttp* http) if (mapArgs.count("-rpcbind")) { LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); } - } else if (mapArgs.count("-rpcbind")) { // Specific bind address - const std::vector& vbind = mapMultiArgs["-rpcbind"]; + } else if (mapMultiArgs.count("-rpcbind")) { // Specific bind address + const std::vector& vbind = mapMultiArgs.at("-rpcbind"); for (std::vector::const_iterator i = vbind.begin(); i != vbind.end(); ++i) { int port = defaultPort; std::string host; diff --git a/src/init.cpp b/src/init.cpp index 6ff1626e5f5a2..399bcdd365191 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -846,7 +846,7 @@ void InitParameterInteraction() LogPrintf("%s : parameter interaction: -bind or -whitebind set -> setting -listen=1\n", __func__); } - if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { + if (mapMultiArgs.count("-connect") && mapMultiArgs.at("-connect").size() > 0) { // when only connecting to trusted nodes, do not seed via DNS, or listen by default if (SoftSetBoolArg("-dnsseed", false)) LogPrintf("%s : parameter interaction: -connect set -> setting -dnsseed=0\n", __func__); @@ -903,12 +903,12 @@ void InitParameterInteraction() bool InitNUParams() { - if (!mapMultiArgs["-nuparams"].empty()) { + if (mapMultiArgs.count("-nuparams")) { // Allow overriding network upgrade parameters for testing if (Params().NetworkIDString() != "regtest") { return UIError("Network upgrade parameters may only be overridden on regtest."); } - const std::vector& deployments = mapMultiArgs["-nuparams"]; + const std::vector& deployments = mapMultiArgs.at("-nuparams"); for (auto i : deployments) { std::vector vDeploymentParams; boost::split(vDeploymentParams, i, boost::is_any_of(":")); @@ -1007,7 +1007,7 @@ bool AppInit2() // ********************************************************* Step 3: parameter-to-internal-flags // Special-case: if -debug=0/-nodebug is set, turn off debugging messages - const std::vector& categories = mapMultiArgs["-debug"]; + const std::vector& categories = mapMultiArgs.at("-debug"); if (!(GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())) { @@ -1331,7 +1331,7 @@ bool AppInit2() // sanitize comments per BIP-0014, format user agent and check total size std::vector uacomments; - for (const std::string& cmt : mapMultiArgs["-uacomment"]) { + for (const std::string& cmt : mapMultiArgs.at("-uacomment")) { if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) return UIError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt)); uacomments.push_back(cmt); @@ -1344,9 +1344,9 @@ bool AppInit2() strSubVersion.size(), MAX_SUBVERSION_LENGTH)); } - if (mapArgs.count("-onlynet")) { + if (mapMultiArgs.count("-onlynet")) { std::set nets; - for (std::string snet : mapMultiArgs["-onlynet"]) { + for (const std::string& snet : mapMultiArgs.at("-onlynet")) { enum Network net = ParseNetwork(snet); if (net == NET_UNROUTABLE) return UIError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet)); @@ -1359,8 +1359,8 @@ bool AppInit2() } } - if (mapArgs.count("-whitelist")) { - for (const std::string& net : mapMultiArgs["-whitelist"]) { + if (mapMultiArgs.count("-whitelist")) { + for (const std::string& net : mapMultiArgs.at("-whitelist")) { CSubNet subnet; LookupSubNet(net.c_str(), subnet); if (!subnet.IsValid()) @@ -1420,14 +1420,16 @@ bool AppInit2() bool fBound = false; if (fListen) { - if (mapArgs.count("-bind") || mapArgs.count("-whitebind")) { - for (std::string strBind : mapMultiArgs["-bind"]) { + if (mapMultiArgs.count("-bind")) { + for (const std::string& strBind : mapMultiArgs.at("-bind")) { CService addrBind; if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) return UIError(ResolveErrMsg("bind", strBind)); fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR)); } - for (std::string strBind : mapMultiArgs["-whitebind"]) { + } + if (mapMultiArgs.count("-whitebind")) { + for (const std::string& strBind : mapMultiArgs.at("-whitebind")) { CService addrBind; if (!Lookup(strBind.c_str(), addrBind, 0, false)) return UIError(ResolveErrMsg("whitebind", strBind)); @@ -1435,7 +1437,8 @@ bool AppInit2() return UIError(strprintf(_("Need to specify a port with -whitebind: '%s'"), strBind)); fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST)); } - } else { + } + if (!mapMultiArgs.count("-bind") && !mapMultiArgs.count("-whitebind")) { struct in_addr inaddr_any; inaddr_any.s_addr = INADDR_ANY; fBound |= Bind(connman, CService((in6_addr)IN6ADDR_ANY_INIT, GetListenPort()), BF_NONE); @@ -1445,8 +1448,8 @@ bool AppInit2() return UIError(_("Failed to listen on any port. Use -listen=0 if you want this.")); } - if (mapArgs.count("-externalip")) { - for (std::string strAddr : mapMultiArgs["-externalip"]) { + if (mapMultiArgs.count("-externalip")) { + for (const std::string& strAddr : mapMultiArgs.at("-externalip")) { CService addrLocal; if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid()) AddLocal(addrLocal,LOCAL_MANUAL); @@ -1455,8 +1458,10 @@ bool AppInit2() } } - for (const std::string& strDest : mapMultiArgs["-seednode"]) - connman.AddOneShot(strDest); + if (mapMultiArgs.count("-seednode")) { + for (const std::string& strDest : mapMultiArgs.at("-seednode")) + connman.AddOneShot(strDest); + } #if ENABLE_ZMQ pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs); @@ -1727,8 +1732,8 @@ bool AppInit2() } std::vector vImportFiles; - if (mapArgs.count("-loadblock")) { - for (std::string strFile : mapMultiArgs["-loadblock"]) + if (mapMultiArgs.count("-loadblock")) { + for (const std::string& strFile : mapMultiArgs.at("-loadblock")) vImportFiles.push_back(strFile); } threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles)); diff --git a/src/net.cpp b/src/net.cpp index 47fa9d4af86d0..a0edd398910e7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1613,12 +1613,12 @@ void CConnman::ProcessOneShot() void CConnman::ThreadOpenConnections() { // Connect to specific addresses - if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) { + if (mapMultiArgs.count("-connect") && !mapMultiArgs.at("-connect").empty()) { for (int64_t nLoop = 0;; nLoop++) { ProcessOneShot(); - for (std::string strAddr : mapMultiArgs["-connect"]) { + for (const std::string& strAddr : mapMultiArgs.at("-connect")) { CAddress addr(CService(), NODE_NONE); - OpenNetworkConnection(addr, false, NULL, strAddr.c_str()); + OpenNetworkConnection(addr, false, nullptr, strAddr.c_str()); for (int i = 0; i < 10 && i < nLoop; i++) { if (!interruptNet.sleep_for(std::chrono::milliseconds(500))) return; @@ -1811,7 +1811,8 @@ void CConnman::ThreadOpenAddedConnections() { { LOCK(cs_vAddedNodes); - vAddedNodes = mapMultiArgs["-addnode"]; + if (mapMultiArgs.count("-addnode")) + vAddedNodes = mapMultiArgs.at("-addnode"); } for (unsigned int i = 0; true; i++) { @@ -2165,7 +2166,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c threadOpenAddedConnections = std::thread(&TraceThread >, "addcon", std::function(std::bind(&CConnman::ThreadOpenAddedConnections, this))); // Initiate outbound connections unless connect=0 - if (!mapArgs.count("-connect") || mapMultiArgs["-connect"].size() != 1 || mapMultiArgs["-connect"][0] != "0") + if (!mapMultiArgs.count("-connect") || mapMultiArgs.at("-connect").size() != 1 || mapMultiArgs.at("-connect")[0] != "0") threadOpenConnections = std::thread(&TraceThread >, "opencon", std::function(std::bind(&CConnman::ThreadOpenConnections, this))); // Process messages diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 0df9e62509f64..4ea2f80668b33 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -533,7 +533,7 @@ void JSONRPCRequest::parse(const UniValue& valRequest) bool IsDeprecatedRPCEnabled(const std::string& method) { - const std::vector enabled_methods = mapMultiArgs["-deprecatedrpc"]; + const std::vector enabled_methods = mapMultiArgs.at("-deprecatedrpc"); return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end(); } diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 518f37f279ed4..dca41d627bd04 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -116,7 +116,7 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters) && !mapMultiArgs.count("f") && !mapMultiArgs.count("-d")); BOOST_CHECK(mapArgs["-a"] == "" && mapArgs["-ccc"] == "multiple"); - BOOST_CHECK(mapMultiArgs["-ccc"].size() == 2); + BOOST_CHECK(mapMultiArgs.at("-ccc").size() == 2); } BOOST_AUTO_TEST_CASE(util_GetArg) diff --git a/src/util.cpp b/src/util.cpp index 5b033e3e5a17c..79f35aac4cf06 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -106,7 +106,8 @@ bool fSucessfullyLoaded = false; std::string strBudgetMode = ""; std::map mapArgs; -std::map > mapMultiArgs; +static std::map > _mapMultiArgs; +const std::map >& mapMultiArgs = _mapMultiArgs; bool fDaemon = false; std::string strMiscWarning; @@ -182,7 +183,7 @@ static void InterpretNegativeSetting(std::string& strKey, std::string& strValue) void ParseParameters(int argc, const char* const argv[]) { mapArgs.clear(); - mapMultiArgs.clear(); + _mapMultiArgs.clear(); for (int i = 1; i < argc; i++) { std::string str(argv[i]); @@ -208,7 +209,7 @@ void ParseParameters(int argc, const char* const argv[]) InterpretNegativeSetting(str, strValue); mapArgs[str] = strValue; - mapMultiArgs[str].push_back(strValue); + _mapMultiArgs[str].push_back(strValue); } } @@ -483,7 +484,7 @@ void ReadConfigFile() InterpretNegativeSetting(strKey, strValue); if (mapArgs.count(strKey) == 0) mapArgs[strKey] = strValue; - mapMultiArgs[strKey].push_back(strValue); + _mapMultiArgs[strKey].push_back(strValue); } // If datadir is changed in .conf file: ClearDatadirCache(); diff --git a/src/util.h b/src/util.h index 16a12047a2b9d..eb6157ad6aa76 100644 --- a/src/util.h +++ b/src/util.h @@ -51,7 +51,7 @@ extern bool fSucessfullyLoaded; extern std::string strBudgetMode; extern std::map mapArgs; -extern std::map > mapMultiArgs; +extern const std::map >& mapMultiArgs; extern std::string strMiscWarning;