2011-05-14 04:31:46 -04:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2020-01-14 16:17:38 -03:00
|
|
|
// Copyright (c) 2009-2020 The Bitcoin Core developers
|
2014-11-17 00:04:01 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 10:02:28 -04:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-13 02:13:08 -03:00
|
|
|
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 10:11:09 -04:00
|
|
|
/**
|
|
|
|
* Server/client environment: argument handling, config file parsing,
|
2018-04-18 14:05:05 -03:00
|
|
|
* thread wrappers, startup time
|
Split up util.cpp/h
Split up util.cpp/h into:
- string utilities (hex, base32, base64): no internal dependencies, no dependency on boost (apart from foreach)
- money utilities (parsesmoney, formatmoney)
- time utilities (gettime*, sleep, format date):
- and the rest (logging, argument parsing, config file parsing)
The latter is basically the environment and OS handling,
and is stripped of all utility functions, so we may want to
rename it to something else than util.cpp/h for clarity (Matt suggested
osinterface).
Breaks dependency of sha256.cpp on all the things pulled in by util.
2014-08-21 10:11:09 -04:00
|
|
|
*/
|
2018-10-22 19:51:11 -03:00
|
|
|
#ifndef BITCOIN_UTIL_SYSTEM_H
|
|
|
|
#define BITCOIN_UTIL_SYSTEM_H
|
2011-05-14 04:31:46 -04:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <config/bitcoin-config.h>
|
2013-04-13 02:13:08 -03:00
|
|
|
#endif
|
|
|
|
|
2018-09-25 02:00:36 -03:00
|
|
|
#include <attributes.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <compat.h>
|
2019-02-11 19:52:59 -03:00
|
|
|
#include <compat/assumptions.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <fs.h>
|
2018-04-18 14:05:05 -03:00
|
|
|
#include <logging.h>
|
2019-11-11 21:05:12 -03:00
|
|
|
#include <optional.h>
|
2017-11-09 21:57:53 -03:00
|
|
|
#include <sync.h>
|
|
|
|
#include <tinyformat.h>
|
2018-10-22 19:51:11 -03:00
|
|
|
#include <util/memory.h>
|
2019-04-22 18:08:51 -04:00
|
|
|
#include <util/settings.h>
|
2019-06-27 14:11:25 -04:00
|
|
|
#include <util/threadnames.h>
|
2018-10-22 19:51:11 -03:00
|
|
|
#include <util/time.h>
|
2011-05-14 04:31:46 -04:00
|
|
|
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <exception>
|
|
|
|
#include <map>
|
2018-04-04 05:06:00 -03:00
|
|
|
#include <set>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
2018-08-05 12:38:25 -04:00
|
|
|
#include <utility>
|
2013-04-13 02:13:08 -03:00
|
|
|
#include <vector>
|
2013-05-24 09:45:08 -04:00
|
|
|
|
2020-01-30 08:07:57 -03:00
|
|
|
class UniValue;
|
|
|
|
|
2017-05-14 14:18:26 -04:00
|
|
|
// Application startup time (used for uptime calculation)
|
|
|
|
int64_t GetStartupTime();
|
|
|
|
|
2015-06-27 16:21:41 -03:00
|
|
|
extern const char * const BITCOIN_CONF_FILENAME;
|
2019-04-28 19:08:26 -04:00
|
|
|
extern const char * const BITCOIN_SETTINGS_FILENAME;
|
2015-06-27 16:21:41 -03:00
|
|
|
|
2014-05-13 06:15:00 -04:00
|
|
|
void SetupEnvironment();
|
2015-09-02 11:18:16 -03:00
|
|
|
bool SetupNetworking();
|
2013-09-18 05:03:21 -03:00
|
|
|
|
2016-06-27 12:39:25 -04:00
|
|
|
template<typename... Args>
|
|
|
|
bool error(const char* fmt, const Args&... args)
|
2016-05-04 09:21:04 -03:00
|
|
|
{
|
2018-04-11 14:03:21 -03:00
|
|
|
LogPrintf("ERROR: %s\n", tfm::format(fmt, args...));
|
2014-01-16 11:52:37 -03:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-09 09:43:06 -03:00
|
|
|
|
2014-12-07 09:29:06 -03:00
|
|
|
void PrintExceptionContinue(const std::exception *pex, const char* pszThread);
|
2018-03-15 10:54:11 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure file contents are fully committed to disk, using a platform-specific
|
|
|
|
* feature analogous to fsync().
|
|
|
|
*/
|
2018-04-20 06:21:08 -03:00
|
|
|
bool FileCommit(FILE *file);
|
2018-03-15 10:54:11 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sync directory contents. This is required on some environments to ensure that
|
|
|
|
* newly created files are committed to disk.
|
|
|
|
*/
|
|
|
|
void DirectoryCommit(const fs::path &dirname);
|
|
|
|
|
2013-01-30 00:17:33 -03:00
|
|
|
bool TruncateFile(FILE *file, unsigned int length);
|
2013-04-25 19:46:47 -03:00
|
|
|
int RaiseFileDescriptorLimit(int nMinFD);
|
2012-08-15 20:21:28 -04:00
|
|
|
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
2020-11-27 09:41:26 -03:00
|
|
|
[[nodiscard]] bool RenameOver(fs::path src, fs::path dest);
|
2017-12-26 03:41:55 -03:00
|
|
|
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
2019-01-30 21:05:18 -03:00
|
|
|
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
2018-03-07 08:08:55 -03:00
|
|
|
bool DirIsWritable(const fs::path& directory);
|
2019-01-24 16:20:57 -03:00
|
|
|
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
|
2018-02-13 09:53:17 -03:00
|
|
|
|
2020-03-20 07:41:11 -03:00
|
|
|
/** Get the size of a file by scanning it.
|
|
|
|
*
|
|
|
|
* @param[in] path The file path
|
|
|
|
* @param[in] max Stop seeking beyond this limit
|
|
|
|
* @return The file size or max
|
|
|
|
*/
|
|
|
|
std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
|
|
|
|
|
2018-02-13 09:53:17 -03:00
|
|
|
/** Release all directory locks. This is used for unit testing only, at runtime
|
|
|
|
* the global destructor will take care of the locks.
|
|
|
|
*/
|
|
|
|
void ReleaseDirectoryLocks();
|
|
|
|
|
2017-02-22 06:10:00 -03:00
|
|
|
bool TryCreateDirectories(const fs::path& p);
|
2017-03-01 13:05:50 -03:00
|
|
|
fs::path GetDefaultDataDir();
|
2018-10-05 15:04:08 -03:00
|
|
|
// The blocks directory is always net specific.
|
|
|
|
const fs::path &GetBlocksDir();
|
2017-03-01 13:05:50 -03:00
|
|
|
const fs::path &GetDataDir(bool fNetSpecific = true);
|
2019-07-23 20:21:25 -04:00
|
|
|
// Return true if -datadir option points to a valid directory or is not specified.
|
|
|
|
bool CheckDataDirOption();
|
2019-06-27 14:11:25 -04:00
|
|
|
/** Tests only */
|
2015-03-03 12:49:12 -03:00
|
|
|
void ClearDatadirCache();
|
2017-03-01 13:05:50 -03:00
|
|
|
fs::path GetConfigFile(const std::string& confPath);
|
2012-04-22 11:22:45 -03:00
|
|
|
#ifdef WIN32
|
2017-03-01 13:05:50 -03:00
|
|
|
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
2012-04-22 11:22:45 -03:00
|
|
|
#endif
|
2018-05-29 09:37:53 -04:00
|
|
|
#ifndef WIN32
|
|
|
|
std::string ShellEscape(const std::string& arg);
|
|
|
|
#endif
|
2019-07-05 12:30:15 -04:00
|
|
|
#if HAVE_SYSTEM
|
2015-05-31 10:36:44 -03:00
|
|
|
void runCommand(const std::string& strCommand);
|
2019-03-14 07:30:37 -03:00
|
|
|
#endif
|
2020-01-30 08:07:57 -03:00
|
|
|
#ifdef HAVE_BOOST_PROCESS
|
|
|
|
/**
|
|
|
|
* Execute a command which returns JSON, and parse the result.
|
|
|
|
*
|
|
|
|
* @param str_command The command to execute, including any arguments
|
|
|
|
* @param str_std_in string to pass to stdin
|
|
|
|
* @return parsed JSON
|
|
|
|
*/
|
|
|
|
UniValue RunCommandParseJSON(const std::string& str_command, const std::string& str_std_in="");
|
|
|
|
#endif // HAVE_BOOST_PROCESS
|
2011-05-14 04:31:46 -04:00
|
|
|
|
2018-01-31 00:33:49 -03:00
|
|
|
/**
|
|
|
|
* Most paths passed as configuration arguments are treated as relative to
|
|
|
|
* the datadir if they are not absolute.
|
|
|
|
*
|
|
|
|
* @param path The path to be conditionally prefixed with datadir.
|
|
|
|
* @param net_specific Forwarded to GetDataDir().
|
|
|
|
* @return The normalized path.
|
|
|
|
*/
|
|
|
|
fs::path AbsPathForConfigVal(const fs::path& path, bool net_specific = true);
|
|
|
|
|
2011-05-14 04:31:46 -04:00
|
|
|
inline bool IsSwitchChar(char c)
|
|
|
|
{
|
2011-10-07 12:02:21 -03:00
|
|
|
#ifdef WIN32
|
2011-05-14 04:31:46 -04:00
|
|
|
return c == '-' || c == '/';
|
|
|
|
#else
|
|
|
|
return c == '-';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-28 20:40:51 -03:00
|
|
|
enum class OptionsCategory {
|
2018-04-28 17:54:58 -03:00
|
|
|
OPTIONS,
|
|
|
|
CONNECTION,
|
|
|
|
WALLET,
|
|
|
|
WALLET_DEBUG_TEST,
|
|
|
|
ZMQ,
|
|
|
|
DEBUG_TEST,
|
|
|
|
CHAINPARAMS,
|
|
|
|
NODE_RELAY,
|
|
|
|
BLOCK_CREATION,
|
|
|
|
RPC,
|
|
|
|
GUI,
|
|
|
|
COMMANDS,
|
2018-04-28 20:40:51 -03:00
|
|
|
REGISTER_COMMANDS,
|
|
|
|
|
|
|
|
HIDDEN // Always the last option to avoid printing these in the help
|
2018-04-28 17:54:58 -03:00
|
|
|
};
|
|
|
|
|
2019-02-04 00:53:19 -03:00
|
|
|
struct SectionInfo
|
|
|
|
{
|
|
|
|
std::string m_name;
|
|
|
|
std::string m_file;
|
|
|
|
int m_line;
|
|
|
|
};
|
|
|
|
|
2017-05-05 20:36:47 -03:00
|
|
|
class ArgsManager
|
|
|
|
{
|
2019-07-27 03:19:53 -04:00
|
|
|
public:
|
2021-02-04 16:03:58 -03:00
|
|
|
enum Flags : uint32_t {
|
2019-07-27 03:19:53 -04:00
|
|
|
// Boolean options can accept negation syntax -noOPTION or -noOPTION=1
|
|
|
|
ALLOW_BOOL = 0x01,
|
|
|
|
ALLOW_INT = 0x02,
|
|
|
|
ALLOW_STRING = 0x04,
|
|
|
|
ALLOW_ANY = ALLOW_BOOL | ALLOW_INT | ALLOW_STRING,
|
|
|
|
DEBUG_ONLY = 0x100,
|
|
|
|
/* Some options would cause cross-contamination if values for
|
|
|
|
* mainnet were used while running on regtest/testnet (or vice-versa).
|
|
|
|
* Setting them as NETWORK_ONLY ensures that sharing a config file
|
|
|
|
* between mainnet and regtest/testnet won't cause problems due to these
|
|
|
|
* parameters by accident. */
|
|
|
|
NETWORK_ONLY = 0x200,
|
2020-01-20 12:32:42 -03:00
|
|
|
// This argument's value is sensitive (such as a password).
|
|
|
|
SENSITIVE = 0x400,
|
2021-01-13 05:00:43 -03:00
|
|
|
COMMAND = 0x800,
|
2019-07-27 03:19:53 -04:00
|
|
|
};
|
|
|
|
|
2017-05-05 20:36:47 -03:00
|
|
|
protected:
|
2018-05-16 15:15:18 -04:00
|
|
|
struct Arg
|
|
|
|
{
|
|
|
|
std::string m_help_param;
|
|
|
|
std::string m_help_text;
|
2019-07-27 03:19:53 -04:00
|
|
|
unsigned int m_flags;
|
2018-05-16 15:15:18 -04:00
|
|
|
};
|
|
|
|
|
2020-01-07 13:14:15 -03:00
|
|
|
mutable RecursiveMutex cs_args;
|
2019-04-22 18:08:51 -04:00
|
|
|
util::Settings m_settings GUARDED_BY(cs_args);
|
2021-01-13 05:00:43 -03:00
|
|
|
std::vector<std::string> m_command GUARDED_BY(cs_args);
|
2018-08-29 17:33:33 -03:00
|
|
|
std::string m_network GUARDED_BY(cs_args);
|
|
|
|
std::set<std::string> m_network_only_args GUARDED_BY(cs_args);
|
|
|
|
std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args GUARDED_BY(cs_args);
|
2021-01-13 05:00:43 -03:00
|
|
|
bool m_accept_any_command GUARDED_BY(cs_args){true};
|
2019-02-04 00:53:19 -03:00
|
|
|
std::list<SectionInfo> m_config_sections GUARDED_BY(cs_args);
|
2018-03-21 23:24:17 -03:00
|
|
|
|
2020-11-26 06:05:59 -03:00
|
|
|
[[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false);
|
2018-03-29 02:02:00 -03:00
|
|
|
|
2019-11-12 15:47:19 -03:00
|
|
|
/**
|
|
|
|
* Returns true if settings values from the default section should be used,
|
|
|
|
* depending on the current network and whether the setting is
|
|
|
|
* network-specific.
|
|
|
|
*/
|
|
|
|
bool UseDefaultSection(const std::string& arg) const EXCLUSIVE_LOCKS_REQUIRED(cs_args);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get setting value.
|
|
|
|
*
|
|
|
|
* Result will be null if setting was unset, true if "-setting" argument was passed
|
|
|
|
* false if "-nosetting" argument was passed, and a string if a "-setting=value"
|
|
|
|
* argument was passed.
|
|
|
|
*/
|
|
|
|
util::SettingsValue GetSetting(const std::string& arg) const;
|
|
|
|
|
2019-11-12 15:56:18 -03:00
|
|
|
/**
|
|
|
|
* Get list of setting values.
|
|
|
|
*/
|
|
|
|
std::vector<util::SettingsValue> GetSettingsList(const std::string& arg) const;
|
|
|
|
|
2017-05-05 20:36:47 -03:00
|
|
|
public:
|
2018-04-04 05:06:00 -03:00
|
|
|
ArgsManager();
|
2020-04-16 12:26:01 -04:00
|
|
|
~ArgsManager();
|
2018-04-04 05:06:00 -03:00
|
|
|
|
2018-04-04 05:03:00 -03:00
|
|
|
/**
|
|
|
|
* Select the network in use
|
|
|
|
*/
|
|
|
|
void SelectConfigNetwork(const std::string& network);
|
|
|
|
|
2020-11-26 06:05:59 -03:00
|
|
|
[[nodiscard]] bool ParseParameters(int argc, const char* const argv[], std::string& error);
|
|
|
|
[[nodiscard]] bool ReadConfigFiles(std::string& error, bool ignore_invalid_keys = false);
|
2017-07-21 19:00:52 -04:00
|
|
|
|
2018-04-04 05:07:00 -03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-11-11 23:06:36 -03:00
|
|
|
const std::set<std::string> GetUnsuitableSectionOnlyArgs() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Log warnings for unrecognized section names in the config file.
|
|
|
|
*/
|
2019-02-04 00:53:19 -03:00
|
|
|
const std::list<SectionInfo> GetUnrecognizedSections() const;
|
2018-04-04 05:07:00 -03:00
|
|
|
|
2021-01-13 05:00:43 -03:00
|
|
|
struct Command {
|
|
|
|
/** The command (if one has been registered with AddCommand), or empty */
|
|
|
|
std::string command;
|
|
|
|
/**
|
|
|
|
* If command is non-empty: Any args that followed it
|
|
|
|
* If command is empty: The unregistered command and any args that followed it
|
|
|
|
*/
|
|
|
|
std::vector<std::string> args;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Get the command and command args (returns std::nullopt if no command provided)
|
|
|
|
*/
|
|
|
|
std::optional<const Command> GetCommand() const;
|
|
|
|
|
2017-07-21 19:00:52 -04:00
|
|
|
/**
|
|
|
|
* Return a vector of strings of the given argument
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return command-line arguments
|
|
|
|
*/
|
|
|
|
std::vector<std::string> GetArgs(const std::string& strArg) const;
|
2011-05-14 04:31:46 -04:00
|
|
|
|
2017-06-14 17:13:00 -04:00
|
|
|
/**
|
|
|
|
* Return true if the given argument has been manually set
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return true if the argument has been set
|
|
|
|
*/
|
2017-07-21 19:00:52 -04:00
|
|
|
bool IsArgSet(const std::string& strArg) const;
|
2017-06-14 17:13:00 -04:00
|
|
|
|
2018-03-21 23:24:17 -03:00
|
|
|
/**
|
|
|
|
* Return true if the argument was originally passed as a negated option,
|
|
|
|
* i.e. -nofoo.
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @return true if the argument was passed negated
|
|
|
|
*/
|
|
|
|
bool IsArgNegated(const std::string& strArg) const;
|
|
|
|
|
2017-06-14 17:13:00 -04:00
|
|
|
/**
|
|
|
|
* Return string argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 06:20:49 -04:00
|
|
|
* @param strDefault (e.g. "1")
|
2017-06-14 17:13:00 -04:00
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
2017-07-21 19:00:52 -04:00
|
|
|
std::string GetArg(const std::string& strArg, const std::string& strDefault) const;
|
2017-06-14 17:13:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return integer argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 06:20:49 -04:00
|
|
|
* @param nDefault (e.g. 1)
|
2017-06-14 17:13:00 -04:00
|
|
|
* @return command-line argument (0 if invalid number) or default value
|
|
|
|
*/
|
2017-07-21 19:00:52 -04:00
|
|
|
int64_t GetArg(const std::string& strArg, int64_t nDefault) const;
|
2017-06-14 17:13:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return boolean argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
2017-07-16 06:20:49 -04:00
|
|
|
* @param fDefault (true or false)
|
2017-06-14 17:13:00 -04:00
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
2017-07-21 19:00:52 -04:00
|
|
|
bool GetBoolArg(const std::string& strArg, bool fDefault) const;
|
2017-06-14 17:13:00 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an argument if it doesn't already have a value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to set (e.g. "-foo")
|
|
|
|
* @param strValue Value (e.g. "1")
|
|
|
|
* @return true if argument gets set, false if it already had a value
|
|
|
|
*/
|
|
|
|
bool SoftSetArg(const std::string& strArg, const std::string& strValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a boolean argument if it doesn't already have a value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to set (e.g. "-foo")
|
|
|
|
* @param fValue Value (e.g. false)
|
|
|
|
* @return true if argument gets set, false if it already had a value
|
|
|
|
*/
|
|
|
|
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
|
|
|
|
|
|
|
|
// Forces an arg setting. Called by SoftSetArg() if the arg hasn't already
|
|
|
|
// been set. Also called directly in testing.
|
|
|
|
void ForceSetArg(const std::string& strArg, const std::string& strValue);
|
2018-03-21 23:24:17 -03:00
|
|
|
|
2018-03-29 02:00:00 -03:00
|
|
|
/**
|
2019-10-28 14:33:40 -03:00
|
|
|
* Returns the appropriate chain name from the program arguments.
|
2018-03-29 02:00:00 -03:00
|
|
|
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
|
|
|
|
*/
|
|
|
|
std::string GetChainName() const;
|
2018-04-28 17:54:58 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add argument
|
|
|
|
*/
|
scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
2019-07-27 05:06:32 -04:00
|
|
|
void AddArg(const std::string& name, const std::string& help, unsigned int flags, const OptionsCategory& cat);
|
2018-04-28 17:54:58 -03:00
|
|
|
|
2021-01-13 05:00:43 -03:00
|
|
|
/**
|
|
|
|
* Add subcommand
|
|
|
|
*/
|
|
|
|
void AddCommand(const std::string& cmd, const std::string& help, const OptionsCategory& cat);
|
|
|
|
|
2018-06-11 17:23:13 -04:00
|
|
|
/**
|
|
|
|
* Add many hidden arguments
|
|
|
|
*/
|
|
|
|
void AddHiddenArgs(const std::vector<std::string>& args);
|
|
|
|
|
2018-04-28 20:40:51 -03:00
|
|
|
/**
|
|
|
|
* Clear available arguments
|
|
|
|
*/
|
2018-08-27 18:19:18 -03:00
|
|
|
void ClearArgs() {
|
|
|
|
LOCK(cs_args);
|
|
|
|
m_available_args.clear();
|
2019-07-27 05:37:09 -04:00
|
|
|
m_network_only_args.clear();
|
2018-08-27 18:19:18 -03:00
|
|
|
}
|
2018-04-28 20:40:51 -03:00
|
|
|
|
2018-04-28 17:54:58 -03:00
|
|
|
/**
|
|
|
|
* Get the help string
|
|
|
|
*/
|
2018-07-21 05:53:54 -04:00
|
|
|
std::string GetHelpMessage() const;
|
2018-04-28 20:40:51 -03:00
|
|
|
|
|
|
|
/**
|
2019-07-27 07:41:27 -04:00
|
|
|
* Return Flags for known arg.
|
2019-11-11 21:05:12 -03:00
|
|
|
* Return nullopt for unknown arg.
|
2018-04-28 20:40:51 -03:00
|
|
|
*/
|
2019-11-11 21:05:12 -03:00
|
|
|
Optional<unsigned int> GetArgFlags(const std::string& name) const;
|
2020-01-20 12:32:42 -03:00
|
|
|
|
2019-04-28 19:08:26 -04:00
|
|
|
/**
|
|
|
|
* Read and update settings file with saved settings. This needs to be
|
|
|
|
* called after SelectParams() because the settings file location is
|
|
|
|
* network-specific.
|
|
|
|
*/
|
|
|
|
bool InitSettings(std::string& error);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get settings file path, or return false if read-write settings were
|
|
|
|
* disabled with -nosettings.
|
|
|
|
*/
|
|
|
|
bool GetSettingsPath(fs::path* filepath = nullptr, bool temp = false) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read settings file. Push errors to vector, or log them if null.
|
|
|
|
*/
|
|
|
|
bool ReadSettingsFile(std::vector<std::string>* errors = nullptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write settings file. Push errors to vector, or log them if null.
|
|
|
|
*/
|
|
|
|
bool WriteSettingsFile(std::vector<std::string>* errors = nullptr) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Access settings with lock held.
|
|
|
|
*/
|
|
|
|
template <typename Fn>
|
|
|
|
void LockSettings(Fn&& fn)
|
|
|
|
{
|
|
|
|
LOCK(cs_args);
|
|
|
|
fn(m_settings);
|
|
|
|
}
|
|
|
|
|
2020-01-20 12:32:42 -03:00
|
|
|
/**
|
|
|
|
* Log the config file options and the command line arguments,
|
|
|
|
* useful for troubleshooting.
|
|
|
|
*/
|
|
|
|
void LogArgs() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helper function for LogArgs().
|
|
|
|
void logArgsPrefix(
|
|
|
|
const std::string& prefix,
|
|
|
|
const std::string& section,
|
|
|
|
const std::map<std::string, std::vector<util::SettingsValue>>& args) const;
|
2017-05-05 20:36:47 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern ArgsManager gArgs;
|
|
|
|
|
2018-03-30 17:47:36 -03:00
|
|
|
/**
|
|
|
|
* @return true if help has been requested via a command-line arg
|
|
|
|
*/
|
|
|
|
bool HelpRequested(const ArgsManager& args);
|
|
|
|
|
2019-02-06 15:57:52 -03:00
|
|
|
/** Add help options to the args manager */
|
|
|
|
void SetupHelpOptions(ArgsManager& args);
|
|
|
|
|
2015-02-04 05:11:49 -03:00
|
|
|
/**
|
|
|
|
* Format a string to be used as group of options in help messages
|
|
|
|
*
|
|
|
|
* @param message Group name (e.g. "RPC server options:")
|
|
|
|
* @return the formatted string
|
|
|
|
*/
|
|
|
|
std::string HelpMessageGroup(const std::string& message);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format a string to be used as option description in help messages
|
|
|
|
*
|
|
|
|
* @param option Option message (e.g. "-rpcuser=<user>")
|
|
|
|
* @param message Option description (e.g. "Username for JSON-RPC connections")
|
|
|
|
* @return the formatted string
|
|
|
|
*/
|
|
|
|
std::string HelpMessageOpt(const std::string& option, const std::string& message);
|
|
|
|
|
2015-07-01 12:38:15 -03:00
|
|
|
/**
|
2017-04-24 22:34:23 -03:00
|
|
|
* Return the number of cores available on the current system.
|
|
|
|
* @note This does count virtual cores, such as those provided by HyperThreading.
|
2015-07-01 12:38:15 -03:00
|
|
|
*/
|
|
|
|
int GetNumCores();
|
|
|
|
|
2014-11-17 00:04:01 -03:00
|
|
|
/**
|
|
|
|
* .. and a wrapper that just calls func once
|
|
|
|
*/
|
2013-03-08 22:19:17 -03:00
|
|
|
template <typename Callable> void TraceThread(const char* name, Callable func)
|
|
|
|
{
|
2018-06-13 14:50:59 -04:00
|
|
|
util::ThreadRename(name);
|
2013-03-08 22:19:17 -03:00
|
|
|
try
|
|
|
|
{
|
2013-09-18 07:38:08 -03:00
|
|
|
LogPrintf("%s thread start\n", name);
|
2013-03-08 22:19:17 -03:00
|
|
|
func();
|
2013-09-18 07:38:08 -03:00
|
|
|
LogPrintf("%s thread exit\n", name);
|
2013-03-08 22:19:17 -03:00
|
|
|
}
|
2014-12-07 09:29:06 -03:00
|
|
|
catch (const std::exception& e) {
|
2014-02-26 09:23:52 -03:00
|
|
|
PrintExceptionContinue(&e, name);
|
|
|
|
throw;
|
2013-03-08 22:19:17 -03:00
|
|
|
}
|
|
|
|
catch (...) {
|
2017-08-07 01:36:37 -04:00
|
|
|
PrintExceptionContinue(nullptr, name);
|
2014-02-26 09:23:52 -03:00
|
|
|
throw;
|
2013-03-08 22:19:17 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-03 02:38:27 -03:00
|
|
|
std::string CopyrightHolders(const std::string& strPrefix);
|
2015-12-22 09:29:13 -03:00
|
|
|
|
2018-03-06 14:50:20 -03:00
|
|
|
/**
|
|
|
|
* On platforms that support it, tell the kernel the calling thread is
|
|
|
|
* CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details.
|
|
|
|
*
|
|
|
|
*/
|
2019-11-25 19:31:31 -03:00
|
|
|
void ScheduleBatchPriority();
|
2018-03-06 14:50:20 -03:00
|
|
|
|
2018-07-17 01:05:04 -04:00
|
|
|
namespace util {
|
|
|
|
|
|
|
|
//! Simplification of std insertion
|
|
|
|
template <typename Tdst, typename Tsrc>
|
|
|
|
inline void insert(Tdst& dst, const Tsrc& src) {
|
|
|
|
dst.insert(dst.begin(), src.begin(), src.end());
|
|
|
|
}
|
|
|
|
template <typename TsetT, typename Tsrc>
|
|
|
|
inline void insert(std::set<TsetT>& dst, const Tsrc& src) {
|
|
|
|
dst.insert(src.begin(), src.end());
|
|
|
|
}
|
|
|
|
|
2018-08-05 12:38:25 -04:00
|
|
|
#ifdef WIN32
|
|
|
|
class WinCmdLineArgs
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
WinCmdLineArgs();
|
|
|
|
~WinCmdLineArgs();
|
|
|
|
std::pair<int, char**> get();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int argc;
|
|
|
|
char** argv;
|
|
|
|
std::vector<std::string> args;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 01:05:04 -04:00
|
|
|
} // namespace util
|
|
|
|
|
2018-10-22 19:51:11 -03:00
|
|
|
#endif // BITCOIN_UTIL_SYSTEM_H
|