20 #include <ripple/app/ledger/InboundLedgers.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/ledger/LedgerToJson.h>
23 #include <ripple/app/main/Application.h>
24 #include <ripple/app/misc/NetworkOPs.h>
25 #include <ripple/app/reporting/P2pProxy.h>
26 #include <ripple/basics/Log.h>
27 #include <ripple/basics/PerfLog.h>
28 #include <ripple/basics/contract.h>
29 #include <ripple/core/Config.h>
30 #include <ripple/core/JobQueue.h>
31 #include <ripple/json/Object.h>
32 #include <ripple/json/to_string.h>
33 #include <ripple/net/InfoSub.h>
34 #include <ripple/net/RPCErr.h>
35 #include <ripple/protocol/ErrorCodes.h>
36 #include <ripple/protocol/jss.h>
37 #include <ripple/resource/Fees.h>
38 #include <ripple/rpc/Context.h>
39 #include <ripple/rpc/RPCHandler.h>
40 #include <ripple/rpc/Role.h>
41 #include <ripple/rpc/impl/Handler.h>
42 #include <ripple/rpc/impl/Tuning.h>
133 fillHandler(JsonContext& context, Handler
const*& result)
138 int const jobCount = context.app.getJobQueue().getJobCountGE(
jtCLIENT);
141 JLOG(context.j.debug()) <<
"Too busy for command: " << jobCount;
146 if (!context.params.isMember(jss::command) &&
147 !context.params.isMember(jss::method))
149 if (context.params.isMember(jss::command) &&
150 context.params.isMember(jss::method))
152 if (context.params[jss::command].asString() !=
153 context.params[jss::method].asString())
157 std::string strCommand = context.params.isMember(jss::command)
158 ? context.params[jss::command].asString()
159 : context.params[jss::method].asString();
161 JLOG(context.j.trace()) <<
"COMMAND:" << strCommand;
162 JLOG(context.j.trace()) <<
"REQUEST:" << context.params;
164 context.apiVersion, context.app.config().BETA_RPC_API, strCommand);
182 template <
class Object,
class Method>
185 JsonContext& context,
191 auto& perfLog = context.app.getPerfLog();
195 perfLog.rpcStart(name, curId);
197 context.app.getJobQueue().makeLoadEvent(
jtGENERIC,
"cmd:" + name);
200 auto ret = method(context, result);
203 JLOG(context.j.debug())
204 <<
"RPC call " << name <<
" completed in "
205 << ((
end - start).
count() / 1000000000.0) <<
"seconds";
206 perfLog.rpcFinish(name, curId);
209 catch (ReportingShouldProxy&)
216 perfLog.rpcError(name, curId);
217 JLOG(context.j.info()) <<
"Caught throw: " << e.
what();
238 "This is a reporting server. "
239 " The default behavior of a reporting server is to only"
240 " return validated data. If you are looking for not yet"
241 " validated data, include \"ledger_index : current\""
242 " in your request, which will cause this server to forward"
243 " the request to a p2p node. If the forward is successful"
244 " the response will include \"forwarded\" : \"true\"";
245 result[jss::warnings] = std::move(warnings);
259 Handler const* handler =
nullptr;
260 if (
auto error = fillHandler(context, handler))
272 <<
"start command: " << handler->
name_
276 auto ret = callMethod(context, method, handler->
name_, result);
279 <<
"finish command: " << handler->
name_
287 auto ret = callMethod(context, method, handler->
name_, result);
304 return handler->role_;