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 <ripple/core/ConfigSections.h>
21 #include <test/jtx/Env.h>
22 #include <test/jtx/envconfig.h>
23 
24 namespace ripple {
25 namespace test {
26 
27 int port_base = 8000;
28 void
29 incPorts(int times)
30 {
31  port_base += (4 * times);
32 }
33 
35 
36 void
38 {
39  std::string const port_peer = std::to_string(port_base);
40  std::string port_rpc = std::to_string(port_base + 1);
41  std::string port_ws = std::to_string(port_base + 2);
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  cfg["port_peer"].set("port", port_peer);
51  cfg["port_peer"].set("protocol", "peer");
52 
53  cfg["server"].append("port_rpc");
54  cfg["port_rpc"].set("ip", getEnvLocalhostAddr());
55  cfg["port_rpc"].set("admin", getEnvLocalhostAddr());
56  cfg["port_rpc"].set("port", port_rpc);
57  cfg["port_rpc"].set("protocol", "http,ws2");
58 
59  cfg["server"].append("port_ws");
60  cfg["port_ws"].set("ip", getEnvLocalhostAddr());
61  cfg["port_ws"].set("admin", getEnvLocalhostAddr());
62  cfg["port_ws"].set("port", port_ws);
63  cfg["port_ws"].set("protocol", "ws");
64  cfg.SSL_VERIFY = false;
65 }
66 
67 namespace jtx {
68 
71 {
72  (*cfg)["port_rpc"].set("admin", "");
73  (*cfg)["port_ws"].set("admin", "");
74  return cfg;
75 }
76 
79 {
80  (*cfg)["port_rpc"].set("admin", "");
81  (*cfg)["port_ws"].set("admin", "");
82  (*cfg)["port_rpc"].set("secure_gateway", getEnvLocalhostAddr());
83  return cfg;
84 }
85 
88 {
89  (*cfg)["port_rpc"].set("admin", "127.0.0.0/8");
90  (*cfg)["port_ws"].set("admin", "127.0.0.0/8");
91  return cfg;
92 }
93 
96 {
97  (*cfg)["port_rpc"].set("admin", "");
98  (*cfg)["port_ws"].set("admin", "");
99  (*cfg)["port_rpc"].set("secure_gateway", "127.0.0.0/8");
100  (*cfg)["port_ws"].set("secure_gateway", "127.0.0.0/8");
101  return cfg;
102 }
103 
104 auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
105 
108 {
109  // If the config has valid validation keys then we run as a validator.
110  cfg->section(SECTION_VALIDATION_SEED)
111  .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
112  return cfg;
113 }
114 
117 {
118  for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
119  {
120  Section& s = (*cfg)[sectionName];
121  auto const port = s.get<std::int32_t>("port");
122  if (port)
123  {
124  s.set("port", std::to_string(*port + increment));
125  }
126  }
127  return cfg;
128 }
129 
132 {
133  std::string port_grpc = std::to_string(port_base + 3);
134  (*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
135  (*cfg)["port_grpc"].set("port", port_grpc);
136  return cfg;
137 }
138 
142  std::string const& secureGateway)
143 {
144  std::string port_grpc = std::to_string(port_base + 3);
145  (*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
146  (*cfg)["port_grpc"].set("port", port_grpc);
147  (*cfg)["port_grpc"].set("secure_gateway", secureGateway);
148  return cfg;
149 }
150 
151 } // namespace jtx
152 } // namespace test
153 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:42
ripple::test::jtx::secure_gateway
std::unique_ptr< Config > secure_gateway(std::unique_ptr< Config >)
Definition: envconfig.cpp:78
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:107
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:131
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:116
ripple::Config::setupControl
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition: Config.cpp:272
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:140
ripple::test::jtx::admin_localnet
std::unique_ptr< Config > admin_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:87
ripple::test::incPorts
void incPorts(int times)
Definition: envconfig.cpp:29
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:70
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:69
ripple::Config::SSL_VERIFY
bool SSL_VERIFY
Definition: Config.h:201
std::to_string
T to_string(T... args)
ripple::test::jtx::defaultseed
constexpr auto defaultseed
Definition: envconfig.cpp:104
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
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:34
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::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:27
ripple::test::jtx::secure_gateway_localnet
std::unique_ptr< Config > secure_gateway_localnet(std::unique_ptr< Config >)
Definition: envconfig.cpp:95
std::unique_ptr
STL class.
ripple::test::setupConfigForUnitTests
void setupConfigForUnitTests(Config &config)
initializes a config object for use with jtx::Env
Definition: envconfig.cpp:37
ripple::ConfigSection::nodeDatabase
static std::string nodeDatabase()
Definition: ConfigSections.h:33