From 3673ca36ef84192b42d7e6acbdc8b5d2ffc7a0cf Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 4 Apr 2018 18:01:00 +1000 Subject: ArgsManager: keep command line and config file arguments separate --- src/util.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 3952461e48..01ff5992fb 100644 --- a/src/util.h +++ b/src/util.h @@ -223,11 +223,12 @@ inline bool IsSwitchChar(char c) class ArgsManager { protected: + friend class ArgsManagerHelper; + mutable CCriticalSection cs_args; - std::map mapArgs; - std::map> mapMultiArgs; + std::map> m_override_args; + std::map> m_config_args; std::unordered_set m_negated_args; - void ReadConfigStream(std::istream& stream); public: -- cgit v1.2.3 From 4d34fcc7138f0ffc831f0f8601c50cc7f494c197 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 4 Apr 2018 18:02:00 +1000 Subject: ArgsManager: drop m_negated_args When a -nofoo option is seen, instead of adding it to a separate set of negated args, set the arg as being an empty vector of strings. This changes the behaviour in some ways: - -nofoo=0 still sets foo=1 but no longer treats it as a negated arg - -nofoo=1 -foo=2 has GetArgs() return [2] rather than [2,0] - "foo=2 \n -nofoo=1" in a config file no longer returns [2,0], just [0] - GetArgs returns an empty vector for negated args --- src/util.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 01ff5992fb..6b80afc58f 100644 --- a/src/util.h +++ b/src/util.h @@ -228,7 +228,6 @@ protected: mutable CCriticalSection cs_args; std::map> m_override_args; std::map> m_config_args; - std::unordered_set m_negated_args; void ReadConfigStream(std::istream& stream); public: @@ -314,11 +313,6 @@ public: * @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given. */ std::string GetChainName() const; - -private: - - // Munge -nofoo into -foo=0 and track the value as negated. - void InterpretNegatedOption(std::string &key, std::string &val); }; extern ArgsManager gArgs; -- cgit v1.2.3 From 95eb66d5842e5ccdeb7481b9ee92ac4aface6b0f Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 4 Apr 2018 18:03:00 +1000 Subject: ArgsManager: support config file sections --- src/util.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 6b80afc58f..ca6523ab14 100644 --- a/src/util.h +++ b/src/util.h @@ -228,9 +228,15 @@ protected: mutable CCriticalSection cs_args; std::map> m_override_args; std::map> m_config_args; + std::string m_network; void ReadConfigStream(std::istream& stream); public: + /** + * Select the network in use + */ + void SelectConfigNetwork(const std::string& network); + void ParseParameters(int argc, const char*const argv[]); void ReadConfigFile(const std::string& confPath); -- cgit v1.2.3 From d1fc4d95afc191072fc650581a9b668b68b47b15 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 4 Apr 2018 18:06:00 +1000 Subject: 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. --- src/util.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index ca6523ab14..8132435628 100644 --- a/src/util.h +++ b/src/util.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -229,9 +230,13 @@ protected: std::map> m_override_args; std::map> m_config_args; std::string m_network; + std::set m_network_only_args; + void ReadConfigStream(std::istream& stream); public: + ArgsManager(); + /** * Select the network in use */ -- cgit v1.2.3 From 68797e20f478d835b7ff691a656242c14283446a Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 4 Apr 2018 18:07:00 +1000 Subject: ArgsManager: Warn when ignoring network-specific config setting When network-specific options such as -addnode, -connect, etc are specified in the default section of the config file, but that setting is ignored due to testnet or regtest being in use, and it is not overridden by either a command line option or a setting in the [regtest] or [test] section of the config file, a warning is added to the log, eg: Warning: Config setting for -connect only applied on regtest network when in [regtest] section. --- src/util.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index 8132435628..ba80c21ddc 100644 --- a/src/util.h +++ b/src/util.h @@ -245,6 +245,14 @@ public: void ParseParameters(int argc, const char*const argv[]); void ReadConfigFile(const std::string& confPath); + /** + * Log warnings for options in m_section_only_args when + * they are specified in the default section but not overridden + * on the command line or in a network-specific section in the + * config file. + */ + void WarnForSectionOnlyArgs(); + /** * Return a vector of strings of the given argument * -- cgit v1.2.3