rippled
Public Member Functions | Private Attributes | List of all members
ripple::ETLSource Class Reference

This class manages a connection to a single ETL source. More...

Collaboration diagram for ripple::ETLSource:
Collaboration graph
[legend]

Public Member Functions

bool isConnected () const
 
std::chrono::system_clock::time_point getLastMsgTime () const
 
void setLastMsgTime ()
 
 ETLSource (std::string ip, std::string wsPort, ReportingETL &etl)
 Create ETL source without gRPC endpoint Fetch ledger and load initial ledger will fail for this source Primarly used in read-only mode, to monitor when ledgers are validated. More...
 
 ETLSource (std::string ip, std::string wsPort, std::string grpcPort, ReportingETL &etl)
 Create ETL source with gRPC endpoint. More...
 
bool hasLedger (uint32_t sequence) const
 
void setValidatedRange (std::string const &range)
 process the validated range received on the ledgers stream. More...
 
std::string getValidatedRange () const
 
void stop ()
 Close the underlying websocket. More...
 
std::pair< grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse > fetchLedger (uint32_t ledgerSequence, bool getObjects=true)
 Fetch the specified ledger. More...
 
std::string toString () const
 
Json::Value toJson () const
 
bool loadInitialLedger (uint32_t ledgerSequence, ThreadSafeQueue< std::shared_ptr< SLE >> &writeQueue)
 Download a ledger in full. More...
 
void start ()
 Begin sequence of operations to connect to the ETL source and subscribe to ledgers and transactions_proposed. More...
 
void reconnect (boost::beast::error_code ec)
 Attempt to reconnect to the ETL source. More...
 
void onResolve (boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type results)
 Callback. More...
 
void onConnect (boost::beast::error_code ec, boost::asio::ip::tcp::resolver::results_type::endpoint_type endpoint)
 Callback. More...
 
void onHandshake (boost::beast::error_code ec)
 Callback. More...
 
void onWrite (boost::beast::error_code ec, size_t size)
 Callback. More...
 
void onRead (boost::beast::error_code ec, size_t size)
 Callback. More...
 
bool handleMessage ()
 Handle the most recently received message. More...
 
void close (bool startAgain)
 Close the websocket. More...
 
std::unique_ptr< org::xrpl::rpc::v1::XRPLedgerAPIService::Stub > getP2pForwardingStub () const
 Get grpc stub to forward requests to p2p node. More...
 
Json::Value forwardToP2p (RPC::JsonContext &context) const
 Forward a JSON RPC request to a p2p node. More...
 

Private Attributes

std::string ip_
 
std::string wsPort_
 
std::string grpcPort_
 
ReportingETLetl_
 
boost::asio::io_context & ioc_
 
std::unique_ptr< org::xrpl::rpc::v1::XRPLedgerAPIService::Stub > stub_
 
std::unique_ptr< boost::beast::websocket::stream< boost::beast::tcp_stream > > ws_
 
boost::asio::ip::tcp::resolver resolver_
 
boost::beast::flat_buffer readBuffer_
 
std::vector< std::pair< uint32_t, uint32_t > > validatedLedgers_
 
std::string validatedLedgersRaw_
 
NetworkValidatedLedgersnetworkValidatedLedgers_
 
beast::Journal journal_
 
Applicationapp_
 
std::mutex mtx_
 
size_t numFailures_ = 0
 
std::atomic_bool closing_ = false
 
std::atomic_bool connected_ = false
 
std::atomic_bool forwardingStream_ = false
 
std::chrono::system_clock::time_point lastMsgTime_
 
std::mutex lastMsgTimeMtx_
 
boost::asio::steady_timer timer_
 

Detailed Description

This class manages a connection to a single ETL source.

This is almost always a p2p node, but really could be another reporting node. This class subscribes to the ledgers and transactions_proposed streams of the associated p2p node, and keeps track of which ledgers the p2p node has. This class also has methods for extracting said ledgers. Lastly this class forwards transactions received on the transactions_proposed streams to any subscribers.

Definition at line 46 of file ETLSource.h.

Constructor & Destructor Documentation

◆ ETLSource() [1/2]

ripple::ETLSource::ETLSource ( std::string  ip,
std::string  wsPort,
ReportingETL etl 
)

