37 std::string::size_type pos;
39 while (std::getline(
stream, str)) {
41 if ((pos = str.find(
'#')) != std::string::npos) {
42 str = str.substr(0, pos);
45 const static std::string
pattern =
" \t\r\n";
48 if (*str.begin() ==
'[' && *str.rbegin() ==
']') {
49 const std::string section = str.substr(1, str.size() - 2);
52 }
else if (*str.begin() ==
'-') {
53 error =
strprintf(
"parse error on line %i: %s, options in configuration file must be specified without leading -",
linenr, str);
55 }
else if ((pos = str.find(
'=')) != std::string::npos) {
56 std::string
name =
prefix + TrimString(std::string_view{str}.substr(0, pos),
pattern);
57 std::string_view value = TrimStringView(std::string_view{str}.substr(pos + 1),
pattern);
58 if (
used_hash &&
name.find(
"rpcpassword") != std::string::npos) {
59 error =
strprintf(
"parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided",
linenr);
62 options.emplace_back(
name, value);
63 if ((pos =
name.rfind(
'.')) != std::string::npos &&
prefix.length() <= pos) {
68 if (str.size() >= 2 && str.starts_with(
"no")) {
69 error +=
strprintf(
", if you intended to specify a negated option, use %s=1 instead", str);
80 if (key.
name ==
"conf") {
81 error =
"conf cannot be set in the configuration file; use includeconf= if you want to include additional config files";
84 if (key.
name ==
"reindex") {
87 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");
96 std::vector<std::pair<std::string, std::string>> options;
100 for (
const std::pair<std::string, std::string>&
option : options) {
212 tfm::format(std::cerr,
"warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n",
conf_file_name);
220 error =
strprintf(
"specified data directory \"%s\" does not exist.",
GetArg(
"-datadir",
""));
228 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
std::string GetChainTypeString() const
Returns the appropriate chain type string from the program arguments.
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
std::optional< unsigned int > GetArgFlags(const std::string &name) const
Return Flags for known arg.
void ClearPathCache()
Clear cached directory paths.
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
fs::path GetDataDirBase() const
Get data directory path.
fs::path GetConfigFilePath() const
Return config file path (read-only)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool ReadConfigStream(std::istream &stream, const std::string &filepath, std::string &error, bool ignore_invalid_keys=false)
bool ReadConfigFiles(std::string &error, bool ignore_invalid_keys=false)
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
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, 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.