mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +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:
@@ -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