Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
GrpcSource.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "etlng/InitialLoadObserverInterface.hpp"
24#include "util/log/Logger.hpp"
25
26#include <boost/asio/spawn.hpp>
27#include <grpcpp/support/status.h>
28#include <org/xrpl/rpc/v1/get_ledger.pb.h>
29#include <xrpl/proto/org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h>
30
31#include <atomic>
32#include <chrono>
33#include <cstdint>
34#include <memory>
35#include <string>
36#include <utility>
37
38namespace etlng::impl {
39
40class GrpcSource {
41 util::Logger log_;
42 std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> stub_;
43 std::unique_ptr<std::atomic_bool> initialLoadShouldStop_;
44 std::chrono::system_clock::duration deadline_;
45
46 static constexpr auto kKEEPALIVE_PING_INTERVAL_MS = 10000;
47 static constexpr auto kKEEPALIVE_TIMEOUT_MS = 5000;
48 static constexpr auto kKEEPALIVE_PERMIT_WITHOUT_CALLS = true; // Allow keepalive pings when no calls
49 static constexpr auto kMAX_PINGS_WITHOUT_DATA = 0; // No limit
50 static constexpr auto kDEADLINE = std::chrono::seconds(30);
51
52public:
53 GrpcSource(
54 std::string const& ip,
55 std::string const& grpcPort,
56 std::chrono::system_clock::duration deadline = kDEADLINE
57 );
58
70 std::pair<grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse>
71 fetchLedger(uint32_t sequence, bool getObjects = true, bool getObjectNeighbors = false);
72
82 loadInitialLedger(uint32_t sequence, uint32_t numMarkers, etlng::InitialLoadObserverInterface& observer);
83
89 void
90 stop(boost::asio::yield_context yield);
91};
92
93} // namespace etlng::impl
std::expected< std::vector< std::string >, InitialLedgerLoadError > InitialLedgerLoadResult
The result type of the initial ledger load.
Definition LoadBalancerInterface.hpp:54
std::pair< grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse > fetchLedger(uint32_t sequence, bool getObjects=true, bool getObjectNeighbors=false)
Fetch data for a specific ledger.
Definition GrpcSource.cpp:92
InitialLedgerLoadResult loadInitialLedger(uint32_t sequence, uint32_t numMarkers, etlng::InitialLoadObserverInterface &observer)
Download a ledger in full.
Definition GrpcSource.cpp:121
void stop(boost::asio::yield_context yield)
Stop any ongoing operations.
Definition GrpcSource.cpp:178
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:94
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36