rippled
Loading...
Searching...
No Matches
envconfig.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <test/jtx/amount.h>
21#include <test/jtx/envconfig.h>
22
23#include <xrpld/core/ConfigSections.h>
24
25namespace ripple {
26namespace test {
27
29
30void
32{
33 using namespace jtx;
34 // Default fees to old values, so tests don't have to worry about changes in
35 // Config.h
36 cfg.FEES.reference_fee = UNIT_TEST_REFERENCE_FEE;
37 cfg.FEES.account_reserve = XRP(200).value().xrp().drops();
38 cfg.FEES.owner_reserve = XRP(50).value().xrp().drops();
39
40 // The Beta API (currently v2) is always available to tests
41 cfg.BETA_RPC_API = true;
42
43 cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
44 cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
46 cfg.legacy("database_path", "");
47 cfg.setupControl(true, true, true);
48 cfg["server"].append(PORT_PEER);
49 cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
50
51 // Using port 0 asks the operating system to allocate an unused port, which
52 // can be obtained after a "bind" call.
53 // Works for all system (Linux, Windows, Unix, Mac).
54 // Check https://man7.org/linux/man-pages/man7/ip.7.html
55 // "ip_local_port_range" section for more info
56 cfg[PORT_PEER].set("port", "0");
57 cfg[PORT_PEER].set("protocol", "peer");
58
59 cfg["server"].append(PORT_RPC);
60 cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
61 cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
62 cfg[PORT_RPC].set("port", "0");
63 cfg[PORT_RPC].set("protocol", "http,ws2");
64
65 cfg["server"].append(PORT_WS);
66 cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
67 cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
68 cfg[PORT_WS].set("port", "0");
69 cfg[PORT_WS].set("protocol", "ws");
70 cfg.SSL_VERIFY = false;
71}
72
73namespace jtx {
74
77{
78 (*cfg)[PORT_RPC].set("admin", "");
79 (*cfg)[PORT_WS].set("admin", "");
80 return cfg;
81}
82
85{
86 (*cfg)[PORT_RPC].set("admin", "");
87 (*cfg)[PORT_WS].set("admin", "");
88 (*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
89 return cfg;
90}
91
94{
95 (*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
96 (*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
97 return cfg;
98}
99
102{
103 (*cfg)[PORT_RPC].set("admin", "");
104 (*cfg)[PORT_WS].set("admin", "");
105 (*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
106 (*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
107 return cfg;
108}
109
110auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
111
114{
115 // If the config has valid validation keys then we run as a validator.
116 cfg->section(SECTION_VALIDATION_SEED)
117 .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
118 return cfg;
119}
120
123{
124 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
125 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
126 return cfg;
127}
128
132 std::string const& secureGateway)
133{
134 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
135
136 // Check https://man7.org/linux/man-pages/man7/ip.7.html
137 // "ip_local_port_range" section for using 0 ports
138 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
139 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
140 return cfg;
141}
142
143} // namespace jtx
144} // namespace test
145} // namespace ripple
void deprecatedClearSection(std::string const &section)
Remove all the key/value pairs from the section.
void overwrite(std::string const &section, std::string const &key, std::string const &value)
Overwrite a key/value pair with a command line argument If the section does not exist it is created.
void legacy(std::string const &section, std::string value)
Set a value that is not a key/value pair.
bool BETA_RPC_API
Definition: Config.h:288
bool SSL_VERIFY
Definition: Config.h:215
FeeSetup FEES
Definition: Config.h:204
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition: Config.cpp:269
T empty(T... args)
std::unique_ptr< Config > validator(std::unique_ptr< Config >, std::string const &)
adjust configuration with params needed to be a validator
Definition: envconfig.cpp:113
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:93
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition: envconfig.cpp:84
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition: envconfig.cpp:76
std::unique_ptr< Config > addGrpcConfig(std::unique_ptr< Config >)
add a grpc address and port to config
Definition: envconfig.cpp:122
auto constexpr defaultseed
Definition: envconfig.cpp:110
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:105
std::unique_ptr< Config > addGrpcConfigWithSecureGateway(std::unique_ptr< Config >, std::string const &secureGateway)
add a grpc address, port and secure_gateway to config
Definition: envconfig.cpp:130
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:101
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition: envconfig.cpp:31
std::atomic< bool > envUseIPv4
Definition: envconfig.cpp:28
char const * getEnvLocalhostAddr()
Definition: envconfig.h:36
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
static std::string nodeDatabase()
static std::string importNodeDatabase()
XRPAmount reference_fee
The cost of a reference transaction in drops.
Definition: Config.h:68
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition: Config.h:74
XRPAmount account_reserve
The account reserve requirement in drops.
Definition: Config.h:71