xrpld
Loading...
Searching...
No Matches
GRPCServer.cpp
1#include <xrpld/app/main/GRPCServer.h>
2
3#include <xrpld/app/ledger/LedgerMaster.h> // IWYU pragma: keep
4#include <xrpld/app/main/Application.h>
5#include <xrpld/rpc/Context.h>
6#include <xrpld/rpc/GRPCHandlers.h>
7#include <xrpld/rpc/Role.h>
8#include <xrpld/rpc/detail/Handler.h>
9
10#include <xrpl/basics/FileUtilities.h>
11#include <xrpl/basics/Log.h>
12#include <xrpl/basics/StringUtilities.h>
13#include <xrpl/basics/contract.h>
14#include <xrpl/beast/core/CurrentThreadName.h>
15#include <xrpl/beast/net/IPAddressConversion.h>
16#include <xrpl/beast/net/IPEndpoint.h>
17#include <xrpl/beast/utility/instrumentation.h>
18#include <xrpl/config/BasicConfig.h>
19#include <xrpl/config/Constants.h>
20#include <xrpl/core/Job.h>
21#include <xrpl/core/JobQueue.h>
22#include <xrpl/protocol/ErrorCodes.h>
23#include <xrpl/resource/Charge.h>
24#include <xrpl/resource/Consumer.h>
25#include <xrpl/resource/Fees.h>
26#include <xrpl/server/InfoSub.h>
27
28#include <boost/asio/ip/address.hpp>
29#include <boost/asio/ip/tcp.hpp>
30#include <boost/icl/interval_set.hpp>
31
32#include <grpc/grpc_security_constants.h>
33#include <grpcpp/completion_queue.h>
34#include <grpcpp/security/server_credentials.h>
35#include <grpcpp/server_builder.h>
36#include <grpcpp/support/status.h>
37#include <org/xrpl/rpc/v1/get_ledger.pb.h>
38#include <org/xrpl/rpc/v1/get_ledger_data.pb.h>
39#include <org/xrpl/rpc/v1/get_ledger_diff.pb.h>
40#include <org/xrpl/rpc/v1/get_ledger_entry.pb.h>
41#include <org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
42
43#include <algorithm>
44#include <cstddef>
45#include <cstdint>
46#include <exception>
47#include <memory>
48#include <optional>
49#include <sstream>
50#include <stdexcept>
51#include <string>
52#include <system_error>
53#include <utility>
54#include <vector>
55
56namespace xrpl {
57
58namespace {
59
60// helper function. converts string to endpoint. handles ipv4 and ipv6, with or
61// without port, with or without prepended scheme
62std::optional<boost::asio::ip::tcp::endpoint>
63getEndpoint(std::string const& peer)
64{
65 try
66 {
67 std::size_t const first = peer.find_first_of(':');
68 std::size_t const last = peer.find_last_of(':');
69 std::string peerClean(peer);
70 if (first != last)
71 {
72 peerClean = peer.substr(first + 1);
73 }
74
75 std::optional<beast::ip::Endpoint> endpoint =
77 if (endpoint)
78 return beast::ip::toAsioEndpoint(endpoint.value());
79 }
80 catch (std::exception const&) // NOLINT(bugprone-empty-catch)
81 {
82 }
83 return {};
84}
85
86} // namespace
87
88template <class Request, class Response>
90 org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService& service,
91 grpc::ServerCompletionQueue& cq,
92 Application& app,
96 rpc::Condition requiredCondition,
97 resource::Charge loadType,
98 std::vector<boost::asio::ip::address> const& secureGatewayIPs)
99 : service_(service)
100 , cq_(cq)
101 , finished_(false)
102 , app_(app)
103 , responder_(&ctx_)
104 , bindListener_(std::move(bindListener))
105 , handler_(std::move(handler))
106 , forward_(std::move(forward))
107 , requiredCondition_(requiredCondition)
108 , loadType_(std::move(loadType))
109 , secureGatewayIPs_(secureGatewayIPs)
110{
111 // Bind a listener. When a request is received, "this" will be returned
112 // from CompletionQueue::Next
114}
115
116template <class Request, class Response>
131
132template <class Request, class Response>
133void
135{
136 // sanity check
137 BOOST_ASSERT(!finished_);
138
140
141 // Need to set finished to true before processing the response,
142 // because as soon as the response is posted to the completion
143 // queue (via responder_.Finish(...) or responder_.FinishWithError(...)),
144 // the CallData object is returned as a tag in handleRpcs().
145 // handleRpcs() checks the finished variable, and if true, destroys
146 // the object. Setting finished to true before calling process
147 // ensures that finished is always true when this CallData object
148 // is returned as a tag in handleRpcs(), after sending the response
149 finished_ = true;
150 auto const coro = app_.getJobQueue().postCoro(
151 JobType::JtRpc, "gRPC-Client", [thisShared](std::shared_ptr<JobQueue::Coro> coro) {
152 thisShared->process(coro);
153 });
154
155 // If coro is null, then the JobQueue has already been shutdown
156 if (!coro)
157 {
158 grpc::Status const status{grpc::StatusCode::INTERNAL, "Job Queue is already stopped"};
159 responder_.FinishWithError(status, this);
160 }
161}
162
163template <class Request, class Response>
164void
166{
167 try
168 {
169 auto usage = getUsage();
170 bool const isUnlimited = clientIsUnlimited();
171 if (!isUnlimited && usage.disconnect(app_.getJournal("gRPCServer")))
172 {
173 grpc::Status const status{
174 grpc::StatusCode::RESOURCE_EXHAUSTED, "usage balance exceeds threshold"};
175 responder_.FinishWithError(status, this);
176 }
177 else
178 {
179 auto loadType = getLoadType();
180 usage.charge(loadType);
181 auto role = getRole(isUnlimited);
182
183 {
184 std::stringstream toLog;
185 toLog << "role = " << (int)role;
186
187 toLog << " address = ";
188 if (auto clientIp = getClientIpAddress())
189 toLog << clientIp.value();
190
191 toLog << " user = ";
192 if (auto user = getUser())
193 toLog << user.value();
194 toLog << " isUnlimited = " << isUnlimited;
195
196 JLOG(app_.getJournal("GRPCServer::Calldata").debug()) << toLog.str();
197 }
198
200 {
201 app_.getJournal("gRPCServer"),
202 app_,
203 loadType,
204 app_.getOPs(),
205 app_.getLedgerMaster(),
206 usage,
207 role,
208 coro,
211 },
212 request_,
213 };
214
215 // Make sure we can currently handle the rpc
216 ErrorCodeI const conditionMetRes = rpc::conditionMet(requiredCondition_, context);
217
218 if (conditionMetRes != RpcSuccess)
219 {
220 rpc::ErrorInfo const errorInfo = rpc::getErrorInfo(conditionMetRes);
221 grpc::Status const status{
222 grpc::StatusCode::FAILED_PRECONDITION, errorInfo.message.cStr()};
223 responder_.FinishWithError(status, this);
224 }
225 else
226 {
229 responder_.Finish(result.first, result.second, this);
230 }
231 }
232 }
233 catch (std::exception const& ex)
234 {
235 grpc::Status const status{grpc::StatusCode::INTERNAL, ex.what()};
236 responder_.FinishWithError(status, this);
237 }
238}
239
240template <class Request, class Response>
241bool
246
247template <class Request, class Response>
253
254template <class Request, class Response>
255Role
257{
258 if (isUnlimited)
259 {
260 return Role::IDENTIFIED;
261 }
262
263 return Role::USER;
264}
265
266template <class Request, class Response>
269{
270 if (auto descriptor = Request::GetDescriptor()->FindFieldByName("user"))
271 {
272 std::string user = Request::GetReflection()->GetString(request_, descriptor);
273 if (!user.empty())
274 {
275 return user;
276 }
277 }
278 return {};
279}
280
281template <class Request, class Response>
284{
285 auto endpoint = getClientEndpoint();
286 if (endpoint)
287 return endpoint->address();
288 return {};
289}
290
291template <class Request, class Response>
294{
295 return xrpl::getEndpoint(ctx_.peer());
296}
297
298template <class Request, class Response>
299bool
301{
302 if (!getUser())
303 return false;
304 auto const clientIp = getClientIpAddress();
305 if (clientIp)
306 {
307 for (auto& ip : secureGatewayIPs_)
308 {
309 if (ip == clientIp)
310 return true;
311 }
312 }
313 return false;
314}
315
316template <class Request, class Response>
317void
319{
320 if (isUnlimited)
321 {
322 if (auto descriptor = Response::GetDescriptor()->FindFieldByName("is_unlimited"))
323 {
324 Response::GetReflection()->SetBool(&response, descriptor, true);
325 }
326 }
327}
328
329template <class Request, class Response>
332{
333 auto endpoint = getClientEndpoint();
334 if (endpoint)
335 return app_.getResourceManager().newInboundEndpoint(beast::ip::fromAsio(endpoint.value()));
336 Throw<std::runtime_error>("Failed to get client endpoint");
337}
338
340 : app_(app), journal_(app_.getJournal("gRPC Server"))
341{
342 // if present, get endpoint from config
343 if (app_.config().exists(Sections::kPortGrpc))
344 {
345 Section const& section = app_.config().section(Sections::kPortGrpc);
346
347 auto const optIp = section.get(Keys::kIp);
348 if (!optIp)
349 return;
350
351 auto const optPort = section.get(Keys::kPort);
352 if (!optPort)
353 return;
354 try
355 {
356 boost::asio::ip::tcp::endpoint const endpoint(
357 boost::asio::ip::make_address(*optIp), std::stoi(*optPort));
358
359 std::stringstream ss;
360 ss << endpoint;
361 serverAddress_ = ss.str();
362 }
363 catch (std::exception const&)
364 {
365 JLOG(journal_.error()) << "Error setting grpc server address";
366 Throw<std::runtime_error>("Error setting grpc server address");
367 }
368
369 auto const optSecureGateway = section.get(Keys::kSecureGateway);
370 if (optSecureGateway)
371 {
372 try
373 {
374 std::stringstream ss{*optSecureGateway};
375 std::string ip;
376 while (std::getline(ss, ip, ','))
377 {
378 ip = trimWhitespace(ip);
379 auto const addr = boost::asio::ip::make_address(ip);
380
381 if (addr.is_unspecified())
382 {
383 JLOG(journal_.error()) << "Can't pass unspecified IP in "
384 << "secure_gateway section of port_grpc";
385 Throw<std::runtime_error>("Unspecified IP in secure_gateway section");
386 }
387
388 secureGatewayIPs_.emplace_back(addr);
389 }
390 }
391 catch (std::exception const&)
392 {
393 JLOG(journal_.error()) << "Error parsing secure gateway IPs for grpc server";
394 Throw<std::runtime_error>("Error parsing secure_gateway section");
395 }
396 }
397
398 // Read TLS certificate configuration (optional)
399 sslCertPath_ = section.get(Keys::kSslCert);
400 sslKeyPath_ = section.get(Keys::kSslKey);
403
404 // If cert or key is specified, both must be specified
405 if (sslCertPath_.has_value() || sslKeyPath_.has_value())
406 {
407 if (!sslCertPath_.has_value() || !sslKeyPath_.has_value())
408 {
409 JLOG(journal_.error())
410 << "Both ssl_cert and ssl_key must be specified for gRPC TLS";
411 Throw<std::runtime_error>("Incomplete TLS configuration for gRPC");
412 }
413 JLOG(journal_.info()) << "gRPC TLS enabled with certificate: " << *sslCertPath_;
414 }
415
416 // Validate TLS configuration consistency: ssl_cert_chain only makes sense when TLS is
417 // enabled
418 if (sslCertChainPath_.has_value() &&
419 (!sslCertPath_.has_value() || !sslKeyPath_.has_value()))
420 {
421 JLOG(journal_.error())
422 << "ssl_cert_chain specified for gRPC without both ssl_cert and ssl_key; "
423 << "this is an invalid TLS configuration";
424 Throw<std::runtime_error>(
425 "Invalid gRPC TLS configuration: ssl_cert_chain requires both ssl_cert and "
426 "ssl_key");
427 }
428
429 // Validate TLS configuration consistency: ssl_client_ca only makes sense when TLS is
430 // enabled
431 if (sslClientCAPath_.has_value() && (!sslCertPath_.has_value() || !sslKeyPath_.has_value()))
432 {
433 JLOG(journal_.error())
434 << "ssl_client_ca specified for gRPC without both ssl_cert and ssl_key; "
435 << "this is an invalid TLS configuration";
436 Throw<std::runtime_error>(
437 "Invalid gRPC TLS configuration: ssl_client_ca requires both ssl_cert and ssl_key");
438 }
439 }
440}
441
442void
444{
445 JLOG(journal_.debug()) << "Shutting down";
446
447 // The below call cancels all "listeners" (CallData objects that are waiting
448 // for a request, as opposed to processing a request), and blocks until all
449 // requests being processed are completed. CallData objects in the midst of
450 // processing requests need to actually send data back to the client, via
451 // responder_.Finish(...) or responder_.FinishWithError(...), for this call
452 // to unblock. Each cancelled listener is returned via cq_.Next(...) with ok
453 // set to false
454 server_->Shutdown();
455 JLOG(journal_.debug()) << "Server has been shutdown";
456
457 // Always shutdown the completion queue after the server. This call allows
458 // cq_.Next() to return false, once all events posted to the completion
459 // queue have been processed. See handleRpcs() for more details.
460 cq_->Shutdown();
461 JLOG(journal_.debug()) << "Completion Queue has been shutdown";
462}
463
464void
466{
467 // This collection should really be an unordered_set. However, to delete
468 // from the unordered_set, we need a shared_ptr, but cq_.Next() (see below
469 // while loop) sets the tag to a raw pointer.
471
472 auto const erase = [&requests](Processor* ptr) {
473 auto const it = std::ranges::find_if(
474 requests, [ptr](std::shared_ptr<Processor>& sPtr) { return sPtr.get() == ptr; });
475 BOOST_ASSERT(it != requests.end());
476 it->swap(requests.back());
477 requests.pop_back();
478 };
479
480 void* tag = nullptr; // uniquely identifies a request.
481 bool ok = false;
482 // Block waiting to read the next event from the completion queue. The
483 // event is uniquely identified by its tag, which in this case is the
484 // memory address of a CallData instance.
485 // The return value of Next should always be checked. This return value
486 // tells us whether there is any kind of event or cq_ is shutting down.
487 // When cq_.Next(...) returns false, all work has been completed and the
488 // loop can exit. When the server is shutdown, each CallData object that is
489 // listening for a request is forcibly cancelled, and is returned by
490 // cq_->Next() with ok set to false. Then, each CallData object processing
491 // a request must complete (by sending data to the client), each of which
492 // will be returned from cq_->Next() with ok set to true. After all
493 // cancelled listeners and all CallData objects processing requests are
494 // returned via cq_->Next(), cq_->Next() will return false, causing the
495 // loop to exit.
496 while (cq_->Next(&tag, &ok))
497 {
498 auto ptr = static_cast<Processor*>(tag);
499 JLOG(journal_.trace()) << "Processing CallData object."
500 << " ptr = " << ptr << " ok = " << ok;
501
502 if (!ok)
503 {
504 JLOG(journal_.debug()) << "Request listener cancelled. "
505 << "Destroying object";
506 erase(ptr);
507 }
508 else
509 {
510 if (!ptr->isFinished())
511 {
512 JLOG(journal_.debug()) << "Received new request. Processing";
513 // ptr is now processing a request, so create a new CallData
514 // object to handle additional requests
515 auto const cloned = ptr->clone();
516 requests.push_back(cloned);
517 // process the request
518 ptr->process();
519 }
520 else
521 {
522 JLOG(journal_.debug()) << "Sent response. Destroying object";
523 erase(ptr);
524 }
525 }
526 }
527 JLOG(journal_.debug()) << "Completion Queue drained";
528}
529
530// create a CallData instance for each RPC
533{
534 using rpc::Condition;
536
537 auto const addToRequests = [&requests](auto callData) {
538 requests.push_back(std::move(callData));
539 };
540
541 {
542 using Cd =
544
545 addToRequests(
547 service_,
548 *cq_,
549 app_,
550 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::RequestGetLedger,
552 &org::xrpl::rpc::v1::XRPLedgerAPIService::Stub::GetLedger,
553 Condition::NoCondition,
556 }
557 {
558 using Cd = CallData<
559 org::xrpl::rpc::v1::GetLedgerDataRequest,
560 org::xrpl::rpc::v1::GetLedgerDataResponse>;
561
562 addToRequests(
564 service_,
565 *cq_,
566 app_,
567 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::RequestGetLedgerData,
569 &org::xrpl::rpc::v1::XRPLedgerAPIService::Stub::GetLedgerData,
570 Condition::NoCondition,
573 }
574 {
575 using Cd = CallData<
576 org::xrpl::rpc::v1::GetLedgerDiffRequest,
577 org::xrpl::rpc::v1::GetLedgerDiffResponse>;
578
579 addToRequests(
581 service_,
582 *cq_,
583 app_,
584 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::RequestGetLedgerDiff,
586 &org::xrpl::rpc::v1::XRPLedgerAPIService::Stub::GetLedgerDiff,
587 Condition::NoCondition,
590 }
591 {
592 using Cd = CallData<
593 org::xrpl::rpc::v1::GetLedgerEntryRequest,
594 org::xrpl::rpc::v1::GetLedgerEntryResponse>;
595
596 addToRequests(
598 service_,
599 *cq_,
600 app_,
601 &org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService::RequestGetLedgerEntry,
603 &org::xrpl::rpc::v1::XRPLedgerAPIService::Stub::GetLedgerEntry,
604 Condition::NoCondition,
607 }
608 return requests;
609}
610
613{
614 if (not sslCertPath_.has_value() or not sslKeyPath_.has_value())
615 {
616 JLOG(journal_.info()) << "Configuring gRPC server without TLS";
617 return grpc::InsecureServerCredentials();
618 }
619
620 JLOG(journal_.info()) << "Configuring gRPC server with TLS";
621
622 try
623 {
625 grpc::SslServerCredentialsOptions sslOpts;
626 grpc::SslServerCredentialsOptions::PemKeyCertPair keyCertPair;
627
628 std::string const certContents = getFileContents(ec, *sslCertPath_);
629 if (ec)
630 {
631 JLOG(journal_.error()) << "Failed to read gRPC SSL certificate file: " << *sslCertPath_
632 << " - " << ec.message(); // LCOV_EXCL_LINE
633 return nullptr;
634 }
635
636 std::string const keyContents = getFileContents(ec, *sslKeyPath_);
637 if (ec)
638 {
639 JLOG(journal_.error()) << "Failed to read gRPC SSL key file: " << *sslKeyPath_ << " - "
640 << ec.message(); // LCOV_EXCL_LINE
641 return nullptr;
642 }
643
644 keyCertPair.private_key = keyContents;
645
646 // Read intermediate CA certificates for server certificate chain (optional)
647 std::string certChainContents;
648 if (sslCertChainPath_.has_value())
649 {
650 certChainContents = getFileContents(ec, *sslCertChainPath_);
651 if (ec)
652 {
653 JLOG(journal_.error())
654 << "Failed to read gRPC SSL cert chain file: " << *sslCertChainPath_ << " - "
655 << ec.message(); // LCOV_EXCL_LINE
656 return nullptr;
657 }
658 }
659
660 // Read CA certificate for client verification (mTLS, optional)
661 if (sslClientCAPath_.has_value())
662 {
663 auto const clientCAContents = getFileContents(ec, *sslClientCAPath_);
664 if (ec)
665 {
666 JLOG(journal_.error())
667 << "Failed to read gRPC SSL client CA file: " << *sslClientCAPath_ << " - "
668 << ec.message(); // LCOV_EXCL_LINE
669 return nullptr;
670 }
671
672 if (clientCAContents.empty())
673 {
674 JLOG(journal_.error())
675 << "Empty/truncated gRPC SSL client CA file: " << *sslClientCAPath_
676 << " - failed to configure mutual TLS"; // LCOV_EXCL_LINE
677 return nullptr;
678 }
679
680 sslOpts.pem_root_certs = clientCAContents;
681 sslOpts.client_certificate_request =
682 GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY;
683 JLOG(journal_.info()) << "gRPC mutual TLS enabled - client certificates will be "
684 "required and verified";
685 }
686
687 // Combine server cert with intermediate CA certs for complete chain
688 keyCertPair.cert_chain = certContents;
689 if (!certChainContents.empty())
690 {
691 keyCertPair.cert_chain += '\n' + certChainContents;
692 JLOG(journal_.info()) << "gRPC server certificate chain configured with "
693 "intermediate CA certificates"; // LCOV_EXCL_LINE
694 }
695
696 sslOpts.pem_key_cert_pairs.push_back(keyCertPair);
697
698 JLOG(journal_.info()) << "gRPC TLS credentials configured successfully"; // LCOV_EXCL_LINE
699 return grpc::SslServerCredentials(sslOpts);
700 }
701 catch (std::exception const& e)
702 {
703 JLOG(journal_.error()) << "Exception while configuring gRPC TLS: "
704 << e.what(); // LCOV_EXCL_LINE
705 return nullptr;
706 }
707}
708
709bool
711{
712 // if config does not specify a grpc server address, don't start
713 if (serverAddress_.empty())
714 return false;
715
716 // Determine TLS mode for logging
717 bool const tlsEnabled = sslCertPath_.has_value() && sslKeyPath_.has_value();
718 bool const mtlsEnabled = tlsEnabled && sslClientCAPath_.has_value();
719
720 std::string tlsMode = "without TLS";
721 if (mtlsEnabled)
722 {
723 tlsMode = "with mutual TLS (mTLS)";
724 }
725 else if (tlsEnabled)
726 {
727 tlsMode = "with TLS";
728 }
729
730 JLOG(journal_.info()) << "Starting gRPC server at " << serverAddress_ << " "
731 << tlsMode; // LCOV_EXCL_LINE
732
733 grpc::ServerBuilder builder;
734 int port = 0;
735
736 // Create credentials (TLS or insecure) based on configuration
738 if (!credentials)
739 {
740 JLOG(journal_.error()) << "Failed to create gRPC server credentials for " << serverAddress_
741 << " (TLS mode: " << tlsMode
742 << ") - server will not start"; // LCOV_EXCL_LINE
743 return false;
744 }
745
746 // Add listening port with appropriate credentials
747 builder.AddListeningPort(serverAddress_, credentials, &port);
748
749 // Register "service_" as the instance through which we'll communicate with
750 // clients. In this case it corresponds to an *asynchronous* service.
751 builder.RegisterService(&service_);
752
753 // Get hold of the completion queue used for the asynchronous communication
754 // with the gRPC runtime.
755 cq_ = builder.AddCompletionQueue();
756
757 // Finally assemble the server.
758 server_ = builder.BuildAndStart();
759 serverPort_ = static_cast<std::uint16_t>(port);
760
761 if (serverPort_ != 0u)
762 {
763 JLOG(journal_.info()) << "gRPC server started successfully on port " << serverPort_;
764 }
765 else
766 {
767 JLOG(journal_.error())
768 << "Failed to start gRPC server at " << serverAddress_ << " (TLS mode: " << tlsMode
769 << "); Possible causes: address already in use, invalid address format, or permission "
770 "denied"; // LCOV_EXCL_LINE
771 }
772
773 return static_cast<bool>(serverPort_);
774}
775
776boost::asio::ip::tcp::endpoint
778{
779 std::string const addr = serverAddress_.substr(0, serverAddress_.find_last_of(':'));
780 return boost::asio::ip::tcp::endpoint(boost::asio::ip::make_address(addr), serverPort_);
781}
782
783bool
785{
786 // Start the server and setup listeners
787 if (running_ = impl_.start(); running_)
788 {
789 thread_ = std::thread([this] {
790 // Start the event loop and begin handling requests
791 beast::setCurrentThreadName("xrpld: grpc");
792 this->impl_.handleRpcs();
793 });
794 }
795 return running_;
796}
797
798void
800{
801 if (running_)
802 {
803 impl_.shutdown();
804 thread_.join();
805 running_ = false;
806 }
807}
808
810{
811 XRPL_ASSERT(!running_, "xrpl::GRPCServer::~GRPCServer : is not running");
812}
813
814boost::asio::ip::tcp::endpoint
816{
817 return impl_.getEndpoint();
818}
819
820} // namespace xrpl
T back(T... args)
static std::optional< Endpoint > fromStringChecked(std::string const &s)
Create an Endpoint from a string.
constexpr char const * cStr() const
Definition json_value.h:65
Forward< Request, Response > forward_
Definition GRPCServer.h:189
std::vector< boost::asio::ip::address > const & secureGatewayIPs_
Definition GRPCServer.h:197
std::optional< boost::asio::ip::address > getClientIpAddress()
org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService & service_
Definition GRPCServer.h:157
Handler< Request, Response > handler_
Definition GRPCServer.h:186
std::optional< std::string > getUser()
BindListener< Request, Response > bindListener_
Definition GRPCServer.h:183
Role getRole(bool isUnlimited)
resource::Consumer getUsage()
std::optional< boost::asio::ip::tcp::endpoint > getClientEndpoint()
resource::Charge getLoadType()
CallData(org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService &service, grpc::ServerCompletionQueue &cq, Application &app, BindListener< Request, Response > bindListener, Handler< Request, Response > handler, Forward< Request, Response > forward, rpc::Condition requiredCondition, resource::Charge loadType, std::vector< boost::asio::ip::address > const &secureGatewayIPs)
grpc::ServerAsyncResponseWriter< Response > responder_
Definition GRPCServer.h:180
std::shared_ptr< Processor > clone() override
void setIsUnlimited(Response &response, bool isUnlimited)
grpc::ServerCompletionQueue & cq_
Definition GRPCServer.h:160
rpc::Condition requiredCondition_
Definition GRPCServer.h:192
grpc::ServerContext ctx_
Definition GRPCServer.h:165
std::uint16_t serverPort_
Definition GRPCServer.h:76
Application & app_
Definition GRPCServer.h:73
std::optional< std::string > sslKeyPath_
Definition GRPCServer.h:82
std::optional< std::string > sslCertPath_
Definition GRPCServer.h:81
std::function< grpc::Status( org::xrpl::rpc::v1::XRPLedgerAPIService::Stub *, grpc::ClientContext *, Request, Response *)> Forward
Definition GRPCServer.h:110
std::vector< boost::asio::ip::address > secureGatewayIPs_
Definition GRPCServer.h:78
std::optional< std::string > sslCertChainPath_
Definition GRPCServer.h:83
std::unique_ptr< grpc::ServerCompletionQueue > cq_
Definition GRPCServer.h:64
std::vector< std::shared_ptr< Processor > > setupListeners()
std::optional< std::string > sslClientCAPath_
Definition GRPCServer.h:85
GRPCServerImpl(Application &app)
beast::Journal journal_
Definition GRPCServer.h:87
std::function< std::pair< Response, grpc::Status >(rpc::GRPCContext< Request > &)> Handler
Definition GRPCServer.h:105
std::unique_ptr< grpc::Server > server_
Definition GRPCServer.h:71
boost::asio::ip::tcp::endpoint getEndpoint() const
std::string serverAddress_
Definition GRPCServer.h:75
org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService service_
Definition GRPCServer.h:69
std::function< void( org::xrpl::rpc::v1::XRPLedgerAPIService::AsyncService &, grpc::ServerContext *, Request *, grpc::ServerAsyncResponseWriter< Response > *, grpc::CompletionQueue *, grpc::ServerCompletionQueue *, void *)> BindListener
Definition GRPCServer.h:93
static constexpr unsigned kApiVersion
Definition GRPCServer.h:107
std::shared_ptr< grpc::ServerCredentials > createServerCredentials()
std::thread thread_
Definition GRPCServer.h:324
boost::asio::ip::tcp::endpoint getEndpoint() const
GRPCServerImpl impl_
Definition GRPCServer.h:323
std::shared_ptr< InfoSub > pointer
Definition InfoSub.h:92
A consumption charge.
Definition Charge.h:13
An endpoint that consumes resources.
Definition Consumer.h:20
T empty(T... args)
T end(T... args)
T find_first_of(T... args)
T find_if(T... args)
T find_last_of(T... args)
T get(T... args)
T getline(T... args)
T make_shared(T... args)
T message(T... args)
boost::asio::ip::tcp::endpoint toAsioEndpoint(Endpoint const &endpoint)
Convert to asio::ip::tcp::endpoint.
Endpoint fromAsio(boost::asio::ip::address const &address)
Convert to Endpoint.
void setCurrentThreadName(std::string_view newThreadName)
Changes the name of the caller thread.
STL namespace.
Charge const kFeeMediumBurdenRpc
ErrorCodeI conditionMet(Condition conditionRequired, T &context)
Definition Handler.h:140
ErrorInfo const & getErrorInfo(ErrorCodeI code)
Returns an ErrorInfo that reflects the error code.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
ErrorCodeI
Definition ErrorCodes.h:23
@ RpcSuccess
Definition ErrorCodes.h:27
std::pair< org::xrpl::rpc::v1::GetLedgerEntryResponse, grpc::Status > doLedgerEntryGrpc(rpc::GRPCContext< org::xrpl::rpc::v1::GetLedgerEntryRequest > const &context)
std::pair< org::xrpl::rpc::v1::GetLedgerDiffResponse, grpc::Status > doLedgerDiffGrpc(rpc::GRPCContext< org::xrpl::rpc::v1::GetLedgerDiffRequest > const &context)
std::string trimWhitespace(std::string str)
Remove leading and trailing ASCII whitespace.
Role
Indicates the level of administrative permission to grant.
Definition Role.h:27
@ IDENTIFIED
Definition Role.h:27
@ USER
Definition Role.h:27
@ JtRpc
Definition Job.h:38
std::string getFileContents(std::error_code &ec, std::filesystem::path const &sourcePath, std::optional< std::size_t > maxSize=std::nullopt)
std::pair< org::xrpl::rpc::v1::GetLedgerResponse, grpc::Status > doLedgerGrpc(rpc::GRPCContext< org::xrpl::rpc::v1::GetLedgerRequest > &context)
std::pair< org::xrpl::rpc::v1::GetLedgerDataResponse, grpc::Status > doLedgerDataGrpc(rpc::GRPCContext< org::xrpl::rpc::v1::GetLedgerDataRequest > const &context)
void erase(STObject &st, TypedField< U > const &f)
Remove a field in an STObject.
Definition STExchange.h:161
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
Definition Role.cpp:115
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52
T pop_back(T... args)
T push_back(T... args)
T str(T... args)
static constexpr auto kSslCertChain
Definition Constants.h:165
static constexpr auto kSslKey
Definition Constants.h:169
static constexpr auto kSslClientCa
Definition Constants.h:168
static constexpr auto kSslCert
Definition Constants.h:164
static constexpr auto kSecureGateway
Definition Constants.h:158
static constexpr auto kPortGrpc
Definition Constants.h:45
Maps an rpc error code to its token, default message, and HTTP status.
Definition ErrorCodes.h:176
json::StaticString message
Definition ErrorCodes.h:195
T substr(T... args)
T value(T... args)
T what(T... args)