Forward client IP to rippled when proxying (#77)

This commit is contained in:
CJ Cobb
2022-01-05 14:51:00 -05:00
committed by GitHub
parent 41e412302b
commit 49c7c9989f
11 changed files with 37 additions and 86 deletions

View File

@@ -11,7 +11,8 @@ make_WsContext(
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<WsBase> const& session,
Backend::LedgerRange const& range,
Counters& counters)
Counters& counters,
std::string const& clientIp)
{
if (!request.contains("command"))
return {};
@@ -27,7 +28,8 @@ make_WsContext(
balancer,
session,
range,
counters};
counters,
clientIp};
}
std::optional<Context>
@@ -37,7 +39,8 @@ make_HttpContext(
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
Backend::LedgerRange const& range,
RPC::Counters& counters)
RPC::Counters& counters,
std::string const& clientIp)
{
if (!request.contains("method") || !request.at("method").is_string())
return {};
@@ -67,7 +70,8 @@ make_HttpContext(
balancer,
nullptr,
range,
counters};
counters,
clientIp};
}
boost::json::object
@@ -162,7 +166,7 @@ buildResponse(Context const& ctx)
{
if (shouldForwardToRippled(ctx))
{
auto res = ctx.balancer->forwardToRippled(ctx.params);
auto res = ctx.balancer->forwardToRippled(ctx.params, ctx.clientIp);
ctx.counters.rpcForwarded(ctx.method);

View File

@@ -39,6 +39,7 @@ struct Context
std::shared_ptr<WsBase> session;
Backend::LedgerRange const& range;
Counters& counters;
std::string clientIp;
Context(
std::string const& command_,
@@ -49,7 +50,8 @@ struct Context
std::shared_ptr<ETLLoadBalancer> const& balancer_,
std::shared_ptr<WsBase> const& session_,
Backend::LedgerRange const& range_,
Counters& counters_)
Counters& counters_,
std::string const& clientIp_)
: method(command_)
, version(version_)
, params(params_)
@@ -59,6 +61,7 @@ struct Context
, session(session_)
, range(range_)
, counters(counters_)
, clientIp(clientIp_)
{
}
};
@@ -138,7 +141,8 @@ make_WsContext(
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<WsBase> const& session,
Backend::LedgerRange const& range,
Counters& counters);
Counters& counters,
std::string const& clientIp);
std::optional<Context>
make_HttpContext(
@@ -147,7 +151,8 @@ make_HttpContext(
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
Backend::LedgerRange const& range,
Counters& counters);
Counters& counters,
std::string const& clientIp);
Result
buildResponse(Context const& ctx);

View File

@@ -31,7 +31,7 @@ doServerInfo(Context const& context)
info["counters"].as_object()["rpc"] = context.counters.report();
}
auto serverInfoRippled = context.balancer->forwardToRippled(context.params);
auto serverInfoRippled = context.balancer->forwardToRippled(context.params, context.clientIp);
if (serverInfoRippled && !serverInfoRippled->contains("error"))
response["info"].as_object()["load_factor"] = 1;