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))
50 if (isProxied(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;
78 auto res = balancer_->forwardToRippled(toForward, ctx.clientIp, ctx.isAdmin, ctx.yield);
80 notifyFailedToForward(ctx.method);
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 kFORCE_FORWARD =
"force_forward";
119 return ctx.isAdmin and ctx.params.contains(kFORCE_FORWARD) and
120 ctx.params.at(kFORCE_FORWARD).is_bool() and ctx.params.at(kFORCE_FORWARD).as_bool();
std::variant< RippledError, ClioError > CombinedError
Clio operates on a combination of Rippled and Custom Clio error codes.
Definition Errors.hpp:62
bool specifiesCurrentOrClosedLedger(boost::json::object const &request)
Check whether the request specifies the current or closed ledger.
Definition RPCHelpers.cpp:1591
static bool isForwarded(std::string_view s)
Checks if a string is a RPC command that will be forwarded to rippled.
Definition RPCCenter.cpp:94
Context that is used by the Webserver to pass around information about an incoming request.
Definition Context.hpp:22