mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-19 18:15:50 +00:00
feat: allow port_grpc to be specified in [server] stanza (#4728)
Prior to this commit, `port_grpc` could not be added to the [server] stanza. Instead of validating gRPC IP/Port/Protocol information in ServerHandler, validate grpc port info in GRPCServer constructor. This should not break backwards compatibility. gRPC-related config info must be in a section (stanza) called [port_gprc]. * Close #4015 - That was an alternate solution. It was decided that with relaxed validation, it is not necessary to rename port_grpc. * Fix #4557
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <ripple/resource/Fees.h>
|
||||
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -427,9 +428,9 @@ GRPCServerImpl::GRPCServerImpl(Application& app)
|
||||
: app_(app), journal_(app_.journal("gRPC Server"))
|
||||
{
|
||||
// if present, get endpoint from config
|
||||
if (app_.config().exists("port_grpc"))
|
||||
if (app_.config().exists(SECTION_PORT_GRPC))
|
||||
{
|
||||
const auto& section = app_.config().section("port_grpc");
|
||||
Section const& section = app_.config().section(SECTION_PORT_GRPC);
|
||||
|
||||
auto const optIp = section.get("ip");
|
||||
if (!optIp)
|
||||
@@ -659,7 +660,7 @@ GRPCServerImpl::setupListeners()
|
||||
secureGatewayIPs_));
|
||||
}
|
||||
return requests;
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
GRPCServerImpl::start()
|
||||
|
||||
@@ -2768,9 +2768,9 @@ NetworkOPsImp::getServerInfo(bool human, bool admin, bool counters)
|
||||
}
|
||||
}
|
||||
|
||||
if (app_.config().exists("port_grpc"))
|
||||
if (app_.config().exists(SECTION_PORT_GRPC))
|
||||
{
|
||||
auto const& grpcSection = app_.config().section("port_grpc");
|
||||
auto const& grpcSection = app_.config().section(SECTION_PORT_GRPC);
|
||||
auto const optPort = grpcSection.get("port");
|
||||
if (optPort && grpcSection.get("ip"))
|
||||
{
|
||||
|
||||
@@ -49,18 +49,24 @@ struct ConfigSection
|
||||
// VFALCO TODO Rename and replace these macros with variables.
|
||||
#define SECTION_AMENDMENTS "amendments"
|
||||
#define SECTION_AMENDMENT_MAJORITY_TIME "amendment_majority_time"
|
||||
#define SECTION_BETA_RPC_API "beta_rpc_api"
|
||||
#define SECTION_CLUSTER_NODES "cluster_nodes"
|
||||
#define SECTION_COMPRESSION "compression"
|
||||
#define SECTION_DATAGRAM_MONITOR "datagram_monitor"
|
||||
#define SECTION_DEBUG_LOGFILE "debug_logfile"
|
||||
#define SECTION_ELB_SUPPORT "elb_support"
|
||||
#define SECTION_FEE_DEFAULT "fee_default"
|
||||
#define SECTION_FETCH_DEPTH "fetch_depth"
|
||||
#define SECTION_HISTORICAL_SHARD_PATHS "historical_shard_paths"
|
||||
#define SECTION_IMPORT_VL_KEYS "import_vl_keys"
|
||||
#define SECTION_INSIGHT "insight"
|
||||
#define SECTION_IO_WORKERS "io_workers"
|
||||
#define SECTION_IPS "ips"
|
||||
#define SECTION_IPS_FIXED "ips_fixed"
|
||||
#define SECTION_LEDGER_HISTORY "ledger_history"
|
||||
#define SECTION_LEDGER_REPLAY "ledger_replay"
|
||||
#define SECTION_MAX_TRANSACTIONS "max_transactions"
|
||||
#define SECTION_NETWORK_ID "network_id"
|
||||
#define SECTION_NETWORK_QUORUM "network_quorum"
|
||||
#define SECTION_NODE_SEED "node_seed"
|
||||
#define SECTION_NODE_SIZE "node_size"
|
||||
@@ -73,6 +79,8 @@ struct ConfigSection
|
||||
#define SECTION_PEERS_MAX "peers_max"
|
||||
#define SECTION_PEERS_IN_MAX "peers_in_max"
|
||||
#define SECTION_PEERS_OUT_MAX "peers_out_max"
|
||||
#define SECTION_PORT_GRPC "port_grpc"
|
||||
#define SECTION_PREFETCH_WORKERS "prefetch_workers"
|
||||
#define SECTION_REDUCE_RELAY "reduce_relay"
|
||||
#define SECTION_RELATIONAL_DB "relational_db"
|
||||
#define SECTION_RELAY_PROPOSALS "relay_proposals"
|
||||
@@ -84,6 +92,7 @@ struct ConfigSection
|
||||
#define SECTION_SSL_VERIFY_FILE "ssl_verify_file"
|
||||
#define SECTION_SSL_VERIFY_DIR "ssl_verify_dir"
|
||||
#define SECTION_SERVER_DOMAIN "server_domain"
|
||||
#define SECTION_SWEEP_INTERVAL "sweep_interval"
|
||||
#define SECTION_VALIDATORS_FILE "validators_file"
|
||||
#define SECTION_VALIDATION_SEED "validation_seed"
|
||||
#define SECTION_VALIDATOR_KEYS "validator_keys"
|
||||
@@ -94,14 +103,6 @@ struct ConfigSection
|
||||
#define SECTION_VALIDATOR_TOKEN "validator_token"
|
||||
#define SECTION_VETO_AMENDMENTS "veto_amendments"
|
||||
#define SECTION_WORKERS "workers"
|
||||
#define SECTION_IO_WORKERS "io_workers"
|
||||
#define SECTION_PREFETCH_WORKERS "prefetch_workers"
|
||||
#define SECTION_LEDGER_REPLAY "ledger_replay"
|
||||
#define SECTION_BETA_RPC_API "beta_rpc_api"
|
||||
#define SECTION_SWEEP_INTERVAL "sweep_interval"
|
||||
#define SECTION_NETWORK_ID "network_id"
|
||||
#define SECTION_IMPORT_VL_KEYS "import_vl_keys"
|
||||
#define SECTION_DATAGRAM_MONITOR "datagram_monitor"
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <ripple/basics/make_SSLContext.h>
|
||||
#include <ripple/beast/net/IPAddressConversion.h>
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/json/json_reader.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
@@ -46,9 +47,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/beast/http/fields.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace ripple {
|
||||
@@ -1344,6 +1343,12 @@ parse_Ports(Config const& config, std::ostream& log)
|
||||
log << "Missing section: [" << name << "]";
|
||||
Throw<std::exception>();
|
||||
}
|
||||
|
||||
// grpc ports are parsed by GRPCServer class. Do not validate
|
||||
// grpc port information in this file.
|
||||
if (name == SECTION_PORT_GRPC)
|
||||
continue;
|
||||
|
||||
ParsedPort parsed = common;
|
||||
parsed.name = name;
|
||||
parse_Port(parsed, config[name], log);
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
// frequently used macros defined here for convinience.
|
||||
#define PORT_WS "port_ws"
|
||||
#define PORT_RPC "port_rpc"
|
||||
#define PORT_PEER "port_peer"
|
||||
|
||||
extern std::atomic<bool> envUseIPv4;
|
||||
|
||||
inline const char*
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <test/jtx/envconfig.h>
|
||||
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/amount.h>
|
||||
|
||||
namespace ripple {
|
||||
@@ -58,22 +57,22 @@ setupConfigForUnitTests(Config& cfg)
|
||||
cfg.deprecatedClearSection(ConfigSection::importNodeDatabase());
|
||||
cfg.legacy("database_path", "");
|
||||
cfg.setupControl(true, true, true);
|
||||
cfg["server"].append("port_peer");
|
||||
cfg["port_peer"].set("ip", getEnvLocalhostAddr());
|
||||
cfg["port_peer"].set("port", port_peer);
|
||||
cfg["port_peer"].set("protocol", "peer");
|
||||
cfg["server"].append(PORT_PEER);
|
||||
cfg[PORT_PEER].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_PEER].set("port", port_peer);
|
||||
cfg[PORT_PEER].set("protocol", "peer");
|
||||
|
||||
cfg["server"].append("port_rpc");
|
||||
cfg["port_rpc"].set("ip", getEnvLocalhostAddr());
|
||||
cfg["port_rpc"].set("admin", getEnvLocalhostAddr());
|
||||
cfg["port_rpc"].set("port", port_rpc);
|
||||
cfg["port_rpc"].set("protocol", "http,ws2");
|
||||
cfg["server"].append(PORT_RPC);
|
||||
cfg[PORT_RPC].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_RPC].set("port", port_rpc);
|
||||
cfg[PORT_RPC].set("protocol", "http,ws2");
|
||||
|
||||
cfg["server"].append("port_ws");
|
||||
cfg["port_ws"].set("ip", getEnvLocalhostAddr());
|
||||
cfg["port_ws"].set("admin", getEnvLocalhostAddr());
|
||||
cfg["port_ws"].set("port", port_ws);
|
||||
cfg["port_ws"].set("protocol", "ws");
|
||||
cfg["server"].append(PORT_WS);
|
||||
cfg[PORT_WS].set("ip", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("admin", getEnvLocalhostAddr());
|
||||
cfg[PORT_WS].set("port", port_ws);
|
||||
cfg[PORT_WS].set("protocol", "ws");
|
||||
cfg.SSL_VERIFY = false;
|
||||
}
|
||||
|
||||
@@ -82,8 +81,8 @@ namespace jtx {
|
||||
std::unique_ptr<Config>
|
||||
no_admin(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin", "");
|
||||
(*cfg)["port_ws"].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -99,27 +98,27 @@ no_admin_networkid(std::unique_ptr<Config> cfg)
|
||||
std::unique_ptr<Config>
|
||||
secure_gateway(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin", "");
|
||||
(*cfg)["port_ws"].set("admin", "");
|
||||
(*cfg)["port_rpc"].set("secure_gateway", getEnvLocalhostAddr());
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", getEnvLocalhostAddr());
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
admin_localnet(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin", "127.0.0.0/8");
|
||||
(*cfg)["port_ws"].set("admin", "127.0.0.0/8");
|
||||
(*cfg)[PORT_RPC].set("admin", "127.0.0.0/8");
|
||||
(*cfg)[PORT_WS].set("admin", "127.0.0.0/8");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
std::unique_ptr<Config>
|
||||
secure_gateway_localnet(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
(*cfg)["port_rpc"].set("admin", "");
|
||||
(*cfg)["port_ws"].set("admin", "");
|
||||
(*cfg)["port_rpc"].set("secure_gateway", "127.0.0.0/8");
|
||||
(*cfg)["port_ws"].set("secure_gateway", "127.0.0.0/8");
|
||||
(*cfg)[PORT_RPC].set("admin", "");
|
||||
(*cfg)[PORT_WS].set("admin", "");
|
||||
(*cfg)[PORT_RPC].set("secure_gateway", "127.0.0.0/8");
|
||||
(*cfg)[PORT_WS].set("secure_gateway", "127.0.0.0/8");
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -137,7 +136,7 @@ validator(std::unique_ptr<Config> cfg, std::string const& seed)
|
||||
std::unique_ptr<Config>
|
||||
port_increment(std::unique_ptr<Config> cfg, int increment)
|
||||
{
|
||||
for (auto const sectionName : {"port_peer", "port_rpc", "port_ws"})
|
||||
for (auto const sectionName : {PORT_PEER, PORT_RPC, PORT_WS})
|
||||
{
|
||||
Section& s = (*cfg)[sectionName];
|
||||
auto const port = s.get<std::int32_t>("port");
|
||||
@@ -153,8 +152,8 @@ std::unique_ptr<Config>
|
||||
addGrpcConfig(std::unique_ptr<Config> cfg)
|
||||
{
|
||||
std::string port_grpc = std::to_string(port_base + 3);
|
||||
(*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)["port_grpc"].set("port", port_grpc);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@@ -164,9 +163,9 @@ addGrpcConfigWithSecureGateway(
|
||||
std::string const& secureGateway)
|
||||
{
|
||||
std::string port_grpc = std::to_string(port_base + 3);
|
||||
(*cfg)["port_grpc"].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)["port_grpc"].set("port", port_grpc);
|
||||
(*cfg)["port_grpc"].set("secure_gateway", secureGateway);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("ip", getEnvLocalhostAddr());
|
||||
(*cfg)[SECTION_PORT_GRPC].set("port", port_grpc);
|
||||
(*cfg)[SECTION_PORT_GRPC].set("secure_gateway", secureGateway);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/rpc/impl/Tuning.h>
|
||||
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <test/jtx.h>
|
||||
#include <test/jtx/Env.h>
|
||||
#include <test/jtx/envconfig.h>
|
||||
@@ -56,7 +57,8 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
testcase("GetLedger");
|
||||
using namespace test::jtx;
|
||||
std::unique_ptr<Config> config = envconfig(addGrpcConfig);
|
||||
std::string grpcPort = *(*config)["port_grpc"].get<std::string>("port");
|
||||
std::string grpcPort =
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config), features);
|
||||
|
||||
env.close();
|
||||
@@ -498,7 +500,8 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
testcase("GetLedgerData");
|
||||
using namespace test::jtx;
|
||||
std::unique_ptr<Config> config = envconfig(addGrpcConfig);
|
||||
std::string grpcPort = *(*config)["port_grpc"].get<std::string>("port");
|
||||
std::string grpcPort =
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config), features);
|
||||
auto grpcLedgerData = [&grpcPort](
|
||||
auto sequence, std::string marker = "") {
|
||||
@@ -620,7 +623,8 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
testcase("GetLedgerDiff");
|
||||
using namespace test::jtx;
|
||||
std::unique_ptr<Config> config = envconfig(addGrpcConfig);
|
||||
std::string grpcPort = *(*config)["port_grpc"].get<std::string>("port");
|
||||
std::string grpcPort =
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config), features);
|
||||
|
||||
auto grpcLedgerDiff = [&grpcPort](
|
||||
@@ -735,7 +739,8 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
testcase("GetLedgerDiff");
|
||||
using namespace test::jtx;
|
||||
std::unique_ptr<Config> config = envconfig(addGrpcConfig);
|
||||
std::string grpcPort = *(*config)["port_grpc"].get<std::string>("port");
|
||||
std::string grpcPort =
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config), features);
|
||||
|
||||
auto grpcLedgerEntry = [&grpcPort](auto sequence, auto key) {
|
||||
@@ -895,7 +900,7 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
std::unique_ptr<Config> config = envconfig(
|
||||
addGrpcConfigWithSecureGateway, getEnvLocalhostAddr());
|
||||
std::string grpcPort =
|
||||
*(*config)["port_grpc"].get<std::string>("port");
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config), features);
|
||||
|
||||
env.close();
|
||||
@@ -955,7 +960,7 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
std::unique_ptr<Config> config =
|
||||
envconfig(addGrpcConfigWithSecureGateway, secureGatewayIp);
|
||||
std::string grpcPort =
|
||||
*(*config)["port_grpc"].get<std::string>("port");
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config));
|
||||
|
||||
env.close();
|
||||
@@ -1008,7 +1013,7 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
std::unique_ptr<Config> config = envconfig(
|
||||
addGrpcConfigWithSecureGateway, getEnvLocalhostAddr());
|
||||
std::string grpcPort =
|
||||
*(*config)["port_grpc"].get<std::string>("port");
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config));
|
||||
|
||||
env.close();
|
||||
@@ -1065,7 +1070,7 @@ class ReportingETL_test : public beast::unit_test::suite
|
||||
std::unique_ptr<Config> config =
|
||||
envconfig(addGrpcConfigWithSecureGateway, secureGatewayIp);
|
||||
std::string grpcPort =
|
||||
*(*config)["port_grpc"].get<std::string>("port");
|
||||
*(*config)[SECTION_PORT_GRPC].get<std::string>("port");
|
||||
Env env(*this, std::move(config));
|
||||
|
||||
env.close();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/app/misc/NetworkOPs.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <test/jtx.h>
|
||||
|
||||
@@ -105,7 +106,7 @@ admin = 127.0.0.1
|
||||
auto const rpc_port =
|
||||
(*config)["port_rpc"].get<unsigned int>("port");
|
||||
auto const grpc_port =
|
||||
(*config)["port_grpc"].get<unsigned int>("port");
|
||||
(*config)[SECTION_PORT_GRPC].get<unsigned int>("port");
|
||||
auto const ws_port = (*config)["port_ws"].get<unsigned int>("port");
|
||||
BEAST_EXPECT(grpc_port);
|
||||
BEAST_EXPECT(rpc_port);
|
||||
|
||||
Reference in New Issue
Block a user