20#include <xrpld/core/Config.h>
21#include <xrpld/core/ConfigSections.h>
22#include <xrpld/net/HTTPClient.h>
24#include <xrpl/basics/FileUtilities.h>
25#include <xrpl/basics/Log.h>
26#include <xrpl/basics/StringUtilities.h>
27#include <xrpl/basics/contract.h>
28#include <xrpl/beast/core/LexicalCast.h>
29#include <xrpl/json/json_reader.h>
30#include <xrpl/protocol/Feature.h>
31#include <xrpl/protocol/SystemParameters.h>
33#include <boost/algorithm/string.hpp>
34#include <boost/format.hpp>
35#include <boost/predef.h>
36#include <boost/regex.hpp>
46#include <sysinfoapi.h>
54 if (MEMORYSTATUSEX msx{
sizeof(MEMORYSTATUSEX)}; GlobalMemoryStatusEx(&msx))
65#include <sys/sysinfo.h>
73 if (
struct sysinfo si; sysinfo(&si) == 0)
85#include <sys/sysctl.h>
94 int mib[] = {CTL_HW, HW_MEMSIZE};
96 size_t size =
sizeof(ram);
98 if (sysctl(mib, 2, &ram, &size, NULL, 0) == 0)
138 []() constexpr->bool {
151 "Mismatch between sized item enum & array indices");
158#define SECTION_DEFAULT_NAME ""
168 boost::algorithm::replace_all(strData,
"\r\n",
"\n");
171 boost::algorithm::replace_all(strData,
"\r",
"\n");
173 boost::algorithm::split(vLines, strData, boost::algorithm::is_any_of(
"\n"));
179 secResult[strSection] = IniFileSections::mapped_type();
182 for (
auto& strValue : vLines)
185 boost::algorithm::trim(strValue);
187 if (strValue.empty() || strValue[0] ==
'#')
191 else if (strValue[0] ==
'[' && strValue[strValue.length() - 1] ==
']')
194 strSection = strValue.
substr(1, strValue.length() - 2);
195 secResult.
emplace(strSection, IniFileSections::mapped_type{});
200 if (!strValue.empty())
201 secResult[strSection].push_back(strValue);
208IniFileSections::mapped_type*
211 if (
auto it = secSource.
find(strSection); it != secSource.
end())
212 return &(it->second);
226 if (pmtEntries && pmtEntries->size() == 1)
228 strValue = (*pmtEntries)[0];
234 JLOG(j.
warn()) <<
"Section '" << strSection <<
"': requires 1 line not "
235 << pmtEntries->
size() <<
" lines.";
247char const*
const Config::configFileName =
"rippled.cfg";
248char const*
const Config::databaseDirName =
"db";
249char const*
const Config::validatorsFileName =
"validators.txt";
256 if (
auto const v =
std::getenv(name); v !=
nullptr)
263 : j_(
beast::Journal::getNullSink())
264 , ramSize_(detail::getMemorySize() / (1024 * 1024 * 1024))
272 NODE_SIZE == 0,
"ripple::Config::setupControl : node size not set");
274 QUIET = bQuiet || bSilent;
283 auto const& threshold =
287 threshold.second.begin(),
288 threshold.second.end(),
290 return (limit == 0) || (ramSize_ < limit);
294 ns != threshold.second.end(),
295 "ripple::Config::setupControl : valid node size");
297 if (ns != threshold.second.end())
307 NODE_SIZE <= 4,
"ripple::Config::setupControl : node size is set");
317 boost::filesystem::path dataDir;
330 if (!strConf.
empty())
331 strConfFile = strConf;
335 if (!strConf.
empty())
345 CONFIG_DIR = boost::filesystem::current_path();
352 auto strXdgConfigHome =
getEnvVar(
"XDG_CONFIG_HOME");
353 auto strXdgDataHome =
getEnvVar(
"XDG_DATA_HOME");
357 || (strHome.empty() &&
358 (strXdgConfigHome.empty() || strXdgDataHome.empty())))
364 if (strXdgConfigHome.empty())
367 strXdgConfigHome = strHome +
"/.config";
370 if (strXdgDataHome.empty())
373 strXdgDataHome = strHome +
"/.local/share";
378 dataDir = strXdgDataHome +
"/" +
systemName();
395 dataDir = boost::filesystem::path(dbPath);
400 if (!dataDir.empty())
402 boost::system::error_code ec;
403 boost::filesystem::create_directories(dataDir, ec);
406 Throw<std::runtime_error>(
407 boost::str(boost::format(
"Can not create %s") % dataDir));
409 legacy(
"database_path", boost::filesystem::absolute(dataDir).
string());
430 if (!config.
exists(
"server"))
438 auto const& section = config[name];
439 auto const optResult = section.get(
"port");
442 auto const port = beast::lexicalCast<std::uint16_t>(*optResult);
446 ss <<
"Invalid value '" << *optResult <<
"' for key 'port' in ["
448 Throw<std::runtime_error>(ss.
str());
463 boost::system::error_code ec;
494 for (
auto& line : strVec)
497 if (
std::count(line.begin(), line.end(),
':') != 1)
503 if (result.
size() == line.size())
516 boost::filesystem::path p(dbPath);
517 legacy(
"database_path", boost::filesystem::absolute(p).
string());
525 if (strTemp ==
"main")
527 else if (strTemp ==
"testnet")
529 else if (strTemp ==
"devnet")
532 NETWORK_ID = beast::lexicalCastThrow<uint32_t>(strTemp);
540 PEERS_MAX = beast::lexicalCastThrow<std::size_t>(strTemp);
547 peers_in_max = beast::lexicalCastThrow<std::size_t>(strTemp);
548 if (*peers_in_max > 1000)
549 Throw<std::runtime_error>(
550 "Invalid value specified in [" SECTION_PEERS_IN_MAX
551 "] section; the value must be less or equal than 1000");
557 peers_out_max = beast::lexicalCastThrow<std::size_t>(strTemp);
558 if (*peers_out_max < 10 || *peers_out_max > 1000)
559 Throw<std::runtime_error>(
560 "Invalid value specified in [" SECTION_PEERS_OUT_MAX
561 "] section; the value must be in range 10-1000");
565 if ((peers_in_max && !peers_out_max) ||
566 (peers_out_max && !peers_in_max))
567 Throw<std::runtime_error>(
"Both sections [" SECTION_PEERS_IN_MAX
569 "and [" SECTION_PEERS_OUT_MAX
570 "] must be configured");
572 if (peers_in_max && peers_out_max)
581 if (boost::iequals(strTemp,
"tiny"))
583 else if (boost::iequals(strTemp,
"small"))
585 else if (boost::iequals(strTemp,
"medium"))
587 else if (boost::iequals(strTemp,
"large"))
589 else if (boost::iequals(strTemp,
"huge"))
593 4, beast::lexicalCastThrow<std::size_t>(strTemp));
600 ELB_SUPPORT = beast::lexicalCastThrow<bool>(strTemp);
606 SSL_VERIFY = beast::lexicalCastThrow<bool>(strTemp);
610 if (boost::iequals(strTemp,
"all"))
612 else if (boost::iequals(strTemp,
"trusted"))
614 else if (boost::iequals(strTemp,
"drop_untrusted"))
617 Throw<std::runtime_error>(
618 "Invalid value specified in [" SECTION_RELAY_VALIDATIONS
624 if (boost::iequals(strTemp,
"all"))
626 else if (boost::iequals(strTemp,
"trusted"))
628 else if (boost::iequals(strTemp,
"drop_untrusted"))
631 Throw<std::runtime_error>(
632 "Invalid value specified in [" SECTION_RELAY_PROPOSALS
636 if (
exists(SECTION_VALIDATION_SEED) &&
exists(SECTION_VALIDATOR_TOKEN))
637 Throw<std::runtime_error>(
"Cannot have both [" SECTION_VALIDATION_SEED
638 "] and [" SECTION_VALIDATOR_TOKEN
639 "] config sections");
653 if (boost::iequals(strTemp,
"full"))
656 else if (boost::iequals(strTemp,
"none"))
664 if (boost::iequals(strTemp,
"none"))
666 else if (boost::iequals(strTemp,
"full"))
669 FETCH_DEPTH = beast::lexicalCastThrow<std::uint32_t>(strTemp);
677 if (
exists(SECTION_VALIDATION_SEED) ||
exists(SECTION_VALIDATOR_TOKEN))
683 PATH_SEARCH = beast::lexicalCastThrow<int>(strTemp);
696 if (SWEEP_INTERVAL < 10 || SWEEP_INTERVAL > 600)
697 Throw<std::runtime_error>(
"Invalid " SECTION_SWEEP_INTERVAL
698 ": must be between 10 and 600 inclusive");
703 WORKERS = beast::lexicalCastThrow<int>(strTemp);
705 if (WORKERS < 1 || WORKERS > 1024)
706 Throw<std::runtime_error>(
707 "Invalid " SECTION_WORKERS
708 ": must be between 1 and 1024 inclusive.");
713 IO_WORKERS = beast::lexicalCastThrow<int>(strTemp);
715 if (IO_WORKERS < 1 || IO_WORKERS > 1024)
716 Throw<std::runtime_error>(
717 "Invalid " SECTION_IO_WORKERS
718 ": must be between 1 and 1024 inclusive.");
725 if (PREFETCH_WORKERS < 1 || PREFETCH_WORKERS > 1024)
726 Throw<std::runtime_error>(
727 "Invalid " SECTION_PREFETCH_WORKERS
728 ": must be between 1 and 1024 inclusive.");
732 COMPRESSION = beast::lexicalCastThrow<bool>(strTemp);
737 if (
exists(SECTION_REDUCE_RELAY))
739 auto sec =
section(SECTION_REDUCE_RELAY);
746 if (TX_RELAY_PERCENTAGE < 10 || TX_RELAY_PERCENTAGE > 100 ||
748 Throw<std::runtime_error>(
749 "Invalid " SECTION_REDUCE_RELAY
750 ", tx_min_peers must be greater or equal to 10"
751 ", tx_relay_percentage must be greater or equal to 10 "
752 "and less or equal to 100");
758 beast::lexicalCastThrow<int>(strTemp),
767 Throw<std::runtime_error>(
768 "Invalid " SECTION_SERVER_DOMAIN
769 ": the domain name does not appear to meet the requirements.");
775 if (
exists(SECTION_OVERLAY))
777 auto const sec =
section(SECTION_OVERLAY);
783 if (
auto val = sec.get(
"max_unknown_time"))
785 seconds{beast::lexicalCastThrow<std::uint32_t>(*val)};
789 Throw<std::runtime_error>(
790 "Invalid value 'max_unknown_time' in " SECTION_OVERLAY
791 ": must be of the form '<number>' representing seconds.");
795 Throw<std::runtime_error>(
796 "Invalid value 'max_unknown_time' in " SECTION_OVERLAY
797 ": the time must be between 300 and 1800 seconds, inclusive.");
801 if (
auto val = sec.get(
"max_diverged_time"))
803 seconds{beast::lexicalCastThrow<std::uint32_t>(*val)};
807 Throw<std::runtime_error>(
808 "Invalid value 'max_diverged_time' in " SECTION_OVERLAY
809 ": must be of the form '<number>' representing seconds.");
814 Throw<std::runtime_error>(
815 "Invalid value 'max_diverged_time' in " SECTION_OVERLAY
816 ": the time must be between 60 and 900 seconds, inclusive.");
821 secConfig, SECTION_AMENDMENT_MAJORITY_TIME, strTemp,
j_))
824 boost::regex
const re(
825 "^\\s*(\\d+)\\s*(minutes|hours|days|weeks)\\s*(\\s+.*)?$");
827 if (!boost::regex_match(strTemp,
match, re))
828 Throw<std::runtime_error>(
829 "Invalid " SECTION_AMENDMENT_MAJORITY_TIME
830 ", must be: [0-9]+ [minutes|hours|days|weeks]");
833 beast::lexicalCastThrow<std::uint32_t>(
match[1].str());
835 if (boost::iequals(
match[2],
"minutes"))
837 else if (boost::iequals(
match[2],
"hours"))
839 else if (boost::iequals(
match[2],
"days"))
841 else if (boost::iequals(
match[2],
"weeks"))
845 Throw<std::runtime_error>(
846 "Invalid " SECTION_AMENDMENT_MAJORITY_TIME
847 ", the minimum amount of time an amendment must hold a "
848 "majority is 15 minutes");
865 boost::filesystem::path validatorsFile;
869 validatorsFile = strTemp;
871 if (validatorsFile.empty())
872 Throw<std::runtime_error>(
873 "Invalid path specified in [" SECTION_VALIDATORS_FILE
"]");
875 if (!validatorsFile.is_absolute() && !
CONFIG_DIR.empty())
878 if (!boost::filesystem::exists(validatorsFile))
879 Throw<std::runtime_error>(
880 "The file specified in [" SECTION_VALIDATORS_FILE
883 validatorsFile.string());
886 !boost::filesystem::is_regular_file(validatorsFile) &&
887 !boost::filesystem::is_symlink(validatorsFile))
888 Throw<std::runtime_error>(
889 "Invalid file specified in [" SECTION_VALIDATORS_FILE
891 validatorsFile.string());
897 if (!validatorsFile.empty())
899 if (!boost::filesystem::exists(validatorsFile))
900 validatorsFile.clear();
902 !boost::filesystem::is_regular_file(validatorsFile) &&
903 !boost::filesystem::is_symlink(validatorsFile))
904 validatorsFile.clear();
908 if (!validatorsFile.empty() &&
909 boost::filesystem::exists(validatorsFile) &&
910 (boost::filesystem::is_regular_file(validatorsFile) ||
911 boost::filesystem::is_symlink(validatorsFile)))
913 boost::system::error_code ec;
917 Throw<std::runtime_error>(
918 "Failed to read '" + validatorsFile.string() +
"'." +
935 auto valSiteEntries =
939 section(SECTION_VALIDATOR_LIST_SITES).
append(*valSiteEntries);
947 auto valListThreshold =
950 if (valListThreshold)
951 section(SECTION_VALIDATOR_LIST_THRESHOLD)
952 .
append(*valListThreshold);
954 if (!entries && !valKeyEntries && !valListKeys)
955 Throw<std::runtime_error>(
956 "The file specified in [" SECTION_VALIDATORS_FILE
958 "does not contain a [" SECTION_VALIDATORS
960 "[" SECTION_VALIDATOR_KEYS
962 "[" SECTION_VALIDATOR_LIST_KEYS
965 validatorsFile.string());
969 auto const& listThreshold =
970 section(SECTION_VALIDATOR_LIST_THRESHOLD);
971 if (listThreshold.lines().empty())
973 else if (listThreshold.values().size() == 1)
975 auto strTemp = listThreshold.values()[0];
976 auto const listThreshold =
977 beast::lexicalCastThrow<std::size_t>(strTemp);
978 if (listThreshold == 0)
982 section(SECTION_VALIDATOR_LIST_KEYS).values().size())
984 Throw<std::runtime_error>(
985 "Value in config section "
986 "[" SECTION_VALIDATOR_LIST_THRESHOLD
987 "] exceeds the number of configured list keys");
989 return listThreshold;
993 Throw<std::runtime_error>(
995 "[" SECTION_VALIDATOR_LIST_THRESHOLD
996 "] should contain single value only");
1004 if (!
section(SECTION_VALIDATOR_LIST_SITES).
lines().empty() &&
1007 Throw<std::runtime_error>(
1009 "] config section is missing");
1014 auto const part =
section(
"features");
1015 for (
auto const& s : part.values())
1020 Throw<std::runtime_error>(
1021 "Unknown feature: " + s +
" in config file.");
1037 Throw<std::runtime_error>(
1038 "The minimum number of required peers (network_quorum) exceeds "
1039 "the maximum number of allowed peers (peers_max)");
1044boost::filesystem::path
1049 if (!log_file.empty() && !log_file.is_absolute())
1053 log_file = boost::filesystem::absolute(log_file,
CONFIG_DIR);
1056 if (!log_file.empty())
1058 auto log_dir = log_file.parent_path();
1060 if (!boost::filesystem::is_directory(log_dir))
1062 boost::system::error_code ec;
1063 boost::filesystem::create_directories(log_dir, ec);
1069 std::cerr <<
"Unable to create log file path " << log_dir
1070 <<
": " << ec.message() <<
'\n';
1084 "ripple::Config::getValueFor : valid index input");
1086 !node || *node <= 4,
1087 "ripple::Config::getValueFor : unset or valid node");
1097 if (
set(temp,
"reference_fee", section) &&
1103 if (
set(temp,
"account_reserve", section))
1105 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.
std::vector< std::string > const & values() const
Returns all the values in the section.
T hardware_concurrency(T... args)
owner_count< ltRIPPLE_STATE > lines
Match the number of trust lines in the account's owner directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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()
static void checkZeroPorts(Config const &config)
IniFileSections parseIniFile(std::string const &strInput, bool const bTrim)
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)
FeeSetup setup_FeeVote(Section const §ion)
bool isProperlyFormedTomlDomain(std::string_view domain)
Determines if the given string looks like a TOML-file hosting domain.
std::unordered_map< std::string, std::vector< std::string > > IniFileSections
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.