Create ETL source without gRPC endpoint Fetch ledger and load initial ledger will fail for this source Primarly used in read-only mode, to monitor when ledgers are validated.

Definition at line 31 of file ETLSource.cpp.

◆ ETLSource() [2/2]

ripple::ETLSource::ETLSource ( std::string  ip,
std::string  wsPort,
std::string  grpcPort,
ReportingETL etl 
)

Create ETL source with gRPC endpoint.

Definition at line 47 of file ETLSource.cpp.

Member Function Documentation

◆ isConnected()

bool ripple::ETLSource::isConnected ( ) const

Definition at line 100 of file ETLSource.h.

◆ getLastMsgTime()

std::chrono::system_clock::time_point ripple::ETLSource::getLastMsgTime ( ) const

Definition at line 106 of file ETLSource.h.

◆ setLastMsgTime()

void ripple::ETLSource::setLastMsgTime ( )

Definition at line 113 of file ETLSource.h.

◆ hasLedger()

bool ripple::ETLSource::hasLedger ( uint32_t  sequence) const
Parameters
sequenceledger sequence to check for
Returns
true if this source has the desired ledger

Definition at line 134 of file ETLSource.h.

◆ setValidatedRange()

void ripple::ETLSource::setValidatedRange ( std::string const &  range)

process the validated range received on the ledgers stream.

set the appropriate member variable

Parameters
rangevalidated range received on ledgers stream

Definition at line 158 of file ETLSource.h.

◆ getValidatedRange()

std::string ripple::ETLSource::getValidatedRange ( ) const
Returns
the validated range of this source
Note
this is only used by server_info

Definition at line 195 of file ETLSource.h.

◆ stop()

void ripple::ETLSource::stop ( )

Close the underlying websocket.

Definition at line 204 of file ETLSource.h.

◆ fetchLedger()

std::pair< grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse > ripple::ETLSource::fetchLedger ( uint32_t  ledgerSequence,
bool  getObjects = true 
)

Fetch the specified ledger.

Parameters
ledgerSequencesequence of the ledger to fetch @getObjects whether to get the account state diff between this ledger and the prior one
Returns
the extracted data and the result status

Definition at line 624 of file ETLSource.cpp.

◆ toString()

std::string ripple::ETLSource::toString ( ) const

Definition at line 222 of file ETLSource.h.

◆ toJson()

Json::Value ripple::ETLSource::toJson ( ) const

Definition at line 230 of file ETLSource.h.

◆ loadInitialLedger()

bool ripple::ETLSource::loadInitialLedger ( uint32_t  ledgerSequence,
ThreadSafeQueue< std::shared_ptr< SLE >> &  writeQueue 
)

Download a ledger in full.

Parameters
ledgerSequencesequence of the ledger to download
writeQueuequeue to push downloaded ledger objects
Returns
true if the download was successful

Definition at line 557 of file ETLSource.cpp.

◆ start()

void ripple::ETLSource::start ( )

Begin sequence of operations to connect to the ETL source and subscribe to ledgers and transactions_proposed.

Definition at line 170 of file ETLSource.cpp.

◆ reconnect()

void ripple::ETLSource::reconnect ( boost::beast::error_code  ec)

Attempt to reconnect to the ETL source.

Definition at line 98 of file ETLSource.cpp.

◆ onResolve()

void ripple::ETLSource::onResolve ( boost::beast::error_code  ec,
boost::asio::ip::tcp::resolver::results_type  results 
)

Callback.

Definition at line 182 of file ETLSource.cpp.

◆ onConnect()

void ripple::ETLSource::onConnect ( boost::beast::error_code  ec,
boost::asio::ip::tcp::resolver::results_type::endpoint_type  endpoint 
)

Callback.

Definition at line 203 of file ETLSource.cpp.

◆ onHandshake()

void ripple::ETLSource::onHandshake ( boost::beast::error_code  ec)

Callback.

Definition at line 245 of file ETLSource.cpp.

◆ onWrite()

void ripple::ETLSource::onWrite ( boost::beast::error_code  ec,
size_t  size 
)

Callback.

Definition at line 279 of file ETLSource.cpp.

◆ onRead()

void ripple::ETLSource::onRead ( boost::beast::error_code  ec,
size_t  size 
)

Callback.

Definition at line 296 of file ETLSource.cpp.

