Browse Source

scripted-diff: Util: Encapsulate mapMultiArgs behind gArgs

-BEGIN VERIFY SCRIPT-
sed -i 's/mapMultiArgs.count(/gArgs.IsArgSet(/g' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
sed -i 's/mapMultiArgs.at("/gArgs.GetArgs("/g' ./src/*.h ./src/*.cpp ./src/*/*.h ./src/*/*.cpp ./src/*/*/*.h ./src/*/*/*.cpp ;
-END VERIFY SCRIPT-
0.15
Jorge Timón 8 years ago
parent
commit
b3cbd554d9
No known key found for this signature in database
GPG Key ID: 8866C18EA1C944A2
  1. 4
      src/httprpc.cpp
  2. 8
      src/httpserver.cpp
  3. 52
      src/init.cpp
  4. 10
      src/net.cpp

4
src/httprpc.cpp

@ -93,9 +93,9 @@ static bool multiUserAuthorized(std::string strUserPass)
std::string strUser = strUserPass.substr(0, strUserPass.find(":")); std::string strUser = strUserPass.substr(0, strUserPass.find(":"));
std::string strPass = strUserPass.substr(strUserPass.find(":") + 1); std::string strPass = strUserPass.substr(strUserPass.find(":") + 1);
if (mapMultiArgs.count("-rpcauth") > 0) { if (gArgs.IsArgSet("-rpcauth") > 0) {
//Search for multi-user login/pass "rpcauth" from config //Search for multi-user login/pass "rpcauth" from config
BOOST_FOREACH(std::string strRPCAuth, mapMultiArgs.at("-rpcauth")) BOOST_FOREACH(std::string strRPCAuth, gArgs.GetArgs("-rpcauth"))
{ {
std::vector<std::string> vFields; std::vector<std::string> vFields;
boost::split(vFields, strRPCAuth, boost::is_any_of(":$")); boost::split(vFields, strRPCAuth, boost::is_any_of(":$"));

8
src/httpserver.cpp

@ -196,8 +196,8 @@ static bool InitHTTPAllowList()
LookupHost("::1", localv6, false); LookupHost("::1", localv6, false);
rpc_allow_subnets.push_back(CSubNet(localv4, 8)); // always allow IPv4 local subnet rpc_allow_subnets.push_back(CSubNet(localv4, 8)); // always allow IPv4 local subnet
rpc_allow_subnets.push_back(CSubNet(localv6)); // always allow IPv6 localhost rpc_allow_subnets.push_back(CSubNet(localv6)); // always allow IPv6 localhost
if (mapMultiArgs.count("-rpcallowip")) { if (gArgs.IsArgSet("-rpcallowip")) {
const std::vector<std::string>& vAllow = mapMultiArgs.at("-rpcallowip"); const std::vector<std::string>& vAllow = gArgs.GetArgs("-rpcallowip");
for (std::string strAllow : vAllow) { for (std::string strAllow : vAllow) {
CSubNet subnet; CSubNet subnet;
LookupSubNet(strAllow.c_str(), subnet); LookupSubNet(strAllow.c_str(), subnet);
@ -321,8 +321,8 @@ static bool HTTPBindAddresses(struct evhttp* http)
if (IsArgSet("-rpcbind")) { if (IsArgSet("-rpcbind")) {
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n"); LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
} }
} else if (mapMultiArgs.count("-rpcbind")) { // Specific bind address } else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
const std::vector<std::string>& vbind = mapMultiArgs.at("-rpcbind"); const std::vector<std::string>& vbind = gArgs.GetArgs("-rpcbind");
for (std::vector<std::string>::const_iterator i = vbind.begin(); i != vbind.end(); ++i) { for (std::vector<std::string>::const_iterator i = vbind.begin(); i != vbind.end(); ++i) {
int port = defaultPort; int port = defaultPort;
std::string host; std::string host;

52
src/init.cpp

@ -741,7 +741,7 @@ void InitParameterInteraction()
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__); LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
} }
if (mapMultiArgs.count("-connect") && mapMultiArgs.at("-connect").size() > 0) { if (gArgs.IsArgSet("-connect") && gArgs.GetArgs("-connect").size() > 0) {
// when only connecting to trusted nodes, do not seed via DNS, or listen by default // when only connecting to trusted nodes, do not seed via DNS, or listen by default
if (SoftSetBoolArg("-dnsseed", false)) if (SoftSetBoolArg("-dnsseed", false))
LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__); LogPrintf("%s: parameter interaction: -connect set -> setting -dnsseed=0\n", __func__);
@ -895,8 +895,8 @@ bool AppInitParameterInteraction()
// Make sure enough file descriptors are available // Make sure enough file descriptors are available
int nBind = std::max( int nBind = std::max(
(mapMultiArgs.count("-bind") ? mapMultiArgs.at("-bind").size() : 0) + (gArgs.IsArgSet("-bind") ? gArgs.GetArgs("-bind").size() : 0) +
(mapMultiArgs.count("-whitebind") ? mapMultiArgs.at("-whitebind").size() : 0), size_t(1)); (gArgs.IsArgSet("-whitebind") ? gArgs.GetArgs("-whitebind").size() : 0), size_t(1));
nUserMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS); nUserMaxConnections = GetArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
nMaxConnections = std::max(nUserMaxConnections, 0); nMaxConnections = std::max(nUserMaxConnections, 0);
@ -911,9 +911,9 @@ bool AppInitParameterInteraction()
InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections)); InitWarning(strprintf(_("Reducing -maxconnections from %d to %d, because of system limitations."), nUserMaxConnections, nMaxConnections));
// ********************************************************* Step 3: parameter-to-internal-flags // ********************************************************* Step 3: parameter-to-internal-flags
if (mapMultiArgs.count("-debug") > 0) { if (gArgs.IsArgSet("-debug") > 0) {
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages // Special-case: if -debug=0/-nodebug is set, turn off debugging messages
const std::vector<std::string>& categories = mapMultiArgs.at("-debug"); const std::vector<std::string>& categories = gArgs.GetArgs("-debug");
if (find(categories.begin(), categories.end(), std::string("0")) == categories.end()) { if (find(categories.begin(), categories.end(), std::string("0")) == categories.end()) {
for (const auto& cat : categories) { for (const auto& cat : categories) {
@ -928,8 +928,8 @@ bool AppInitParameterInteraction()
} }
// Now remove the logging categories which were explicitly excluded // Now remove the logging categories which were explicitly excluded
if (mapMultiArgs.count("-debugexclude") > 0) { if (gArgs.IsArgSet("-debugexclude") > 0) {
const std::vector<std::string>& excludedCategories = mapMultiArgs.at("-debugexclude"); const std::vector<std::string>& excludedCategories = gArgs.GetArgs("-debugexclude");
for (const auto& cat : excludedCategories) { for (const auto& cat : excludedCategories) {
uint32_t flag = 0; uint32_t flag = 0;
if (!GetLogCategory(&flag, &cat)) { if (!GetLogCategory(&flag, &cat)) {
@ -1100,12 +1100,12 @@ bool AppInitParameterInteraction()
fEnableReplacement = (std::find(vstrReplacementModes.begin(), vstrReplacementModes.end(), "fee") != vstrReplacementModes.end()); fEnableReplacement = (std::find(vstrReplacementModes.begin(), vstrReplacementModes.end(), "fee") != vstrReplacementModes.end());
} }
if (mapMultiArgs.count("-bip9params")) { if (gArgs.IsArgSet("-bip9params")) {
// Allow overriding BIP9 parameters for testing // Allow overriding BIP9 parameters for testing
if (!chainparams.MineBlocksOnDemand()) { if (!chainparams.MineBlocksOnDemand()) {
return InitError("BIP9 parameters may only be overridden on regtest."); return InitError("BIP9 parameters may only be overridden on regtest.");
} }
const std::vector<std::string>& deployments = mapMultiArgs.at("-bip9params"); const std::vector<std::string>& deployments = gArgs.GetArgs("-bip9params");
for (auto i : deployments) { for (auto i : deployments) {
std::vector<std::string> vDeploymentParams; std::vector<std::string> vDeploymentParams;
boost::split(vDeploymentParams, i, boost::is_any_of(":")); boost::split(vDeploymentParams, i, boost::is_any_of(":"));
@ -1254,8 +1254,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
// sanitize comments per BIP-0014, format user agent and check total size // sanitize comments per BIP-0014, format user agent and check total size
std::vector<std::string> uacomments; std::vector<std::string> uacomments;
if (mapMultiArgs.count("-uacomment")) { if (gArgs.IsArgSet("-uacomment")) {
BOOST_FOREACH(std::string cmt, mapMultiArgs.at("-uacomment")) BOOST_FOREACH(std::string cmt, gArgs.GetArgs("-uacomment"))
{ {
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT))
return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt)); return InitError(strprintf(_("User Agent comment (%s) contains unsafe characters."), cmt));
@ -1268,9 +1268,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
strSubVersion.size(), MAX_SUBVERSION_LENGTH)); strSubVersion.size(), MAX_SUBVERSION_LENGTH));
} }
if (mapMultiArgs.count("-onlynet")) { if (gArgs.IsArgSet("-onlynet")) {
std::set<enum Network> nets; std::set<enum Network> nets;
BOOST_FOREACH(const std::string& snet, mapMultiArgs.at("-onlynet")) { BOOST_FOREACH(const std::string& snet, gArgs.GetArgs("-onlynet")) {
enum Network net = ParseNetwork(snet); enum Network net = ParseNetwork(snet);
if (net == NET_UNROUTABLE) if (net == NET_UNROUTABLE)
return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet)); return InitError(strprintf(_("Unknown network specified in -onlynet: '%s'"), snet));
@ -1283,8 +1283,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
} }
} }
if (mapMultiArgs.count("-whitelist")) { if (gArgs.IsArgSet("-whitelist")) {
BOOST_FOREACH(const std::string& net, mapMultiArgs.at("-whitelist")) { BOOST_FOREACH(const std::string& net, gArgs.GetArgs("-whitelist")) {
CSubNet subnet; CSubNet subnet;
LookupSubNet(net.c_str(), subnet); LookupSubNet(net.c_str(), subnet);
if (!subnet.IsValid()) if (!subnet.IsValid())
@ -1345,16 +1345,16 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
if (fListen) { if (fListen) {
bool fBound = false; bool fBound = false;
if (mapMultiArgs.count("-bind")) { if (gArgs.IsArgSet("-bind")) {
BOOST_FOREACH(const std::string& strBind, mapMultiArgs.at("-bind")) { BOOST_FOREACH(const std::string& strBind, gArgs.GetArgs("-bind")) {
CService addrBind; CService addrBind;
if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false))
return InitError(ResolveErrMsg("bind", strBind)); return InitError(ResolveErrMsg("bind", strBind));
fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR)); fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR));
} }
} }
if (mapMultiArgs.count("-whitebind")) { if (gArgs.IsArgSet("-whitebind")) {
BOOST_FOREACH(const std::string& strBind, mapMultiArgs.at("-whitebind")) { BOOST_FOREACH(const std::string& strBind, gArgs.GetArgs("-whitebind")) {
CService addrBind; CService addrBind;
if (!Lookup(strBind.c_str(), addrBind, 0, false)) if (!Lookup(strBind.c_str(), addrBind, 0, false))
return InitError(ResolveErrMsg("whitebind", strBind)); return InitError(ResolveErrMsg("whitebind", strBind));
@ -1363,7 +1363,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST)); fBound |= Bind(connman, addrBind, (BF_EXPLICIT | BF_REPORT_ERROR | BF_WHITELIST));
} }
} }
if (!mapMultiArgs.count("-bind") && !mapMultiArgs.count("-whitebind")) { if (!gArgs.IsArgSet("-bind") && !gArgs.IsArgSet("-whitebind")) {
struct in_addr inaddr_any; struct in_addr inaddr_any;
inaddr_any.s_addr = INADDR_ANY; inaddr_any.s_addr = INADDR_ANY;
fBound |= Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE); fBound |= Bind(connman, CService(in6addr_any, GetListenPort()), BF_NONE);
@ -1373,8 +1373,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
return InitError(_("Failed to listen on any port. Use -listen=0 if you want this.")); return InitError(_("Failed to listen on any port. Use -listen=0 if you want this."));
} }
if (mapMultiArgs.count("-externalip")) { if (gArgs.IsArgSet("-externalip")) {
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs.at("-externalip")) { BOOST_FOREACH(const std::string& strAddr, gArgs.GetArgs("-externalip")) {
CService addrLocal; CService addrLocal;
if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid()) if (Lookup(strAddr.c_str(), addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
AddLocal(addrLocal, LOCAL_MANUAL); AddLocal(addrLocal, LOCAL_MANUAL);
@ -1383,8 +1383,8 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
} }
} }
if (mapMultiArgs.count("-seednode")) { if (gArgs.IsArgSet("-seednode")) {
BOOST_FOREACH(const std::string& strDest, mapMultiArgs.at("-seednode")) BOOST_FOREACH(const std::string& strDest, gArgs.GetArgs("-seednode"))
connman.AddOneShot(strDest); connman.AddOneShot(strDest);
} }
@ -1610,9 +1610,9 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
std::vector<fs::path> vImportFiles; std::vector<fs::path> vImportFiles;
if (mapMultiArgs.count("-loadblock")) if (gArgs.IsArgSet("-loadblock"))
{ {
BOOST_FOREACH(const std::string& strFile, mapMultiArgs.at("-loadblock")) BOOST_FOREACH(const std::string& strFile, gArgs.GetArgs("-loadblock"))
vImportFiles.push_back(strFile); vImportFiles.push_back(strFile);
} }

10
src/net.cpp

@ -1670,12 +1670,12 @@ void CConnman::ProcessOneShot()
void CConnman::ThreadOpenConnections() void CConnman::ThreadOpenConnections()
{ {
// Connect to specific addresses // Connect to specific addresses
if (mapMultiArgs.count("-connect") && mapMultiArgs.at("-connect").size() > 0) if (gArgs.IsArgSet("-connect") && gArgs.GetArgs("-connect").size() > 0)
{ {
for (int64_t nLoop = 0;; nLoop++) for (int64_t nLoop = 0;; nLoop++)
{ {
ProcessOneShot(); ProcessOneShot();
BOOST_FOREACH(const std::string& strAddr, mapMultiArgs.at("-connect")) BOOST_FOREACH(const std::string& strAddr, gArgs.GetArgs("-connect"))
{ {
CAddress addr(CService(), NODE_NONE); CAddress addr(CService(), NODE_NONE);
OpenNetworkConnection(addr, false, NULL, strAddr.c_str()); OpenNetworkConnection(addr, false, NULL, strAddr.c_str());
@ -1877,8 +1877,8 @@ void CConnman::ThreadOpenAddedConnections()
{ {
{ {
LOCK(cs_vAddedNodes); LOCK(cs_vAddedNodes);
if (mapMultiArgs.count("-addnode")) if (gArgs.IsArgSet("-addnode"))
vAddedNodes = mapMultiArgs.at("-addnode"); vAddedNodes = gArgs.GetArgs("-addnode");
} }
while (true) while (true)
@ -2289,7 +2289,7 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
threadOpenAddedConnections = std::thread(&TraceThread<std::function<void()> >, "addcon", std::function<void()>(std::bind(&CConnman::ThreadOpenAddedConnections, this))); threadOpenAddedConnections = std::thread(&TraceThread<std::function<void()> >, "addcon", std::function<void()>(std::bind(&CConnman::ThreadOpenAddedConnections, this)));
// Initiate outbound connections unless connect=0 // Initiate outbound connections unless connect=0
if (!mapMultiArgs.count("-connect") || mapMultiArgs.at("-connect").size() != 1 || mapMultiArgs.at("-connect")[0] != "0") if (!gArgs.IsArgSet("-connect") || gArgs.GetArgs("-connect").size() != 1 || gArgs.GetArgs("-connect")[0] != "0")
threadOpenConnections = std::thread(&TraceThread<std::function<void()> >, "opencon", std::function<void()>(std::bind(&CConnman::ThreadOpenConnections, this))); threadOpenConnections = std::thread(&TraceThread<std::function<void()> >, "opencon", std::function<void()>(std::bind(&CConnman::ThreadOpenConnections, this)));
// Process messages // Process messages

Loading…
Cancel
Save