41 std::shared_ptr<LoadBalancerType> balancer_;
42 std::reference_wrapper<CountersType> counters_;
43 std::shared_ptr<HandlerProviderType const> handlerProvider_;
47 std::shared_ptr<LoadBalancerType>
const& balancer,
48 CountersType& counters,
49 std::shared_ptr<HandlerProviderType const>
const& handlerProvider
51 : balancer_{balancer}, counters_{std::ref(counters)}, handlerProvider_{handlerProvider}
58 auto const& request = ctx.params;
60 if (ctx.method ==
"subscribe" || ctx.method ==
"unsubscribe")
63 if (handlerProvider_->isClioOnly(ctx.method))
66 if (isProxied(ctx.method))
72 if (isForcedForward(ctx))
75 auto const checkAccountInfoForward = [&]() {
76 return ctx.method ==
"account_info" and request.contains(
"queue") and request.at(
"queue").is_bool() and
77 request.at(
"queue").as_bool();
80 auto const checkLedgerForward = [&]() {
81 return ctx.method ==
"ledger" and request.contains(
"queue") and request.at(
"queue").is_bool() and
82 request.at(
"queue").as_bool();
85 return static_cast<bool>(checkAccountInfoForward() or checkLedgerForward());
91 auto toForward = ctx.params;
92 toForward[
"command"] = ctx.method;
94 auto res = balancer_->forwardToRippled(toForward, ctx.clientIp, ctx.isAdmin, ctx.yield);
96 notifyFailedToForward(ctx.method);
100 notifyForwarded(ctx.method);
101 return Result{std::move(res).value()};
105 isProxied(std::string
const& method)
const
107 static std::unordered_set<std::string>
const kPROXIED_COMMANDS{
108 "server_definitions",
111 "submit_multisigned",
122 return kPROXIED_COMMANDS.contains(method);
127 notifyForwarded(std::string
const& method)
129 if (validHandler(method))
130 counters_.get().rpcForwarded(method);
134 notifyFailedToForward(std::string
const& method)
136 if (validHandler(method))
137 counters_.get().rpcFailedToForward(method);
141 validHandler(std::string
const& method)
const
143 return handlerProvider_->contains(method) || isProxied(method);
149 static constexpr auto kFORCE_FORWARD =
"force_forward";
150 return ctx.isAdmin and ctx.params.contains(kFORCE_FORWARD) and ctx.params.at(kFORCE_FORWARD).is_bool() and
151 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 whethe the request specifies the current or closed ledger.
Definition RPCHelpers.cpp:1332
Context that is used by the Webserver to pass around information about an incoming request.
Definition Context.hpp:40