◆ handleMessage()

bool ripple::ETLSource::handleMessage ( )

Handle the most recently received message.

Returns
true if the message was handled successfully. false on error

Definition at line 319 of file ETLSource.cpp.

◆ close()

void ripple::ETLSource::close ( bool  startAgain)

Close the websocket.

Parameters
startAgainwhether to reconnect

Definition at line 135 of file ETLSource.cpp.

◆ getP2pForwardingStub()

std::unique_ptr< org::xrpl::rpc::v1::XRPLedgerAPIService::Stub > ripple::ETLSource::getP2pForwardingStub ( ) const

Get grpc stub to forward requests to p2p node.

Returns
stub to send requests to ETL source

Definition at line 791 of file ETLSource.cpp.

◆ forwardToP2p()

Json::Value ripple::ETLSource::forwardToP2p ( RPC::JsonContext context) const

Forward a JSON RPC request to a p2p node.

Parameters
contextcontext of RPC request
Returns
response received from ETL source

Definition at line 812 of file ETLSource.cpp.

Member Data Documentation

◆ ip_

std::string ripple::ETLSource::ip_
private

Definition at line 48 of file ETLSource.h.

◆ wsPort_

std::string ripple::ETLSource::wsPort_
private

Definition at line 50 of file ETLSource.h.

◆ grpcPort_

std::string ripple::ETLSource::grpcPort_
private

Definition at line 52 of file ETLSource.h.

◆ etl_

ReportingETL& ripple::ETLSource::etl_
private

Definition at line 54 of file ETLSource.h.

◆ ioc_

boost::asio::io_context& ripple::ETLSource::ioc_
private

Definition at line 57 of file ETLSource.h.

◆ stub_

std::unique_ptr<org::xrpl::rpc::v1::XRPLedgerAPIService::Stub> ripple::ETLSource::stub_
private

Definition at line 59 of file ETLSource.h.

◆ ws_

std::unique_ptr<boost::beast::websocket::stream<boost::beast::tcp_stream> > ripple::ETLSource::ws_
private

Definition at line 62 of file ETLSource.h.

◆ resolver_

boost::asio::ip::tcp::resolver ripple::ETLSource::resolver_
private

Definition at line 63 of file ETLSource.h.

◆ readBuffer_

boost::beast::flat_buffer ripple::ETLSource::readBuffer_
private

Definition at line 65 of file ETLSource.h.

◆ validatedLedgers_

std::vector<std::pair<uint32_t, uint32_t> > ripple::ETLSource::validatedLedgers_
private

Definition at line 67 of file ETLSource.h.

◆ validatedLedgersRaw_

std::string ripple::ETLSource::validatedLedgersRaw_
private

Definition at line 69 of file ETLSource.h.

◆ networkValidatedLedgers_

NetworkValidatedLedgers& ripple::ETLSource::networkValidatedLedgers_
private

Definition at line 71 of file ETLSource.h.

◆ journal_

beast::Journal ripple::ETLSource::journal_
private

Definition at line 73 of file ETLSource.h.

◆ app_

Application& ripple::ETLSource::app_
private

Definition at line 75 of file ETLSource.h.

◆ mtx_

std::mutex ripple::ETLSource::mtx_
mutableprivate

Definition at line 77 of file ETLSource.h.

◆ numFailures_

size_t ripple::ETLSource::numFailures_ = 0
private

Definition at line 79 of file ETLSource.h.

◆ closing_

std::atomic_bool ripple::ETLSource::closing_ = false
private

Definition at line 81 of file ETLSource.h.

◆ connected_

std::atomic_bool ripple::ETLSource::connected_ = false
private

Definition at line 83 of file ETLSource.h.

◆ forwardingStream_

std::atomic_bool ripple::ETLSource::forwardingStream_ = false
private

Definition at line 89 of file ETLSource.h.

◆ lastMsgTime_

std::chrono::system_clock::time_point ripple::ETLSource::lastMsgTime_
private

Definition at line 92 of file ETLSource.h.

◆ lastMsgTimeMtx_

std::mutex ripple::ETLSource::lastMsgTimeMtx_
mutableprivate

Definition at line 93 of file ETLSource.h.

◆ timer_

boost::asio::steady_timer ripple::ETLSource::timer_
private

Definition at line 96 of file ETLSource.h.