2011-05-14 10:31:46 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2019-01-29 15:53:14 +01:00
|
|
|
// Copyright (c) 2014-2019 The Dash Core developers
|
2014-11-17 04:04:01 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 16:02:28 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-13 07:13:08 +02: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 16:11:09 +02:00
|
|
|
/**
|
|
|
|
* Server/client environment: argument handling, config file parsing,
|
|
|
|
* logging, thread wrappers
|
|
|
|
*/
|
2011-05-14 10:31:46 +02:00
|
|
|
#ifndef BITCOIN_UTIL_H
|
|
|
|
#define BITCOIN_UTIL_H
|
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2015-04-03 00:51:08 +02:00
|
|
|
#include "config/dash-config.h"
|
2013-04-13 07:13:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "compat.h"
|
2017-04-06 20:19:21 +02:00
|
|
|
#include "fs.h"
|
2014-01-16 15:52:37 +01:00
|
|
|
#include "tinyformat.h"
|
2014-09-14 12:43:56 +02:00
|
|
|
#include "utiltime.h"
|
2016-01-24 05:21:14 +01:00
|
|
|
#include "amount.h"
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2016-06-01 20:23:11 +02:00
|
|
|
#include <atomic>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <exception>
|
|
|
|
#include <map>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string>
|
Collection of minor performance optimizations (#2855)
* Merge #13176: Improve CRollingBloomFilter performance: replace modulus with FastMod
9aac9f90d5e56752cc6cbfac48063ad29a01143c replace modulus with FastMod (Martin Ankerl)
Pull request description:
Not sure if this is optimization is necessary, but anyway I have some spare time so here it is. This replaces the slow modulo operation with a much faster 64bit multiplication & shift. This works when the hash is uniformly distributed between 0 and 2^32-1. This speeds up the benchmark by a factor of about 1.3:
```
RollingBloom, 5, 1500000, 3.73733, 4.97569e-07, 4.99002e-07, 4.98372e-07 # before
RollingBloom, 5, 1500000, 2.86842, 3.81630e-07, 3.83730e-07, 3.82473e-07 # FastMod
```
Be aware that this changes the internal data of the filter, so this should probably
not be used for CBloomFilter because of interoperability problems.
Tree-SHA512: 04104f3fb09f56c9d14458a6aad919aeb0a5af944e8ee6a31f00e93c753e22004648c1cd65bf36752b6addec528d19fb665c27b955ce1666a85a928e17afa47a
* Use unordered_map in CSporkManager
In one of my profiling sessions with many InstantSend transactions
happening, calls into CSporkManager added up to about 1% of total CPU time.
This is easily avoidable by using unordered maps.
* Use std::unordered_map instead of std::map in limitedmap
* Use unordered_set for CNode::setAskFor
* Add serialization support for unordered maps and sets
* Use unordered_map for mapArgs and mapMultiArgs
* Let limitedmap prune in batches and use unordered_multimap
Due to the batched pruning, there is no need to maintain an ordered map
of values anymore. Only when nPruneAfterSize, there is a need to create
a temporary ordered vector of values to figure out what can be removed.
* Instead of using a multimap for mapAskFor, use a vector which we sort on demand
CNode::AskFor will now push entries into an initially unordered vector
instead of an ordered multimap. Only when we later want to use vecAskFor in
SendMessages, we sort the vector.
The vector will actually be mostly sorted in most cases as insertion order
usually mimics the desired ordering. Only the last few entries might need
some shuffling around. Doing the sort on-demand should be less wasteful
then trying to maintain correct order all the time.
* Fix compilation of tests
* Fix limitedmap tests
* Rename limitedmap to unordered_limitedmap to ensure backports conflict
This ensures that future backports that depends on limitedmap's ordering
conflict so that we are made aware of needed action.
* Fix compilation error on Travis
2019-04-11 14:42:14 +02:00
|
|
|
#include <unordered_map>
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <vector>
|
2013-05-24 15:45:08 +02:00
|
|
|
|
2015-04-16 16:20:01 +02:00
|
|
|
#include <boost/signals2/signal.hpp>
|
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 16:11:09 +02:00
|
|
|
#include <boost/thread/exceptions.hpp>
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
// Debugging macros
|
|
|
|
|
|
|
|
// Uncomment the following line to enable debugging messages
|
|
|
|
// or enable on a per file basis prior to inclusion of util.h
|
|
|
|
//#define ENABLE_DASH_DEBUG
|
|
|
|
#ifdef ENABLE_DASH_DEBUG
|
|
|
|
#define DBG( x ) x
|
|
|
|
#else
|
2017-03-17 10:28:50 +01:00
|
|
|
#define DBG( x )
|
2016-08-17 09:08:25 +02:00
|
|
|
#endif
|
|
|
|
|
2015-03-18 00:06:58 +01:00
|
|
|
//Dash only features
|
2014-12-09 02:17:57 +01:00
|
|
|
|
2018-01-26 02:11:01 +01:00
|
|
|
extern bool fMasternodeMode;
|
2015-01-18 16:28:16 +01:00
|
|
|
extern bool fLiteMode;
|
2016-06-15 21:13:04 +02:00
|
|
|
extern int nWalletBackups;
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2016-09-16 19:16:22 +02:00
|
|
|
static const bool DEFAULT_LOGTIMEMICROS = false;
|
|
|
|
static const bool DEFAULT_LOGIPS = false;
|
|
|
|
static const bool DEFAULT_LOGTIMESTAMPS = true;
|
2016-03-14 22:04:48 +01:00
|
|
|
static const bool DEFAULT_LOGTHREADNAMES = false;
|
2015-10-23 19:07:36 +02:00
|
|
|
|
2015-04-16 16:20:01 +02:00
|
|
|
/** Signals for translation. */
|
|
|
|
class CTranslationInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Translate a message to the native language of the user. */
|
|
|
|
boost::signals2::signal<std::string (const char* psz)> Translate;
|
|
|
|
};
|
|
|
|
|
Collection of minor performance optimizations (#2855)
* Merge #13176: Improve CRollingBloomFilter performance: replace modulus with FastMod
9aac9f90d5e56752cc6cbfac48063ad29a01143c replace modulus with FastMod (Martin Ankerl)
Pull request description:
Not sure if this is optimization is necessary, but anyway I have some spare time so here it is. This replaces the slow modulo operation with a much faster 64bit multiplication & shift. This works when the hash is uniformly distributed between 0 and 2^32-1. This speeds up the benchmark by a factor of about 1.3:
```
RollingBloom, 5, 1500000, 3.73733, 4.97569e-07, 4.99002e-07, 4.98372e-07 # before
RollingBloom, 5, 1500000, 2.86842, 3.81630e-07, 3.83730e-07, 3.82473e-07 # FastMod
```
Be aware that this changes the internal data of the filter, so this should probably
not be used for CBloomFilter because of interoperability problems.
Tree-SHA512: 04104f3fb09f56c9d14458a6aad919aeb0a5af944e8ee6a31f00e93c753e22004648c1cd65bf36752b6addec528d19fb665c27b955ce1666a85a928e17afa47a
* Use unordered_map in CSporkManager
In one of my profiling sessions with many InstantSend transactions
happening, calls into CSporkManager added up to about 1% of total CPU time.
This is easily avoidable by using unordered maps.
* Use std::unordered_map instead of std::map in limitedmap
* Use unordered_set for CNode::setAskFor
* Add serialization support for unordered maps and sets
* Use unordered_map for mapArgs and mapMultiArgs
* Let limitedmap prune in batches and use unordered_multimap
Due to the batched pruning, there is no need to maintain an ordered map
of values anymore. Only when nPruneAfterSize, there is a need to create
a temporary ordered vector of values to figure out what can be removed.
* Instead of using a multimap for mapAskFor, use a vector which we sort on demand
CNode::AskFor will now push entries into an initially unordered vector
instead of an ordered multimap. Only when we later want to use vecAskFor in
SendMessages, we sort the vector.
The vector will actually be mostly sorted in most cases as insertion order
usually mimics the desired ordering. Only the last few entries might need
some shuffling around. Doing the sort on-demand should be less wasteful
then trying to maintain correct order all the time.
* Fix compilation of tests
* Fix limitedmap tests
* Rename limitedmap to unordered_limitedmap to ensure backports conflict
This ensures that future backports that depends on limitedmap's ordering
conflict so that we are made aware of needed action.
* Fix compilation error on Travis
2019-04-11 14:42:14 +02:00
|
|
|
extern const std::unordered_map<std::string, std::vector<std::string> >& mapMultiArgs;
|
2011-05-14 10:31:46 +02:00
|
|
|
extern bool fPrintToConsole;
|
2013-12-14 13:51:11 +01:00
|
|
|
extern bool fPrintToDebugLog;
|
2016-12-19 12:38:35 +01:00
|
|
|
|
2011-05-14 10:31:46 +02:00
|
|
|
extern bool fLogTimestamps;
|
2015-10-23 19:07:36 +02:00
|
|
|
extern bool fLogTimeMicros;
|
2016-03-14 22:04:48 +01:00
|
|
|
extern bool fLogThreadNames;
|
2014-02-27 02:55:04 +01:00
|
|
|
extern bool fLogIPs;
|
2016-06-01 20:23:11 +02:00
|
|
|
extern std::atomic<bool> fReopenDebugLog;
|
2015-04-16 16:20:01 +02:00
|
|
|
extern CTranslationInterface translationInterface;
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
extern const char * const BITCOIN_CONF_FILENAME;
|
|
|
|
extern const char * const BITCOIN_PID_FILENAME;
|
|
|
|
|
2019-05-22 23:51:39 +02:00
|
|
|
extern std::atomic<uint64_t> logCategories;
|
|
|
|
|
2015-04-16 16:20:01 +02:00
|
|
|
/**
|
|
|
|
* Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
|
|
|
|
* If no translation slot is registered, nothing is returned, and simply return the input.
|
|
|
|
*/
|
|
|
|
inline std::string _(const char* psz)
|
|
|
|
{
|
|
|
|
boost::optional<std::string> rv = translationInterface.Translate(psz);
|
|
|
|
return rv ? (*rv) : psz;
|
|
|
|
}
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2014-05-13 12:15:00 +02:00
|
|
|
void SetupEnvironment();
|
2015-09-02 16:18:16 +02:00
|
|
|
bool SetupNetworking();
|
2013-09-18 10:03:21 +02:00
|
|
|
|
2019-05-22 23:51:39 +02:00
|
|
|
namespace BCLog {
|
|
|
|
enum LogFlags : uint64_t {
|
|
|
|
NONE = 0,
|
|
|
|
NET = (1 << 0),
|
|
|
|
TOR = (1 << 1),
|
|
|
|
MEMPOOL = (1 << 2),
|
|
|
|
HTTP = (1 << 3),
|
|
|
|
BENCHMARK = (1 << 4),
|
|
|
|
ZMQ = (1 << 5),
|
|
|
|
DB = (1 << 6),
|
|
|
|
RPC = (1 << 7),
|
|
|
|
ESTIMATEFEE = (1 << 8),
|
|
|
|
ADDRMAN = (1 << 9),
|
|
|
|
SELECTCOINS = (1 << 10),
|
|
|
|
REINDEX = (1 << 11),
|
|
|
|
CMPCTBLOCK = (1 << 12),
|
|
|
|
RANDOM = (1 << 13),
|
|
|
|
PRUNE = (1 << 14),
|
|
|
|
PROXY = (1 << 15),
|
|
|
|
MEMPOOLREJ = (1 << 16),
|
|
|
|
LIBEVENT = (1 << 17),
|
|
|
|
COINDB = (1 << 18),
|
|
|
|
QT = (1 << 19),
|
|
|
|
LEVELDB = (1 << 20),
|
|
|
|
|
|
|
|
//Start Dash
|
|
|
|
CHAINLOCKS = ((uint64_t)1 << 32),
|
|
|
|
GOBJECT = ((uint64_t)1 << 33),
|
|
|
|
INSTANTSEND = ((uint64_t)1 << 34),
|
|
|
|
KEEPASS = ((uint64_t)1 << 35),
|
|
|
|
LLMQ = ((uint64_t)1 << 36),
|
|
|
|
LLMQ_DKG = ((uint64_t)1 << 37),
|
|
|
|
LLMQ_SIGS = ((uint64_t)1 << 38),
|
|
|
|
MNPAYMENTS = ((uint64_t)1 << 39),
|
|
|
|
MNSYNC = ((uint64_t)1 << 40),
|
|
|
|
PRIVATESEND = ((uint64_t)1 << 41),
|
|
|
|
SPORK = ((uint64_t)1 << 42),
|
|
|
|
ALERT = ((uint64_t)1 << 43),
|
|
|
|
//End Dash
|
|
|
|
|
|
|
|
ALL = ~(uint64_t)0,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
static inline bool LogAcceptCategory(uint64_t category)
|
|
|
|
{
|
|
|
|
return (logCategories.load(std::memory_order_relaxed) & category) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns a string with the supported log categories */
|
|
|
|
std::string ListLogCategories();
|
|
|
|
|
|
|
|
/** Returns a string with the list of active log categories */
|
|
|
|
std::string ListActiveLogCategories();
|
|
|
|
|
|
|
|
/** Return true if str parses as a log category and set the flags in f */
|
|
|
|
bool GetLogCategory(uint64_t *f, const std::string *str);
|
|
|
|
|
2014-11-17 04:04:01 +01:00
|
|
|
/** Send a string to the log output */
|
2014-01-16 15:52:37 +01:00
|
|
|
int LogPrintStr(const std::string &str);
|
|
|
|
|
2018-08-21 17:34:26 +02:00
|
|
|
/** Formats a string without throwing exceptions. Instead, it'll return an error string instead of formatted string. */
|
|
|
|
template<typename... Args>
|
|
|
|
std::string SafeStringFormat(const std::string& fmt, const Args&... args)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
return tinyformat::format(fmt, args...);
|
2017-03-17 10:28:50 +01:00
|
|
|
} catch (std::runtime_error& fmterr) {
|
|
|
|
std::string message = tinyformat::format("\n****TINYFORMAT ERROR****\n err=\"%s\"\n fmt=\"%s\"\n", fmterr.what(), fmt);
|
2018-08-21 17:34:26 +02:00
|
|
|
fprintf(stderr, "%s", message.c_str());
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-21 15:32:33 +02:00
|
|
|
/** Get format string from VA_ARGS for error reporting */
|
|
|
|
template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt, const Args&... args) { return fmt; }
|
|
|
|
|
|
|
|
#define LogPrintf(...) do { \
|
|
|
|
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
|
|
|
|
try { \
|
|
|
|
_log_msg_ = tfm::format(__VA_ARGS__); \
|
|
|
|
} catch (tinyformat::format_error &e) { \
|
|
|
|
/* Original format string will have newline so don't add one here */ \
|
|
|
|
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
|
2017-01-05 10:46:54 +01:00
|
|
|
} \
|
2019-05-21 15:32:33 +02:00
|
|
|
LogPrintStr(_log_msg_); \
|
2017-01-05 10:46:54 +01:00
|
|
|
} while(0)
|
|
|
|
|
2019-05-21 15:32:33 +02:00
|
|
|
#define LogPrint(category, ...) do { \
|
|
|
|
if (LogAcceptCategory((category))) { \
|
|
|
|
LogPrintf(__VA_ARGS__); \
|
|
|
|
} \
|
2017-01-05 10:46:54 +01:00
|
|
|
} while(0)
|
2016-05-05 08:19:35 +02:00
|
|
|
|
2016-07-29 12:32:38 +02:00
|
|
|
template<typename... Args>
|
|
|
|
bool error(const char* fmt, const Args&... args)
|
2016-05-05 08:19:35 +02:00
|
|
|
{
|
2018-08-21 17:34:26 +02:00
|
|
|
LogPrintStr("ERROR: " + SafeStringFormat(fmt, args...) + "\n");
|
2014-01-16 15:52:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
2012-09-09 14:43:06 +02:00
|
|
|
|
2019-02-21 19:37:16 +01:00
|
|
|
void PrintExceptionContinue(const std::exception_ptr pex, const char* pszThread);
|
2012-02-06 18:37:49 +01:00
|
|
|
void ParseParameters(int argc, const char*const argv[]);
|
2016-09-21 14:13:33 +02:00
|
|
|
void FileCommit(FILE *file);
|
2013-01-30 04:17:33 +01:00
|
|
|
bool TruncateFile(FILE *file, unsigned int length);
|
2013-04-26 00:46:47 +02:00
|
|
|
int RaiseFileDescriptorLimit(int nMinFD);
|
2012-08-16 02:21:28 +02:00
|
|
|
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length);
|
2017-04-06 20:19:21 +02:00
|
|
|
bool RenameOver(fs::path src, fs::path dest);
|
|
|
|
bool TryCreateDirectory(const fs::path& p);
|
|
|
|
fs::path GetDefaultDataDir();
|
|
|
|
const fs::path &GetDataDir(bool fNetSpecific = true);
|
2018-01-18 17:55:51 +01:00
|
|
|
boost::filesystem::path GetBackupsDir();
|
2015-03-03 16:49:12 +01:00
|
|
|
void ClearDatadirCache();
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetConfigFile(const std::string& confPath);
|
2013-07-24 09:30:09 +02:00
|
|
|
#ifndef WIN32
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetPidFile();
|
|
|
|
void CreatePidFile(const fs::path &path, pid_t pid);
|
2013-07-24 09:30:09 +02:00
|
|
|
#endif
|
2016-12-27 19:11:21 +01:00
|
|
|
void ReadConfigFile(const std::string& confPath);
|
2012-04-22 16:22:45 +02:00
|
|
|
#ifdef WIN32
|
2017-04-06 20:19:21 +02:00
|
|
|
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
|
2012-04-22 16:22:45 +02:00
|
|
|
#endif
|
2015-05-15 21:31:14 +02:00
|
|
|
void OpenDebugLog();
|
2011-05-14 10:31:46 +02:00
|
|
|
void ShrinkDebugFile();
|
2015-05-31 15:36:44 +02:00
|
|
|
void runCommand(const std::string& strCommand);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
|
|
|
inline bool IsSwitchChar(char c)
|
|
|
|
{
|
2011-10-07 17:02:21 +02:00
|
|
|
#ifdef WIN32
|
2011-05-14 10:31:46 +02:00
|
|
|
return c == '-' || c == '/';
|
|
|
|
#else
|
|
|
|
return c == '-';
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-12-27 19:11:21 +01: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
|
|
|
|
*/
|
|
|
|
bool IsArgSet(const std::string& strArg);
|
|
|
|
|
2012-02-06 18:37:49 +01:00
|
|
|
/**
|
|
|
|
* Return string argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @param default (e.g. "1")
|
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
|
|
|
std::string GetArg(const std::string& strArg, const std::string& strDefault);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2012-02-06 18:37:49 +01:00
|
|
|
/**
|
|
|
|
* Return integer argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @param default (e.g. 1)
|
|
|
|
* @return command-line argument (0 if invalid number) or default value
|
|
|
|
*/
|
2013-04-13 07:13:08 +02:00
|
|
|
int64_t GetArg(const std::string& strArg, int64_t nDefault);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2012-02-06 18:37:49 +01:00
|
|
|
/**
|
|
|
|
* Return boolean argument or default value
|
|
|
|
*
|
|
|
|
* @param strArg Argument to get (e.g. "-foo")
|
|
|
|
* @param default (true or false)
|
|
|
|
* @return command-line argument or default value
|
|
|
|
*/
|
2013-04-28 17:37:50 +02:00
|
|
|
bool GetBoolArg(const std::string& strArg, bool fDefault);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2012-01-03 16:14:22 +01: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
|
|
|
|
*/
|
2012-02-06 21:48:00 +01:00
|
|
|
bool SoftSetBoolArg(const std::string& strArg, bool fValue);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2018-02-21 17:32:08 +01:00
|
|
|
// Forces a arg setting
|
2016-12-27 19:11:21 +01:00
|
|
|
void ForceSetArg(const std::string& strArg, const std::string& strValue);
|
2017-09-21 01:18:39 +02:00
|
|
|
void ForceSetMultiArgs(const std::string& strArg, const std::vector<std::string>& values);
|
2016-12-27 19:11:21 +01:00
|
|
|
void ForceRemoveArg(const std::string& strArg);
|
|
|
|
|
2015-02-04 09:11:49 +01: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);
|
2011-05-14 10:31:46 +02:00
|
|
|
|
2013-08-08 11:58:57 +02:00
|
|
|
/**
|
2015-02-04 09:11:49 +01:00
|
|
|
* 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
|
2013-08-08 11:58:57 +02:00
|
|
|
*/
|
2015-02-04 09:11:49 +01:00
|
|
|
std::string HelpMessageOpt(const std::string& option, const std::string& message);
|
|
|
|
|
2015-07-01 17:38:15 +02:00
|
|
|
/**
|
|
|
|
* Return the number of physical cores available on the current system.
|
|
|
|
* @note This does not count virtual cores, such as those provided by HyperThreading
|
|
|
|
* when boost is newer than 1.56.
|
|
|
|
*/
|
|
|
|
int GetNumCores();
|
|
|
|
|
2012-06-24 17:03:57 +02:00
|
|
|
void RenameThread(const char* name);
|
2016-03-14 22:04:48 +01:00
|
|
|
std::string GetThreadName();
|
2014-11-17 04:04:01 +01:00
|
|
|
|
2018-05-24 13:57:36 +02:00
|
|
|
namespace ctpl {
|
|
|
|
class thread_pool;
|
|
|
|
}
|
|
|
|
void RenameThreadPool(ctpl::thread_pool& tp, const char* baseName);
|
|
|
|
|
2014-11-17 04:04:01 +01:00
|
|
|
/**
|
|
|
|
* .. and a wrapper that just calls func once
|
|
|
|
*/
|
2013-03-09 02:19:17 +01:00
|
|
|
template <typename Callable> void TraceThread(const char* name, Callable func)
|
|
|
|
{
|
2015-03-19 15:15:08 +01:00
|
|
|
std::string s = strprintf("dash-%s", name);
|
2013-03-09 02:19:17 +01:00
|
|
|
RenameThread(s.c_str());
|
|
|
|
try
|
|
|
|
{
|
2013-09-18 12:38:08 +02:00
|
|
|
LogPrintf("%s thread start\n", name);
|
2013-03-09 02:19:17 +01:00
|
|
|
func();
|
2013-09-18 12:38:08 +02:00
|
|
|
LogPrintf("%s thread exit\n", name);
|
2013-03-09 02:19:17 +01:00
|
|
|
}
|
2014-12-07 13:29:06 +01:00
|
|
|
catch (const boost::thread_interrupted&)
|
2013-03-09 02:19:17 +01:00
|
|
|
{
|
2013-09-18 12:38:08 +02:00
|
|
|
LogPrintf("%s thread interrupt\n", name);
|
2013-03-09 02:19:17 +01:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
catch (...) {
|
2019-02-21 19:37:16 +01:00
|
|
|
PrintExceptionContinue(std::current_exception(), name);
|
2014-02-26 13:23:52 +01:00
|
|
|
throw;
|
2013-03-09 02:19:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 15:20:11 +01:00
|
|
|
std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear);
|
2017-07-04 19:31:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Converts version strings to 4-byte unsigned integer
|
|
|
|
* @param strVersion version in "x.x.x" format (decimal digits only)
|
|
|
|
* @return 4-byte unsigned integer, most significant byte is always 0
|
|
|
|
* Throws std::bad_cast if format doesn\t match.
|
|
|
|
*/
|
|
|
|
uint32_t StringVersionToInt(const std::string& strVersion);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Converts version as 4-byte unsigned integer to string
|
|
|
|
* @param nVersion 4-byte unsigned integer, most significant byte is always 0
|
|
|
|
* @return version string in "x.x.x" format (last 3 bytes as version parts)
|
|
|
|
* Throws std::bad_cast if format doesn\t match.
|
|
|
|
*/
|
|
|
|
std::string IntVersionToString(uint32_t nVersion);
|
|
|
|
|
|
|
|
|
2017-07-10 16:41:42 +02:00
|
|
|
/**
|
|
|
|
* @brief Copy of the IntVersionToString, that returns "Invalid version" string
|
|
|
|
* instead of throwing std::bad_cast
|
|
|
|
* @param nVersion 4-byte unsigned integer, most significant byte is always 0
|
|
|
|
* @return version string in "x.x.x" format (last 3 bytes as version parts)
|
|
|
|
* or "Invalid version" if can't cast the given value
|
|
|
|
*/
|
|
|
|
std::string SafeIntVersionToString(uint32_t nVersion);
|
|
|
|
|
|
|
|
|
2014-08-28 22:21:03 +02:00
|
|
|
#endif // BITCOIN_UTIL_H
|