20 #include <ripple/app/main/GRPCServer.h>
21 #include <ripple/resource/Fees.h>
36 peerClean = peer.
substr(first + 1);
42 template <
class Request,
class Response>
44 org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService& service,
45 grpc::ServerCompletionQueue& cq,
56 , bindListener_(
std::move(bindListener))
57 , handler_(
std::move(handler))
58 , requiredCondition_(
std::move(requiredCondition))
59 , loadType_(
std::move(loadType))
66 template <
class Request,
class Response>
70 return std::make_shared<CallData<Request, Response>>(
80 template <
class Request,
class Response>
85 BOOST_ASSERT(!finished_);
88 this->shared_from_this();
103 thisShared->process(coro);
110 grpc::StatusCode::INTERNAL,
"Job Queue is already stopped"};
111 responder_.FinishWithError(status,
this);
115 template <
class Request,
class Response>
122 auto usage = getUsage();
123 if (usage.disconnect())
126 grpc::StatusCode::RESOURCE_EXHAUSTED,
127 "usage balance exceeds threshhold"};
128 responder_.FinishWithError(status,
this);
132 auto loadType = getLoadType();
133 usage.charge(loadType);
134 auto role = getRole();
156 grpc::StatusCode::FAILED_PRECONDITION,
158 responder_.FinishWithError(status,
this);
163 responder_.Finish(result.
first, result.
second,
this);
169 grpc::Status status{grpc::StatusCode::INTERNAL, ex.
what()};
170 responder_.FinishWithError(status,
this);
174 template <
class Request,
class Response>
181 template <
class Request,
class Response>
188 template <
class Request,
class Response>
195 template <
class Request,
class Response>
200 boost::optional<beast::IP::Endpoint> endpoint =
223 boost::asio::ip::make_address(ipPair.
first),
253 JLOG(
journal_.
debug()) <<
"Completion Queue has been shutdown";
269 return sPtr.get() == ptr;
271 BOOST_ASSERT(it != requests.
end());
272 it->swap(requests.
back());
292 while (
cq_->Next(&tag, &ok))
296 <<
" ptr = " << ptr <<
" ok = " << ok;
301 <<
"Destroying object";
306 if (!ptr->isFinished())
308 JLOG(
journal_.
debug()) <<
"Received new request. Processing";
311 auto cloned = ptr->clone();
318 JLOG(
journal_.
debug()) <<
"Sent response. Destroying object";
332 auto addToRequests = [&requests](
auto callData) {
338 org::xrpl::rpc::v1::GetFeeRequest,
339 org::xrpl::rpc::v1::GetFeeResponse>;
341 addToRequests(std::make_shared<cd>(
345 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
353 org::xrpl::rpc::v1::GetAccountInfoRequest,
354 org::xrpl::rpc::v1::GetAccountInfoResponse>;
356 addToRequests(std::make_shared<cd>(
360 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
361 RequestGetAccountInfo,
368 org::xrpl::rpc::v1::GetTransactionRequest,
369 org::xrpl::rpc::v1::GetTransactionResponse>;
371 addToRequests(std::make_shared<cd>(
375 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
376 RequestGetTransaction,
383 org::xrpl::rpc::v1::SubmitTransactionRequest,
384 org::xrpl::rpc::v1::SubmitTransactionResponse>;
386 addToRequests(std::make_shared<cd>(
390 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
391 RequestSubmitTransaction,
399 org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest,
400 org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse>;
402 addToRequests(std::make_shared<cd>(
406 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
407 RequestGetAccountTransactionHistory,
424 grpc::ServerBuilder builder;
426 builder.AddListeningPort(
serverAddress_, grpc::InsecureServerCredentials());
432 cq_ = builder.AddCompletionQueue();
434 server_ = builder.BuildAndStart();
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
Holds a collection of configuration values.
std::shared_ptr< Coro > postCoro(JobType t, std::string const &name, F &&f)
Creates a coroutine and adds a job to the queue which will run it.
Stream trace() const
Severity stream access functions.
std::shared_ptr< Processor > clone() override
ErrorInfo const & get_error_info(error_code_i code)
Returns an ErrorInfo that reflects the error code.
const Charge feeMediumBurdenRPC
std::string to_string() const
Returns a string representing the endpoint.
org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService service_
std::pair< org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse, grpc::Status > doAccountTxGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest > &context)
grpc::ServerCompletionQueue & cq_
std::unique_ptr< grpc::Server > server_
const Charge feeReferenceRPC
constexpr const char * c_str() const
virtual bool isFinished() override
virtual NetworkOPs & getOPs()=0
Json::StaticString message
void erase(STObject &st, TypedField< U > const &f)
Remove a field in an STObject.
org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService & service_
std::unique_ptr< grpc::ServerCompletionQueue > cq_
Resource::Consumer getUsage()
std::shared_ptr< InfoSub > pointer
virtual LedgerMaster & getLedgerMaster()=0
virtual Config & config()=0
T find_last_of(T... args)
virtual JobQueue & getJobQueue()=0
std::pair< org::xrpl::rpc::v1::GetTransactionResponse, grpc::Status > doTxGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetTransactionRequest > &context)
GRPCServerImpl(Application &app)
Maps an rpc error code to its token and default message.
Resource::Charge getLoadType()
std::pair< std::string, bool > find(std::string const &name) const
Retrieve a key/value pair.
BindListener< Request, Response > bindListener_
virtual Resource::Manager & getResourceManager()=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::vector< std::shared_ptr< Processor > > setupListeners()
virtual beast::Journal journal(std::string const &name)=0
error_code_i conditionMet(Condition condition_required, T &context)
An endpoint that consumes resources.
T find_first_of(T... args)
std::pair< org::xrpl::rpc::v1::GetFeeResponse, grpc::Status > doFeeGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetFeeRequest > &context)
A version-independent IP address and port combination.
static boost::optional< Endpoint > from_string_checked(std::string const &s)
Create an Endpoint from a string.
Role
Indicates the level of administrative permission to grant.
CallData(org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService &service, grpc::ServerCompletionQueue &cq, Application &app, BindListener< Request, Response > bindListener, Handler< Request, Response > handler, RPC::Condition requiredCondition, Resource::Charge loadType)
virtual void process() override
std::string serverAddress_
std::pair< org::xrpl::rpc::v1::GetAccountInfoResponse, grpc::Status > doAccountInfoGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::GetAccountInfoRequest > &context)
bool exists(std::string const &name) const
Returns true if a section with the given name exists.
grpc::ServerAsyncResponseWriter< Response > responder_
Section & section(std::string const &name)
Returns the section with the given name.
std::pair< org::xrpl::rpc::v1::SubmitTransactionResponse, grpc::Status > doSubmitGrpc(RPC::GRPCContext< org::xrpl::rpc::v1::SubmitTransactionRequest > &context)