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
30 {
31  port_base += 3;
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 
86 auto constexpr defaultseed = "shUwVw52ofnCUX5m7kPTKzJdr4HEH";
87 
90 {
91  // If the config has valid validation keys then we run as a validator.
92  cfg->section(SECTION_VALIDATION_SEED)
93  .append(std::vector<std::string>{seed.empty() ? defaultseed : seed});
94  return cfg;
95 }
96 
99 {
100  for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
101  {
102  Section& s = (*cfg)[sectionName];
103  auto const port = s.get<std::int32_t>("port");
104  if (port)
105  {
106  s.set("port", std::to_string(*port + increment));
107  }
108  }
109  return cfg;
110 }
111 
114 {
115  std::string port_grpc = std::to_string(port_base + 3);
116  (*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
117  (*cfg)["port_grpc"].set("port", port_grpc);
118  return cfg;
119 }
120 
121 } // namespace jtx
122 } // namespace test
123 } // namespace ripple
ripple::Section
Holds a collection of configuration values.
Definition: BasicConfig.h:43
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:89
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:113
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:98
ripple::Config::setupControl
void setupControl(bool bQuiet, bool bSilent, bool bStandalone)
Definition: Config.cpp:201
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:167
ripple::Config
Definition: Config.h:69
ripple::Config::SSL_VERIFY
bool SSL_VERIFY
Definition: Config.h:177
std::to_string
T to_string(T... args)
ripple::test::jtx::defaultseed
constexpr auto defaultseed
Definition: envconfig.cpp:86
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:175
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:154
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::get
boost::optional< T > get(std::string const &name) const
Definition: BasicConfig.h:143
ripple::Section::set
void set(std::string const &key, std::string const &value)
Set a key/value pair.
Definition: BasicConfig.cpp:32
ripple::test::incPorts
void incPorts()
Definition: envconfig.cpp:29
std::string::empty
T empty(T... args)
ripple::test::port_base
int port_base
Definition: envconfig.cpp:27
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