22class ForwardingProxy {
25 std::shared_ptr<etl::LoadBalancerInterface> balancer_;
26 std::reference_wrapper<CountersType> counters_;
27 std::shared_ptr<HandlerProviderType const> handlerProvider_;
31 std::shared_ptr<etl::LoadBalancerInterface>
const& balancer,
32 CountersType& counters,
33 std::shared_ptr<HandlerProviderType const>
const& handlerProvider
35 : balancer_{balancer}, counters_{std::ref(counters)}, handlerProvider_{handlerProvider}
42 auto const& request = ctx.
params;
44 if (ctx.
method ==
"subscribe" || ctx.
method ==
"unsubscribe")
47 if (handlerProvider_->isClioOnly(ctx.
method))
56 if (isForcedForward(ctx))
59 auto const checkAccountInfoForward = [&] {
60 return ctx.
method ==
"account_info" and request.contains(
"queue") and
61 request.at(
"queue").is_bool() and request.at(
"queue").as_bool();
64 auto const checkLedgerForward = [&] {
65 return ctx.
method ==
"ledger" and request.contains(
"queue") and
66 request.at(
"queue").is_bool() and request.at(
"queue").as_bool();
69 return static_cast<bool>(checkAccountInfoForward() or checkLedgerForward());
75 auto toForward = ctx.
params;
76 toForward[
"command"] = ctx.
method;
80 notifyFailedToForward(ctx.
method);
81 return Result{Status{CombinedError{res.error()}}};
84 notifyForwarded(ctx.
method);
85 return Result{std::move(res).value()};
89 isProxied(std::string
const& method)
const
96 notifyForwarded(std::string
const& method)
98 if (validHandler(method))
99 counters_.get().rpcForwarded(method);
103 notifyFailedToForward(std::string
const& method)
105 if (validHandler(method))
106 counters_.get().rpcFailedToForward(method);
110 validHandler(std::string
const& method)
const
112 return handlerProvider_->contains(method) || isProxied(method);
118 static constexpr auto kForceForward =
"force_forward";
119 return ctx.
isAdmin and ctx.
params.contains(kForceForward) and
120 ctx.
params.at(kForceForward).is_bool() and ctx.
params.at(kForceForward).as_bool();
bool specifiesCurrentOrClosedLedger(boost::json::object const &request)
Check whether the request specifies the current or closed ledger.
Definition RPCHelpers.cpp:1721
static bool isForwarded(std::string_view s)
Checks if a string is a RPC command that will be forwarded to rippled.
Definition RPCCenter.cpp:95
Context that is used by the Webserver to pass around information about an incoming request.
Definition Context.hpp:22
std::string clientIp
IP of the peer.
Definition Context.hpp:29
boost::asio::yield_context yield
The coroutine context the request is handled in.
Definition Context.hpp:23
boost::json::object params
Request's parameters/data as a JSON object.
Definition Context.hpp:26
std::string method
The method/command requested.
Definition Context.hpp:24
bool isAdmin
Whether the peer has admin privileges.
Definition Context.hpp:30