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