20#include <xrpld/core/Config.h>
21#include <xrpld/core/ConfigSections.h>
22#include <xrpld/net/HTTPClient.h>
23#include <xrpl/basics/FileUtilities.h>
24#include <xrpl/basics/Log.h>
25#include <xrpl/basics/StringUtilities.h>
26#include <xrpl/basics/contract.h>
27#include <xrpl/beast/core/LexicalCast.h>
28#include <xrpl/json/json_reader.h>
29#include <xrpl/protocol/Feature.h>
30#include <xrpl/protocol/SystemParameters.h>
31#include <boost/algorithm/string.hpp>
32#include <boost/format.hpp>
33#include <boost/predef.h>
34#include <boost/regex.hpp>
35#include <boost/system/error_code.hpp>
44#include <sysinfoapi.h>
52 if (MEMORYSTATUSEX msx{
sizeof(MEMORYSTATUSEX)}; GlobalMemoryStatusEx(&msx))
63#include <sys/sysinfo.h>
71 if (
struct sysinfo si; sysinfo(&si) == 0)
83#include <sys/sysctl.h>
92 int mib[] = {CTL_HW, HW_MEMSIZE};
94 size_t size =
sizeof(ram);
96 if (sysctl(mib, 2, &ram, &size, NULL, 0) == 0)
136 []() constexpr->bool {
149 "Mismatch between sized item enum & array indices");
156#define SECTION_DEFAULT_NAME ""
166 boost::algorithm::replace_all(strData,
"\r\n",
"\n");
169 boost::algorithm::replace_all(strData,
"\r",
"\n");
171 boost::algorithm::split(vLines, strData, boost::algorithm::is_any_of(
"\n"));
177 secResult[strSection] = IniFileSections::mapped_type();
180 for (
auto& strValue : vLines)
183 boost::algorithm::trim(strValue);
185 if (strValue.empty() || strValue[0] ==
'#')
189 else if (strValue[0] ==
'[' && strValue[strValue.length() - 1] ==
']')
192 strSection = strValue.
substr(1, strValue.length() - 2);
193 secResult.
emplace(strSection, IniFileSections::mapped_type{});
198 if (!strValue.empty())
199 secResult[strSection].push_back(strValue);
206IniFileSections::mapped_type*
209 if (
auto it = secSource.
find(strSection); it != secSource.
end())
210 return &(it->second);
224 if (pmtEntries && pmtEntries->size() == 1)
226 strValue = (*pmtEntries)[0];
232 JLOG(j.
warn()) <<
"Section '" << strSection <<
"': requires 1 line not "
233 << pmtEntries->
size() <<
" lines.";
245char const*
const Config::configFileName =
"rippled.cfg";
246char const*
const Config::databaseDirName =
"db";
247char const*
const Config::validatorsFileName =
"validators.txt";
254 if (
auto const v =
std::getenv(name); v !=
nullptr)
261 : j_(
beast::Journal::getNullSink())
262 , ramSize_(detail::getMemorySize() / (1024 * 1024 * 1024))
270 NODE_SIZE == 0,
"ripple::Config::setupControl : node size not set");
272 QUIET = bQuiet || bSilent;
281 auto const& threshold =
285 threshold.second.begin(),
286 threshold.second.end(),
288 return (limit == 0) || (ramSize_ < limit);
292 ns != threshold.second.end(),
293 "ripple::Config::setupControl : valid node size");
295 if (ns != threshold.second.end())
305 NODE_SIZE <= 4,
"ripple::Config::setupControl : node size is set");
315 boost::filesystem::path dataDir;
328 if (!strConf.
empty())
329 strConfFile = strConf;
333 if (!strConf.
empty())
343 CONFIG_DIR = boost::filesystem::current_path();
350 auto strXdgConfigHome =
getEnvVar(
"XDG_CONFIG_HOME");
351 auto strXdgDataHome =
getEnvVar(
"XDG_DATA_HOME");
355 || (strHome.empty() &&
356 (strXdgConfigHome.empty() || strXdgDataHome.empty())))
362 if (strXdgConfigHome.empty())
365 strXdgConfigHome = strHome +
"/.config";
368 if (strXdgDataHome.empty())
371 strXdgDataHome = strHome +
"/.local/share";
376 dataDir = strXdgDataHome +
"/" +
systemName();
393 dataDir = boost::filesystem::path(dbPath);
398 if (!dataDir.empty())
400 boost::system::error_code ec;
401 boost::filesystem::create_directories(dataDir, ec);
404 Throw<std::runtime_error>(
405 boost::str(boost::format(
"Can not create %s") % dataDir));
407 legacy(
"database_path", boost::filesystem::absolute(dataDir).
string());
432 boost::system::error_code ec;
462 for (
auto& line : strVec)
465 if (
std::count(line.begin(), line.end(),
':') != 1)
471 if (result.
size() == line.size())
484 boost::filesystem::path p(dbPath);
485 legacy(
"database_path", boost::filesystem::absolute(p).
string());
493 if (strTemp ==
"main")
495 else if (strTemp ==
"testnet")
497 else if (strTemp ==
"devnet")
500 NETWORK_ID = beast::lexicalCastThrow<uint32_t>(strTemp);
508 PEERS_MAX = beast::lexicalCastThrow<std::size_t>(strTemp);
515 peers_in_max = beast::lexicalCastThrow<std::size_t>(strTemp);
516 if (*peers_in_max > 1000)
517 Throw<std::runtime_error>(
518 "Invalid value specified in [" SECTION_PEERS_IN_MAX
519 "] section; the value must be less or equal than 1000");
525 peers_out_max = beast::lexicalCastThrow<std::size_t>(strTemp);
526 if (*peers_out_max < 10 || *peers_out_max > 1000)
527 Throw<std::runtime_error>(
528 "Invalid value specified in [" SECTION_PEERS_OUT_MAX
529 "] section; the value must be in range 10-1000");
533 if ((peers_in_max && !peers_out_max) ||
534 (peers_out_max && !peers_in_max))
535 Throw<std::runtime_error>(
"Both sections [" SECTION_PEERS_IN_MAX
537 "and [" SECTION_PEERS_OUT_MAX
538 "] must be configured");
540 if (peers_in_max && peers_out_max)
549 if (boost::iequals(strTemp,
"tiny"))
551 else if (boost::iequals(strTemp,
"small"))
553 else if (boost::iequals(strTemp,
"medium"))
555 else if (boost::iequals(strTemp,
"large"))
557 else if (boost::iequals(strTemp,
"huge"))
561 4, beast::lexicalCastThrow<std::size_t>(strTemp));
568 ELB_SUPPORT = beast::lexicalCastThrow<bool>(strTemp);
574 SSL_VERIFY = beast::lexicalCastThrow<bool>(strTemp);
578 if (boost::iequals(strTemp,
"all"))
580 else if (boost::iequals(strTemp,
"trusted"))
582 else if (boost::iequals(strTemp,
"drop_untrusted"))
585 Throw<std::runtime_error>(
586 "Invalid value specified in [" SECTION_RELAY_VALIDATIONS
592 if (boost::iequals(strTemp,
"all"))
594 else if (boost::iequals(strTemp,
"trusted"))
596 else if (boost::iequals(strTemp,
"drop_untrusted"))
599 Throw<std::runtime_error>(
600 "Invalid value specified in [" SECTION_RELAY_PROPOSALS
604 if (
exists(SECTION_VALIDATION_SEED) &&
exists(SECTION_VALIDATOR_TOKEN))
605 Throw<std::runtime_error>(
"Cannot have both [" SECTION_VALIDATION_SEED
606 "] and [" SECTION_VALIDATOR_TOKEN
607 "] config sections");
621 if (boost::iequals(strTemp,
"full"))
624 else if (boost::iequals(strTemp,
"none"))
632 if (boost::iequals(strTemp,
"none"))
634 else if (boost::iequals(strTemp,
"full"))
637 FETCH_DEPTH = beast::lexicalCastThrow<std::uint32_t>(strTemp);
645 if (
exists(SECTION_VALIDATION_SEED) ||
exists(SECTION_VALIDATOR_TOKEN))
651 PATH_SEARCH = beast::lexicalCastThrow<int>(strTemp);
664 if (SWEEP_INTERVAL < 10 || SWEEP_INTERVAL > 600)
665 Throw<std::runtime_error>(
"Invalid " SECTION_SWEEP_INTERVAL
666 ": must be between 10 and 600 inclusive");
671 WORKERS = beast::lexicalCastThrow<int>(strTemp);
673 if (WORKERS < 1 || WORKERS > 1024)
674 Throw<std::runtime_error>(
675 "Invalid " SECTION_WORKERS
676 ": must be between 1 and 1024 inclusive.");
681 IO_WORKERS = beast::lexicalCastThrow<int>(strTemp);
683 if (IO_WORKERS < 1 || IO_WORKERS > 1024)
684 Throw<std::runtime_error>(
685 "Invalid " SECTION_IO_WORKERS
686 ": must be between 1 and 1024 inclusive.");
693 if (PREFETCH_WORKERS < 1 || PREFETCH_WORKERS > 1024)
694 Throw<std::runtime_error>(
695 "Invalid " SECTION_PREFETCH_WORKERS
696 ": must be between 1 and 1024 inclusive.");
700 COMPRESSION = beast::lexicalCastThrow<bool>(strTemp);
705 if (
exists(SECTION_REDUCE_RELAY))
707 auto sec =
section(SECTION_REDUCE_RELAY);
714 if (TX_RELAY_PERCENTAGE < 10 || TX_RELAY_PERCENTAGE > 100 ||
716 Throw<std::runtime_error>(
717 "Invalid " SECTION_REDUCE_RELAY
718 ", tx_min_peers must be greater or equal to 10"
719 ", tx_relay_percentage must be greater or equal to 10 "
720 "and less or equal to 100");
726 beast::lexicalCastThrow<int>(strTemp),
735 Throw<std::runtime_error>(
736 "Invalid " SECTION_SERVER_DOMAIN
737 ": the domain name does not appear to meet the requirements.");
743 if (
exists(SECTION_OVERLAY))
745 auto const sec =
section(SECTION_OVERLAY);
751 if (
auto val = sec.get(
"max_unknown_time"))
753 seconds{beast::lexicalCastThrow<std::uint32_t>(*val)};
757 Throw<std::runtime_error>(
758 "Invalid value 'max_unknown_time' in " SECTION_OVERLAY
759 ": must be of the form '<number>' representing seconds.");
763 Throw<std::runtime_error>(
764 "Invalid value 'max_unknown_time' in " SECTION_OVERLAY
765 ": the time must be between 300 and 1800 seconds, inclusive.");
769 if (
auto val = sec.get(
"max_diverged_time"))
771 seconds{beast::lexicalCastThrow<std::uint32_t>(*val)};
775 Throw<std::runtime_error>(
776 "Invalid value 'max_diverged_time' in " SECTION_OVERLAY
777 ": must be of the form '<number>' representing seconds.");
782 Throw<std::runtime_error>(
783 "Invalid value 'max_diverged_time' in " SECTION_OVERLAY
784 ": the time must be between 60 and 900 seconds, inclusive.");
789 secConfig, SECTION_AMENDMENT_MAJORITY_TIME, strTemp,
j_))
792 boost::regex
const re(
793 "^\\s*(\\d+)\\s*(minutes|hours|days|weeks)\\s*(\\s+.*)?$");
795 if (!boost::regex_match(strTemp,
match, re))
796 Throw<std::runtime_error>(
797 "Invalid " SECTION_AMENDMENT_MAJORITY_TIME
798 ", must be: [0-9]+ [minutes|hours|days|weeks]");
801 beast::lexicalCastThrow<std::uint32_t>(
match[1].str());
803 if (boost::iequals(
match[2],
"minutes"))
805 else if (boost::iequals(
match[2],
"hours"))
807 else if (boost::iequals(
match[2],
"days"))
809 else if (boost::iequals(
match[2],
"weeks"))
813 Throw<std::runtime_error>(
814 "Invalid " SECTION_AMENDMENT_MAJORITY_TIME
815 ", the minimum amount of time an amendment must hold a "
816 "majority is 15 minutes");
833 boost::filesystem::path validatorsFile;
837 validatorsFile = strTemp;
839 if (validatorsFile.empty())
840 Throw<std::runtime_error>(
841 "Invalid path specified in [" SECTION_VALIDATORS_FILE
"]");
843 if (!validatorsFile.is_absolute() && !
CONFIG_DIR.empty())
846 if (!boost::filesystem::exists(validatorsFile))
847 Throw<std::runtime_error>(
848 "The file specified in [" SECTION_VALIDATORS_FILE
851 validatorsFile.string());
854 !boost::filesystem::is_regular_file(validatorsFile) &&
855 !boost::filesystem::is_symlink(validatorsFile))
856 Throw<std::runtime_error>(
857 "Invalid file specified in [" SECTION_VALIDATORS_FILE
859 validatorsFile.string());
865 if (!validatorsFile.empty())
867 if (!boost::filesystem::exists(validatorsFile))
868 validatorsFile.clear();
870 !boost::filesystem::is_regular_file(validatorsFile) &&
871 !boost::filesystem::is_symlink(validatorsFile))
872 validatorsFile.clear();
876 if (!validatorsFile.empty() &&
877 boost::filesystem::exists(validatorsFile) &&
878 (boost::filesystem::is_regular_file(validatorsFile) ||
879 boost::filesystem::is_symlink(validatorsFile)))
881 boost::system::error_code ec;
885 Throw<std::runtime_error>(
886 "Failed to read '" + validatorsFile.string() +
"'." +
903 auto valSiteEntries =
907 section(SECTION_VALIDATOR_LIST_SITES).
append(*valSiteEntries);
915 auto valListThreshold =
918 if (valListThreshold)
919 section(SECTION_VALIDATOR_LIST_THRESHOLD)
920 .
append(*valListThreshold);
922 if (!entries && !valKeyEntries && !valListKeys)
923 Throw<std::runtime_error>(
924 "The file specified in [" SECTION_VALIDATORS_FILE
926 "does not contain a [" SECTION_VALIDATORS
928 "[" SECTION_VALIDATOR_KEYS
930 "[" SECTION_VALIDATOR_LIST_KEYS
933 validatorsFile.string());
937 auto const& listThreshold =
938 section(SECTION_VALIDATOR_LIST_THRESHOLD);
939 if (listThreshold.lines().empty())
941 else if (listThreshold.values().size() == 1)
943 auto strTemp = listThreshold.values()[0];
944 auto const listThreshold =
945 beast::lexicalCastThrow<std::size_t>(strTemp);
946 if (listThreshold == 0)
950 section(SECTION_VALIDATOR_LIST_KEYS).values().size())
952 Throw<std::runtime_error>(
953 "Value in config section "
954 "[" SECTION_VALIDATOR_LIST_THRESHOLD
955 "] exceeds the number of configured list keys");
957 return listThreshold;
961 Throw<std::runtime_error>(
963 "[" SECTION_VALIDATOR_LIST_THRESHOLD
964 "] should contain single value only");
972 if (!
section(SECTION_VALIDATOR_LIST_SITES).lines().empty() &&
973 section(SECTION_VALIDATOR_LIST_KEYS).lines().empty())
975 Throw<std::runtime_error>(
977 "] config section is missing");
982 auto const part =
section(
"features");
983 for (
auto const& s : part.values())
988 Throw<std::runtime_error>(
989 "Unknown feature: " + s +
" in config file.");
1005 Throw<std::runtime_error>(
1006 "The minimum number of required peers (network_quorum) exceeds "
1007 "the maximum number of allowed peers (peers_max)");
1012boost::filesystem::path
1017 if (!log_file.empty() && !log_file.is_absolute())
1021 log_file = boost::filesystem::absolute(log_file,
CONFIG_DIR);
1024 if (!log_file.empty())
1026 auto log_dir = log_file.parent_path();
1028 if (!boost::filesystem::is_directory(log_dir))
1030 boost::system::error_code ec;
1031 boost::filesystem::create_directories(log_dir, ec);
1037 std::cerr <<
"Unable to create log file path " << log_dir
1038 <<
": " << ec.message() <<
'\n';
1052 "ripple::Config::getValueFor : valid index input");
1054 !node || *node <= 4,
1055 "ripple::Config::getValueFor : unset or valid node");
1065 if (
set(temp,
"reference_fee", section) &&
1071 if (
set(temp,
"account_reserve", section))
1073 if (
set(temp,
"owner_reserve", section))
A generic endpoint for log messages.
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
Section & section(std::string const &name)
Returns the section with the given name.
void build(IniFileSections const &ifs)
void legacy(std::string const §ion, std::string value)
Set a value that is not a key/value pair.
static char const *const databaseDirName
std::optional< int > SWEEP_INTERVAL
std::uint32_t LEDGER_HISTORY
std::uint32_t FETCH_DEPTH
std::size_t NETWORK_QUORUM
std::vector< std::string > IPS_FIXED
boost::filesystem::path CONFIG_DIR
void setup(std::string const &strConf, bool bQuiet, bool bSilent, bool bStandalone)
static char const *const configFileName
std::vector< std::string > IPS
bool VP_REDUCE_RELAY_ENABLE
std::size_t TX_REDUCE_RELAY_MIN_PEERS
std::optional< std::size_t > VALIDATOR_LIST_THRESHOLD
int RELAY_UNTRUSTED_PROPOSALS
bool TX_REDUCE_RELAY_ENABLE
boost::filesystem::path getDebugLogFile() const
Returns the full path and filename of the debug log file.
bool TX_REDUCE_RELAY_METRICS
static constexpr int MIN_JOB_QUEUE_TX
bool RUN_STANDALONE
Operate in stand-alone mode.
std::size_t TX_RELAY_PERCENTAGE
std::string SERVER_DOMAIN
static constexpr int MAX_JOB_QUEUE_TX
std::chrono::seconds MAX_DIVERGED_TIME
boost::filesystem::path CONFIG_FILE
int getValueFor(SizedItem item, std::optional< std::size_t > node=std::nullopt) const
Retrieve the default value for the item at the specified node size.
bool signingEnabled_
Determines if the server will sign a tx, given an account's secret seed.
boost::filesystem::path DEBUG_LOGFILE
std::string SSL_VERIFY_FILE
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
std::unordered_set< uint256, beast::uhash<> > features
std::chrono::seconds AMENDMENT_MAJORITY_TIME
bool VP_REDUCE_RELAY_SQUELCH
static char const *const validatorsFileName
std::chrono::seconds MAX_UNKNOWN_TIME
std::size_t PEERS_OUT_MAX
int RELAY_UNTRUSTED_VALIDATIONS
std::string SSL_VERIFY_DIR
static void initializeSSLContext(Config const &config, beast::Journal j)
Holds a collection of configuration values.
void append(std::vector< std::string > const &lines)
Append a set of lines to this section.
T hardware_concurrency(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::map< std::string, std::vector< std::string > > IniFileSections
bool getSingleSection(IniFileSections &secSource, std::string const &strSection, std::string &strValue, beast::Journal j)
IniFileSections::mapped_type * getIniFileSection(IniFileSections &secSource, std::string const &strSection)
static std::string const & systemName()
std::chrono::duration< int, std::ratio_multiply< std::chrono::hours::period, std::ratio< 24 > > > days
bool get_if_exists(Section const §ion, std::string const &name, T &v)
std::chrono::duration< int, std::ratio_multiply< days::period, std::ratio< 7 > > > weeks
static std::string getEnvVar(char const *name)
std::optional< uint256 > getRegisteredFeature(std::string const &name)
std::string getFileContents(boost::system::error_code &ec, boost::filesystem::path const &sourcePath, std::optional< std::size_t > maxSize=std::nullopt)
IniFileSections parseIniFile(std::string const &strInput, const bool bTrim)
FeeSetup setup_FeeVote(Section const §ion)
bool isProperlyFormedTomlDomain(std::string_view domain)
Determines if the given string looks like a TOML-file hosting domain.
constexpr std::array< std::pair< SizedItem, std::array< int, 5 > >, 13 > sizedItems
T regex_replace(T... args)
static std::string nodeDatabase()
Fee schedule for startup / standalone, and to vote for.
XRPAmount reference_fee
The cost of a reference transaction in drops.
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
XRPAmount account_reserve
The account reserve requirement in drops.