mirror of
https://github.com/XRPLF/clio.git
synced 2026-06-05 09:46:48 +00:00
Forward client IP to rippled when proxying (#77)
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user