diff options
author | Anthony Towns <aj@erisian.com.au> | 2018-04-04 18:06:00 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2018-04-11 23:15:28 +1000 |
commit | d1fc4d95afc191072fc650581a9b668b68b47b15 (patch) | |
tree | 41dbee4286d56041857c9d39845c31aa610d1cd1 /src/util.cpp | |
parent | 8a9817d175453c74ec060dcac026cd713bec98fa (diff) |
ArgsManager: limit some options to only apply on mainnet when in default section
When specified in bitcoin.conf without using the [regtest] or [test]
section header, or a "regtest." or "test." prefix, the "addnode",
"connect", "port", "bind", "rpcport", "rpcbind", and "wallet" settings
will only be applied when running on mainnet.
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/util.cpp b/src/util.cpp index 85c3d221af..51c28349f3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -460,6 +460,13 @@ class ArgsManagerHelper { public: typedef std::map<std::string, std::vector<std::string>> MapArgs; + /** Determine whether to use config settings in the default section, + * See also comments around ArgsManager::ArgsManager() below. */ + static inline bool UseDefaultSection(const ArgsManager& am, const std::string& arg) + { + return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args.count(arg) == 0); + } + /** Convert regular argument into the network-specific setting */ static inline std::string NetworkArg(const ArgsManager& am, const std::string& arg) { @@ -521,9 +528,11 @@ public: } } - found_result = GetArgHelper(am.m_config_args, arg); - if (found_result.first) { - return found_result; + if (UseDefaultSection(am, arg)) { + found_result = GetArgHelper(am.m_config_args, arg); + if (found_result.first) { + return found_result; + } } return found_result; @@ -575,6 +584,22 @@ static bool InterpretNegatedOption(std::string& key, std::string& val) return false; } +ArgsManager::ArgsManager() : + /* These options would cause cross-contamination if values for + * mainnet were used while running on regtest/testnet (or vice-versa). + * Setting them as section_only_args ensures that sharing a config file + * between mainnet and regtest/testnet won't cause problems due to these + * parameters by accident. */ + m_network_only_args{ + "-addnode", "-connect", + "-port", "-bind", + "-rpcport", "-rpcbind", + "-wallet", + } +{ + // nothing to do +} + void ArgsManager::SelectConfigNetwork(const std::string& network) { m_network = network; @@ -621,11 +646,16 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const if (IsArgNegated(strArg)) return result; // special case LOCK(cs_args); + ArgsManagerHelper::AddArgs(result, m_override_args, strArg); if (!m_network.empty()) { ArgsManagerHelper::AddArgs(result, m_config_args, ArgsManagerHelper::NetworkArg(*this, strArg)); } - ArgsManagerHelper::AddArgs(result, m_config_args, strArg); + + if (ArgsManagerHelper::UseDefaultSection(*this, strArg)) { + ArgsManagerHelper::AddArgs(result, m_config_args, strArg); + } + return result; } |