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();
157 grpc::StatusCode::FAILED_PRECONDITION,
159 responder_.FinishWithError(status,
this);
164 responder_.Finish(result.
first, result.
second,
this);
170 grpc::Status status{grpc::StatusCode::INTERNAL, ex.
what()};
171 responder_.FinishWithError(status,
this);
175 template <
class Request,
class Response>
182 template <
class Request,
class Response>
189 template <
class Request,
class Response>
196 template <
class Request,
class Response>
201 boost::optional<beast::IP::Endpoint> endpoint =
224 boost::asio::ip::make_address(ipPair.
first),
254 JLOG(
journal_.
debug()) <<
"Completion Queue has been shutdown";
270 return sPtr.get() == ptr;
272 BOOST_ASSERT(it != requests.
end());
273 it->swap(requests.
back());
293 while (
cq_->Next(&tag, &ok))
297 <<
" ptr = " << ptr <<
" ok = " << ok;
302 <<
"Destroying object";
307 if (!ptr->isFinished())
309 JLOG(
journal_.
debug()) <<
"Received new request. Processing";
312 auto cloned = ptr->clone();
319 JLOG(
journal_.
debug()) <<
"Sent response. Destroying object";
333 auto addToRequests = [&requests](
auto callData) {
339 org::xrpl::rpc::v1::GetFeeRequest,
340 org::xrpl::rpc::v1::GetFeeResponse>;
342 addToRequests(std::make_shared<cd>(
346 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
354 org::xrpl::rpc::v1::GetAccountInfoRequest,
355 org::xrpl::rpc::v1::GetAccountInfoResponse>;
357 addToRequests(std::make_shared<cd>(
361 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
362 RequestGetAccountInfo,
369 org::xrpl::rpc::v1::GetTransactionRequest,
370 org::xrpl::rpc::v1::GetTransactionResponse>;
372 addToRequests(std::make_shared<cd>(
376 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
377 RequestGetTransaction,
384 org::xrpl::rpc::v1::SubmitTransactionRequest,
385 org::xrpl::rpc::v1::SubmitTransactionResponse>;
387 addToRequests(std::make_shared<cd>(
391 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
392 RequestSubmitTransaction,
400 org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest,
401 org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse>;
403 addToRequests(std::make_shared<cd>(
407 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
408 RequestGetAccountTransactionHistory,
425 grpc::ServerBuilder builder;
427 builder.AddListeningPort(
serverAddress_, grpc::InsecureServerCredentials());
433 cq_ = builder.AddCompletionQueue();
435 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.
static constexpr unsigned apiVersion
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)