20 #include <ripple/app/main/GRPCServer.h>
21 #include <ripple/beast/core/CurrentThreadName.h>
22 #include <ripple/resource/Fees.h>
37 peerClean = peer.
substr(first + 1);
43 template <
class Request,
class Response>
45 org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService& service,
46 grpc::ServerCompletionQueue& cq,
57 , bindListener_(
std::move(bindListener))
58 , handler_(
std::move(handler))
59 , requiredCondition_(
std::move(requiredCondition))
60 , loadType_(
std::move(loadType))
67 template <
class Request,
class Response>
71 return std::make_shared<CallData<Request, Response>>(
81 template <
class Request,
class Response>
86 BOOST_ASSERT(!finished_);
89 this->shared_from_this();
104 thisShared->process(coro);
111 grpc::StatusCode::INTERNAL,
"Job Queue is already stopped"};
112 responder_.FinishWithError(status,
this);
116 template <
class Request,
class Response>
123 auto usage = getUsage();
124 if (usage.disconnect())
127 grpc::StatusCode::RESOURCE_EXHAUSTED,
128 "usage balance exceeds threshhold"};
129 responder_.FinishWithError(status,
this);
133 auto loadType = getLoadType();
134 usage.charge(loadType);
135 auto role = getRole();
158 grpc::StatusCode::FAILED_PRECONDITION,
160 responder_.FinishWithError(status,
this);
165 responder_.Finish(result.
first, result.
second,
this);
171 grpc::Status status{grpc::StatusCode::INTERNAL, ex.
what()};
172 responder_.FinishWithError(status,
this);
176 template <
class Request,
class Response>
183 template <
class Request,
class Response>
190 template <
class Request,
class Response>
197 template <
class Request,
class Response>
202 boost::optional<beast::IP::Endpoint> endpoint =
225 boost::asio::ip::make_address(ipPair.
first),
255 JLOG(
journal_.
debug()) <<
"Completion Queue has been shutdown";
271 return sPtr.get() == ptr;
273 BOOST_ASSERT(it != requests.
end());
274 it->swap(requests.
back());
294 while (
cq_->Next(&tag, &ok))
298 <<
" ptr = " << ptr <<
" ok = " << ok;
303 <<
"Destroying object";
308 if (!ptr->isFinished())
310 JLOG(
journal_.
debug()) <<
"Received new request. Processing";
313 auto cloned = ptr->clone();
320 JLOG(
journal_.
debug()) <<
"Sent response. Destroying object";
334 auto addToRequests = [&requests](
auto callData) {
340 org::xrpl::rpc::v1::GetFeeRequest,
341 org::xrpl::rpc::v1::GetFeeResponse>;
343 addToRequests(std::make_shared<cd>(
347 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
355 org::xrpl::rpc::v1::GetAccountInfoRequest,
356 org::xrpl::rpc::v1::GetAccountInfoResponse>;
358 addToRequests(std::make_shared<cd>(
362 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
363 RequestGetAccountInfo,
370 org::xrpl::rpc::v1::GetTransactionRequest,
371 org::xrpl::rpc::v1::GetTransactionResponse>;
373 addToRequests(std::make_shared<cd>(
377 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
378 RequestGetTransaction,
385 org::xrpl::rpc::v1::SubmitTransactionRequest,
386 org::xrpl::rpc::v1::SubmitTransactionResponse>;
388 addToRequests(std::make_shared<cd>(
392 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
393 RequestSubmitTransaction,
401 org::xrpl::rpc::v1::GetAccountTransactionHistoryRequest,
402 org::xrpl::rpc::v1::GetAccountTransactionHistoryResponse>;
404 addToRequests(std::make_shared<cd>(
408 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::
409 RequestGetAccountTransactionHistory,
426 grpc::ServerBuilder builder;
428 builder.AddListeningPort(
serverAddress_, grpc::InsecureServerCredentials());
434 cq_ = builder.AddCompletionQueue();
436 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.
void onStart() override
Override called during start.
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.
void stopped()
Called by derived classes to indicate that the stoppable has stopped.
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
void setCurrentThreadName(std::string_view name)
Changes the name of the caller thread.
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)
void onStop() override
Override called when the stop notification is issued.
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)