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/envconfig.h>
21
22#include <test/jtx/amount.h>
23#include <xrpld/core/ConfigSections.h>
24
25namespace ripple {
26namespace test {
27
28int port_base = 8000;
29void
30incPorts(int times)
31{
32 port_base += (4 * times);
33}
34
36
37void
39{
40 std::string const port_peer = std::to_string(port_base);
41 std::string port_rpc = std::to_string(port_base + 1);
43
44 using namespace jtx;
45 // Default fees to old values, so tests don't have to worry about changes in
46 // Config.h
47 cfg.FEES.reference_fee = 10;
48 cfg.FEES.account_reserve = XRP(200).value().xrp().drops();
49 cfg.FEES.owner_reserve = XRP(50).value().xrp().drops();
50
51 // The Beta API (currently v2) is always available to tests
52 cfg.BETA_RPC_API = true;
53
54 cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
55 cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
57 cfg.legacy("database_path", "");
58 cfg.setupControl(true, true, true);
59 cfg["server"].append(PORT_PEER);
60 cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
61 cfg[PORT_PEER].set("port", port_peer);
62 cfg[PORT_PEER].set("protocol", "peer");
63
64 cfg["server"].append(PORT_RPC);
65 cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
66 cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
67 cfg[PORT_RPC].set("port", port_rpc);
68 cfg[PORT_RPC].set("protocol", "http,ws2");
69
70 cfg["server"].append(PORT_WS);
71 cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
72 cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
73 cfg[PORT_WS].set("port", port_ws);
74 cfg[PORT_WS].set("protocol", "ws");
75 cfg.SSL_VERIFY = false;
76}
77
78namespace jtx {
79
82{
83 (*cfg)[PORT_RPC].set("admin", "");
84 (*cfg)[PORT_WS].set("admin", "");
85 return cfg;
86}
87
90{
91 (*cfg)[PORT_RPC].set("admin", "");
92 (*cfg)[PORT_WS].set("admin", "");
93 (*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
94 return cfg;
95}
96
99{
100 (*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
101 (*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
102 return cfg;
103}
104
107{
108 (*cfg)[PORT_RPC].set("admin", "");
109 (*cfg)[PORT_WS].set("admin", "");
110 (*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
111 (*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
112 return cfg;
113}
114
115auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
116
119{
120 // If the config has valid validation keys then we run as a validator.
121 cfg->section(SECTION_VALIDATION_SEED)
122 .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
123 return cfg;
124}
125
128{
129 for (auto const sectionName : {PORT_PEER, PORT_RPC, PORT_WS})
130 {
131 Section& s = (*cfg)[sectionName];
132 auto const port = s.get<std::int32_t>("port");
133 if (port)
134 {
135 s.set("port", std::to_string(*port + increment));
136 }
137 }
138 return cfg;
139}
140
143{
144 std::string port_grpc = std::to_string(port_base + 3);
145 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
146 (*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
147 return cfg;
148}
149
153 std::string const& secureGateway)
154{
155 std::string port_grpc = std::to_string(port_base + 3);
156 (*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
157 (*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
158 (*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
159 return cfg;
160}
161
162} // namespace jtx
163} // namespace test
164} // 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:295
bool SSL_VERIFY
Definition: Config.h:222
FeeSetup FEES
Definition: Config.h:211
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition: Config.cpp:267
Holds a collection of configuration values.
Definition: BasicConfig.h:43
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:32
std::optional< T > get(std::string const &name) const
Definition: BasicConfig.h:138
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:118
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:98
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition: envconfig.cpp:89
std::unique_ptr< Config > no_admin(std::unique_ptr< Config >)
adjust config so no admin ports are enabled
Definition: envconfig.cpp:81
std::unique_ptr< Config > port_increment(std::unique_ptr< Config >, int)
adjust the default configured server ports by a specified value
Definition: envconfig.cpp:127
std::unique_ptr< Config > addGrpcConfig(std::unique_ptr< Config >)
add a grpc address and port to config
Definition: envconfig.cpp:142
auto constexpr defaultseed
Definition: envconfig.cpp:115
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:151
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:106
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition: envconfig.cpp:38
void incPorts(int times)
Definition: envconfig.cpp:30
const char * getEnvLocalhostAddr()
Definition: envconfig.h:36
std::atomic< bool > envUseIPv4
Definition: envconfig.cpp:35
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:75
XRPAmount owner_reserve
The per-owned item reserve requirement in drops.
Definition: Config.h:81
XRPAmount account_reserve
The account reserve requirement in drops.
Definition: Config.h:78
T to_string(T... args)