mirror of
https://github.com/XRPLF/rippled.git
synced 2026-07-23 23:20:33 +00:00
refactor: Change config section and key string literals into constants (#7095)
Co-authored-by: Bart <11445373+bthomee@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
#include <test/jtx/amount.h>
|
||||
|
||||
#include <xrpld/core/Config.h>
|
||||
#include <xrpld/core/ConfigSections.h>
|
||||
|
||||
#include <xrpl/config/Constants.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
@@ -27,33 +28,33 @@ setupConfigForUnitTests(Config& cfg)
|
||||
// The Beta API (currently v2) is always available to tests
|
||||
cfg.betaRpcApi = true;
|
||||
|
||||
cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
|
||||
cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
|
||||
cfg.deprecatedClearSection(ConfigSection::importNodeDatabase());
|
||||
cfg.legacy("database_path", "");
|
||||
cfg.overwrite(Sections::kNodeDatabase, Keys::kType, "memory");
|
||||
cfg.overwrite(Sections::kNodeDatabase, Keys::kPath, "main");
|
||||
cfg.deprecatedClearSection(Sections::kImportNodeDatabase);
|
||||
cfg.legacy(Sections::kDatabasePath, "");
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append(PORT_PEER);
|
||||
cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
|
||||
cfg[Sections::kServer].append(Sections::kPortPeer);
|
||||
cfg[Sections::kPortPeer].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
|
||||
// Using port 0 asks the operating system to allocate an unused port, which
|
||||
// can be obtained after a "bind" call.
|
||||
// Works for all system (Linux, Windows, Unix, Mac).
|
||||
// Check https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
// "ip_local_port_range" section for more info
|
||||
cfg[PORT_PEER].set("port", "0");
|
||||
cfg[PORT_PEER].set("protocol", "peer");
|
||||
cfg[Sections::kPortPeer].set(Keys::kPort, "0");
|
||||
cfg[Sections::kPortPeer].set(Keys::kProtocol, "peer");
|
||||
|
||||
cfg["server"].append(PORT_RPC);
|
||||
cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("port", "0");
|
||||
cfg[PORT_RPC].set("protocol", "http,ws2");
|
||||
cfg[Sections::kServer].append(Sections::kPortRpc);
|
||||
cfg[Sections::kPortRpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
cfg[Sections::kPortRpc].set(Keys::kAdmin, getEnvLocalhostAddr());
|
||||
cfg[Sections::kPortRpc].set(Keys::kPort, "0");
|
||||
cfg[Sections::kPortRpc].set(Keys::kProtocol, "http,ws2");
|
||||
|
||||
cfg["server"].append(PORT_WS);
|
||||
cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("port", "0");
|
||||
cfg[PORT_WS].set("protocol", "ws");
|
||||
cfg[Sections::kServer].append(Sections::kPortWs);
|
||||
cfg[Sections::kPortWs].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
cfg[Sections::kPortWs].set(Keys::kAdmin, getEnvLocalhostAddr());
|
||||
cfg[Sections::kPortWs].set(Keys::kPort, "0");
|
||||
cfg[Sections::kPortWs].set(Keys::kProtocol, "ws");
|
||||
cfg.sslVerify = false;
|
||||
}
|
||||
|
||||
@@ -62,35 +63,35 @@ namespace jtx {
|
||||
std::unique_ptr<Config>
|
||||
noAdmin(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
|
||||
(*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
secureGateway(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
|
||||
(*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kSecureGateway, getEnvLocalhostAddr());
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
adminLocalnet(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
|
||||
(*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "127.0.0.0/8");
|
||||
(*cfg)[Sections::kPortWs].set(Keys::kAdmin, "127.0.0.0/8");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
secureGatewayLocalnet(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
|
||||
(*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kAdmin, "");
|
||||
(*cfg)[Sections::kPortWs].set(Keys::kAdmin, "");
|
||||
(*cfg)[Sections::kPortRpc].set(Keys::kSecureGateway, "127.0.0.0/8");
|
||||
(*cfg)[Sections::kPortWs].set(Keys::kSecureGateway, "127.0.0.0/8");
|
||||
return cfg;
|
||||
}
|
||||
std::unique_ptr<Config>
|
||||
@@ -106,7 +107,7 @@ std::unique_ptr<Config>
|
||||
validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
{
|
||||
// If the config has valid validation keys then we run as a validator.
|
||||
cfg->section(SECTION_VALIDATION_SEED)
|
||||
cfg->section(Sections::kValidationSeed)
|
||||
.append(std::vector<std::string>{seed.empty() ? kDefaultSeed : seed});
|
||||
return cfg;
|
||||
}
|
||||
@@ -114,20 +115,20 @@ validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfig(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
addGrpcConfigWithSecureGateway(std::unique_ptr<Config> cfg, std::string const& secureGateway)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
|
||||
// Check https://man7.org/linux/man-pages/man7/ip.7.html
|
||||
// "ip_local_port_range" section for using 0 ports
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSecureGateway, secureGateway);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -137,10 +138,10 @@ addGrpcConfigWithTLS(
|
||||
std::string const& certPath,
|
||||
std::string const& keyPath)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", certPath);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", keyPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -151,11 +152,11 @@ addGrpcConfigWithTLSAndClientCA(
|
||||
std::string const& keyPath,
|
||||
std::string const& clientCAPath)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", certPath);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", keyPath);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_client_ca", clientCAPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslClientCa, clientCAPath);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -166,11 +167,11 @@ addGrpcConfigWithTLSAndCertChain(
|
||||
std::string const& keyPath,
|
||||
std::string const& certChainPath)
|
||||
{
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", "0");
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert", certPath);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_key", keyPath);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ssl_cert_chain", certChainPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kIp, getEnvLocalhostAddr());
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kPort, "0");
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCert, certPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslKey, keyPath);
|
||||
(*cfg)[Sections::kPortGrpc].set(Keys::kSslCertChain, certChainPath);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -180,13 +181,13 @@ makeConfig(
|
||||
std::map<std::string, std::string> extraVoting)
|
||||
{
|
||||
auto p = test::jtx::envconfig();
|
||||
auto& section = p->section("transaction_queue");
|
||||
section.set("ledgers_in_queue", "2");
|
||||
section.set("minimum_queue_size", "2");
|
||||
section.set("min_ledgers_to_compute_size_limit", "3");
|
||||
section.set("max_ledger_counts_to_store", "100");
|
||||
section.set("retry_sequence_percent", "25");
|
||||
section.set("normal_consensus_increase_percent", "0");
|
||||
auto& section = p->section(Sections::kTransactionQueue);
|
||||
section.set(Keys::kLedgersInQueue, "2");
|
||||
section.set(Keys::kMinimumQueueSize, "2");
|
||||
section.set(Keys::kMinLedgersToComputeSizeLimit, "3");
|
||||
section.set(Keys::kMaxLedgerCountsToStore, "100");
|
||||
section.set(Keys::kRetrySequencePercent, "25");
|
||||
section.set(Keys::kNormalConsensusIncreasePercent, "0");
|
||||
|
||||
for (auto const& [k, v] : extraTxQ)
|
||||
section.set(k, v);
|
||||
@@ -195,14 +196,14 @@ makeConfig(
|
||||
// a FeeVote
|
||||
if (!extraVoting.empty())
|
||||
{
|
||||
auto& votingSection = p->section("voting");
|
||||
auto& votingSection = p->section(Sections::kVoting);
|
||||
for (auto const& [k, v] : extraVoting)
|
||||
{
|
||||
votingSection.set(k, v);
|
||||
}
|
||||
|
||||
// In order for the vote to occur, we must run as a validator
|
||||
p->section("validation_seed").legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
|
||||
p->section(Sections::kValidationSeed).legacy("shUwVw52ofnCUX5m7kPTKzJdr4HEH");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user