44 std::shared_ptr<etlng::LoadBalancerInterface> balancer_;
45 std::reference_wrapper<CountersType> counters_;
46 std::shared_ptr<HandlerProviderType const> handlerProvider_;
50 std::shared_ptr<etlng::LoadBalancerInterface>
const& balancer,
51 CountersType& counters,
52 std::shared_ptr<HandlerProviderType const>
const& handlerProvider
54 : balancer_{balancer}, counters_{std::ref(counters)}, handlerProvider_{handlerProvider}
61 auto const& request = ctx.params;
63 if (ctx.method ==
"subscribe" || ctx.method ==
"unsubscribe")
66 if (handlerProvider_->isClioOnly(ctx.method))
69 if (isProxied(ctx.method))
75 if (isForcedForward(ctx))
78 auto const checkAccountInfoForward = [&]() {
79 return ctx.method ==
"account_info" and request.contains(
"queue") and request.at(
"queue").is_bool() and
80 request.at(
"queue").as_bool();
83 auto const checkLedgerForward = [&]() {
84 return ctx.method ==
"ledger" and request.contains(
"queue") and request.at(
"queue").is_bool() and
85 request.at(
"queue").as_bool();
88 return static_cast<bool>(checkAccountInfoForward() or checkLedgerForward());
94 auto toForward = ctx.params;
95 toForward[
"command"] = ctx.method;
97 auto res = balancer_->forwardToRippled(toForward, ctx.clientIp, ctx.isAdmin, ctx.yield);
99 notifyFailedToForward(ctx.method);
103 notifyForwarded(ctx.method);
104 return Result{std::move(res).value()};
108 isProxied(std::string
const& method)
const
115 notifyForwarded(std::string
const& method)
117 if (validHandler(method))
118 counters_.get().rpcForwarded(method);
122 notifyFailedToForward(std::string
const& method)
124 if (validHandler(method))
125 counters_.get().rpcFailedToForward(method);
129 validHandler(std::string
const& method)
const
131 return handlerProvider_->contains(method) || isProxied(method);
137 static constexpr auto kFORCE_FORWARD =
"force_forward";
138 return ctx.isAdmin and ctx.params.contains(kFORCE_FORWARD) and ctx.params.at(kFORCE_FORWARD).is_bool() and
139 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:79
bool specifiesCurrentOrClosedLedger(boost::json::object const &request)
Check whether the request specifies the current or closed ledger.
Definition RPCHelpers.cpp:1504
static bool isForwarded(std::string_view s)
Checks if a string is a RPC command that will be forwarded to rippled.
Definition RPCCenter.cpp:108
Context that is used by the Webserver to pass around information about an incoming request.
Definition Context.hpp:40