35 std::string::size_type pos;
37 while (std::getline(
stream, str)) {
39 if ((pos = str.find(
'#')) != std::string::npos) {
40 str = str.substr(0, pos);
43 const static std::string
pattern =
" \t\r\n";
46 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
47 const std::string section = str.substr(1, str.size() - 2);
50 }
else if (*str.begin() ==
'-') {
51 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -",
linenr, str);
53 }
else if ((pos = str.find(
'=')) != std::string::npos) {
54 std::string
name =
prefix + TrimString(std::string_view{str}.substr(0, pos),
pattern);
55 std::string_view value = TrimStringView(std::string_view{str}.substr(pos + 1),
pattern);
56 if (
used_hash &&
name.find(
"rpcpassword") != std::string::npos) {
57 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided",
linenr);
60 options.emplace_back(
name, value);
61 if ((pos =
name.rfind(
'.')) != std::string::npos &&
prefix.length() <= pos) {
66 if (str.size() >= 2 && str.starts_with(
"no")) {
67 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
78 if (key.
name ==
"conf") {
79 error =
"conf cannot be set in the configuration file; use includeconf= if you want to include additional config files";
82 if (key.
name ==
"reindex") {
85 LogWarning(
"reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary");
94 std::vector<std::pair<std::string, std::string>> options;
98 for (
const std::pair<std::string, std::string>&
option : options) {
176 auto add_includes = [&](
const std::string& network,
size_t skip = 0) {
223 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n",
conf_file_name);
231 error =
strprintf(
"specified data directory \"%s\" does not exist.",
GetArg(
"-datadir",
""));
239 if (path.is_absolute() || path.empty()) {
std::optional< common::SettingsValue > InterpretValue(const KeyInfo &key, const std::string *value, unsigned int flags, std::string &error)
Interpret settings value based on registered flags.
bool CheckDataDirOption(const ArgsManager &args)
fs::path AbsPathForConfigVal(const ArgsManager &args, const fs::path &path, bool net_specific=true)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
KeyInfo InterpretKey(std::string key)
Parse "name", "section.name", "noname", "section.noname" settings keys.
const char *const BITCOIN_CONF_FILENAME
bool ReadConfigString(const std::string &str_config) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
fs::path GetDataDirBase() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Get data directory path.
fs::path GetConfigFilePath() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return config file path (read-only)
fs::path GetPathArg_(std::string arg, const fs::path &default_value={}) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
void ClearPathCache() EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Clear cached directory paths.
fs::path GetDataDir(bool net_specific) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
Get data directory path.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return string argument or default value.
std::string GetChainTypeString() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Returns the appropriate chain type string from the program arguments.
bool IsArgSet(const std::string &strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return true if the given argument has been manually set.
fs::path GetDataDirNet() const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Get data directory path with appended network identifier.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
std::optional< unsigned int > GetArgFlags_(const std::string &name) const EXCLUSIVE_LOCKS_REQUIRED(cs_args)
static bool GetConfigOptions(std::istream &stream, const std::string &filepath, std::string &error, std::vector< std::pair< std::string, std::string > > &options, std::list< SectionInfo > §ions)
bool IsConfSupported(KeyInfo &key, std::string &error)
fs::path AbsPathForConfigVal(const ArgsManager &args, const fs::path &path, bool net_specific)
Most paths passed as configuration arguments are treated as relative to the datadir if they are not a...
static std::string PathToString(const path &path)
Convert path object to a byte string.
auto FindKey(Map &&map, Key &&key) -> decltype(&map.at(key))
Map lookup helper.
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
std::string_view TrimStringView(std::string_view str LIFETIMEBOUND, std::string_view pattern=" \f\n\r\t\v")
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
static const int64_t values[]
A selection of numbers that do not trigger int64_t overflow when added/subtracted.
Accessor for list of settings that skips negated values when iterated over.
bool last_negated() const
True if the last value is negated.
size_t negated() const
Number of negated values.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.