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  cfg.overwrite(ConfigSection::nodeDatabase(), "type", "memory");
53  cfg.overwrite(ConfigSection::nodeDatabase(), "path", "main");
55  cfg.legacy("database_path", "");
56  cfg.setupControl(true, true, true);
57  cfg["server"].append("port_peer");
58  cfg["port_peer"].set("ip", getEnvLocalhostAddr());
59  cfg["port_peer"].set("port", port_peer);
60  cfg["port_peer"].set("protocol", "peer");
61 
62  cfg["server"].append("port_rpc");
63  cfg["port_rpc"].set("ip", getEnvLocalhostAddr());
64  cfg["port_rpc"].set("admin", getEnvLocalhostAddr());
65  cfg["port_rpc"].set("port", port_rpc);
66  cfg["port_rpc"].set("protocol", "http,ws2");
67 
68  cfg["server"].append("port_ws");
69  cfg["port_ws"].set("ip", getEnvLocalhostAddr());
70  cfg["port_ws"].set("admin", getEnvLocalhostAddr());
71  cfg["port_ws"].set("port", port_ws);
72  cfg["port_ws"].set("protocol", "ws");
73  cfg.SSL_VERIFY = false;
74 }
75 
76 namespace jtx {
77 
80 {
81  (*cfg)["port_rpc"].set("admin", "");
82  (*cfg)["port_ws"].set("admin", "");
83  return cfg;
84 }
85 
88 {
89  (*cfg)["port_rpc"].set("admin", "");
90  (*cfg)["port_ws"].set("admin", "");
91  (*cfg)["port_rpc"].set("secure_gateway", getEnvLocalhostAddr());
92  return cfg;
93 }
94 
97 {
98  (*cfg)["port_rpc"].set("admin", "127.0.0.0/8");
99  (*cfg)["port_ws"].set("admin", "127.0.0.0/8");
100  return cfg;
101 }
102 
105 {
106  (*cfg)["port_rpc"].set("admin", "");
107  (*cfg)["port_ws"].set("admin", "");
108  (*cfg)["port_rpc"].set("secure_gateway", "127.0.0.0/8");
109  (*cfg)["port_ws"].set("secure_gateway", "127.0.0.0/8");
110  return cfg;
111 }
112 
113 auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
114 
117 {
118  // If the config has valid validation keys then we run as a validator.
119  cfg->section(SECTION_VALIDATION_SEED)
120  .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
121  return cfg;
122 }
123 
126 {
127  for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
128  {
129  Section& s = (*cfg)[sectionName];
130  auto const port = s.get<std::int32_t>("port");
131  if (port)
132  {
133  s.set("port", std::to_string(*port + increment));
134  }
135  }
136  return cfg;
137 }
138 
141 {
142  std::string port_grpc = std::to_string(port_base + 3);
143  (*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
144  (*cfg)["port_grpc"].set("port", port_grpc);
145  return cfg;
146 }
147 
151  std::string const& secureGateway)
152 {
153  std::string port_grpc = std::to_string(port_base + 3);
154  (*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
155  (*cfg)["port_grpc"].set("port", port_grpc);
156  (*cfg)["port_grpc"].set("secure_gateway", secureGateway);
157  return cfg;
158 }
159 
160 } // namespace jtx
161 } // namespace test
162 } // 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:72
ripple::test::jtx::secure_gateway
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition: envconfig.cpp:87
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:116
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:140
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:125
ripple::Config::setupControl
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition: Config.cpp:273
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:149
ripple::test::jtx::admin_localnet
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:96
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:79
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:89
ripple::Config::SSL_VERIFY
bool SSL_VERIFY
Definition: Config.h:220
std::to_string
T to_string(T... args)
ripple::test::jtx::defaultseed
constexpr auto defaultseed
Definition: envconfig.cpp:113
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:75
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:78
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:104
std::unique_ptr
STL class.
ripple::Config::FEES
FeeSetup FEES
Definition: Config.h:209
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