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#include <xrpld/core/ConfigSections.h>
23
24namespace ripple {
25namespace test {
26
28
29void
31{
32 using namespace jtx;
33 // Default fees to old values, so tests don't have to worry about changes in
34 // Config.h
35 cfg.FEES.reference_fee = 10;
36 cfg.FEES.account_reserve = XRP(200).value().xrp().drops();
37 cfg.FEES.owner_reserve = XRP(50).value().xrp().drops();
38
39 // The Beta API (currently v2) is always available to tests
40 cfg.BETA_RPC_API = true;
41
42 cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
43 cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
45 cfg.legacy("database_path", "");
46 cfg.setupControl(true, true, true);
47 cfg["server"].append(PORT_PEER);
48 cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
49
50 // Using port 0 asks the operating system to allocate an unused port, which
51 // can be obtained after a "bind" call.
52 // Works for all system (Linux, Windows, Unix, Mac).
53 // Check https://man7.org/linux/man-pages/man7/ip.7.html
54 // "ip_local_port_range" section for more info
55 cfg[PORT_PEER].set("port", "0");
56 cfg[PORT_PEER].set("protocol", "peer");
57
58 cfg["server"].append(PORT_RPC);
59 cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
60 cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
61 cfg[PORT_RPC].set("port", "0");
62 cfg[PORT_RPC].set("protocol", "http,ws2");
63
64 cfg["server"].append(PORT_WS);
65 cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
66 cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
67 cfg[PORT_WS].set("port", "0");
68 cfg[PORT_WS].set("protocol", "ws");
69 cfg.SSL_VERIFY = false;
70}
71
72namespace jtx {
73
76{
77 (*cfg)[PORT_RPC].set("admin", "");
78 (*cfg)[PORT_WS].set("admin", "");
79 return cfg;
80}
81
84{
85 (*cfg)[PORT_RPC].set("admin", "");
86 (*cfg)[PORT_WS].set("admin", "");
87 (*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
88 return cfg;
89}
90
93{
94 (*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
95 (*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
96 return cfg;
97}
98
101{
102 (*cfg)[PORT_RPC].set("admin", "");
103 (*cfg)[PORT_WS].set("admin", "");
104 (*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
105 (*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
106 return cfg;
107}
108
109auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
110
113{
114 // If the config has valid validation keys then we run as a validator.
115 cfg->section(SECTION_VALIDATION_SEED)
116 .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
117 return cfg;
118}
119
122{
123 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
124 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
125 return cfg;
126}
127
131 std::string const& secureGateway)
132{
133 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
134
135 // Check https://man7.org/linux/man-pages/man7/ip.7.html
136 // "ip_local_port_range" section for using 0 ports
137 (*cfg)[SECTION_PORT_GRPC].set("port", "0");
138 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
139 return cfg;
140}
141
142} // namespace jtx
143} // namespace test
144} // 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:268
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:112
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:92
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition: envconfig.cpp:83
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition: envconfig.cpp:75
std::unique_ptr< Config > addGrpcConfig(std::unique_ptr< Config >)
add a grpc address and port to config
Definition: envconfig.cpp:121
auto constexpr defaultseed
Definition: envconfig.cpp:109
XRP_t const XRP
Converts to XRP Issue or STAmount.
Definition: amount.cpp:104
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:129
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:100
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition: envconfig.cpp:30
const char * getEnvLocalhostAddr()
Definition: envconfig.h:36
std::atomic< bool > envUseIPv4
Definition: envconfig.cpp:27
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