rippled
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ripple::InboundLedger Class Referencefinal

#include <InboundLedger.h>

Inheritance diagram for ripple::InboundLedger:
Inheritance graph
[legend]
Collaboration diagram for ripple::InboundLedger:
Collaboration graph
[legend]

Public Types

enum class  Reason { HISTORY , GENERIC , CONSENSUS }
 
using clock_type = beast::abstract_clock< std::chrono::steady_clock >
 
using neededHash_t = std::pair< protocol::TMGetObjectByHash::ObjectType, uint256 >
 

Public Member Functions

 InboundLedger (Application &app, uint256 const &hash, std::uint32_t seq, Reason reason, clock_type &, std::unique_ptr< PeerSet > peerSet)
 
 ~InboundLedger ()
 
void update (std::uint32_t seq)
 
bool isComplete () const
 Returns true if we got all the data.
 
bool isFailed () const
 Returns false if we failed to get the data.
 
std::shared_ptr< Ledger const > getLedger () const
 
std::uint32_t getSeq () const
 
bool checkLocal ()
 
void init (ScopedLockType &collectionLock)
 
bool gotData (std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > const &)
 Stash a TMLedgerData received from a peer for later processing Returns 'true' if we need to dispatch.
 
Json::Value getJson (int)
 Return a Json::objectValue.
 
void runData ()
 Process pending TMLedgerData Query the a random sample of the 'best' peers.
 
void touch ()
 
clock_type::time_point getLastAction () const
 
virtual void cancel ()
 Cancel the task by marking it as failed if the task is not done.
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 

Protected Types

using ScopedLockType = std::unique_lock< std::recursive_mutex >
 

Protected Member Functions

void setTimer (ScopedLockType &)
 Schedule a call to queueJob() after mTimerInterval.
 
void queueJob (ScopedLockType &)
 Queue a job to call invokeOnTimer().
 
bool isDone () const
 

Protected Attributes

Applicationapp_
 
beast::Journal journal_
 
std::recursive_mutex mtx_
 
uint256 const hash_
 The hash of the object (in practice, always a ledger) we are trying to fetch.
 
int timeouts_
 
bool complete_
 
bool failed_
 
bool progress_
 Whether forward progress has been made.
 
std::chrono::milliseconds timerInterval_
 The minimum time to wait between calls to execute().
 
QueueJobParameter queueJobParameter_
 

Private Types

enum class  TriggerReason { added , reply , timeout }
 

Private Member Functions

void filterNodes (std::vector< std::pair< SHAMapNodeID, uint256 > > &nodes, TriggerReason reason)
 
void trigger (std::shared_ptr< Peer > const &, TriggerReason)
 Request more nodes, perhaps from a specific peer.
 
std::vector< neededHash_tgetNeededHashes ()
 
void addPeers ()
 Add more peers to the set, if possible.
 
void tryDB (NodeStore::Database &srcDB)
 
void done ()
 
void onTimer (bool progress, ScopedLockType &peerSetLock) override
 Called with a lock by the PeerSet when the timer expires.
 
std::size_t getPeerCount () const
 
std::weak_ptr< TimeoutCounterpmDowncast () override
 Return a weak pointer to this.
 
int processData (std::shared_ptr< Peer > peer, protocol::TMLedgerData &data)
 Process one TMLedgerData Returns the number of useful nodes.
 
bool takeHeader (std::string const &data)
 Take ledger header data Call with a lock.
 
void receiveNode (protocol::TMLedgerData &packet, SHAMapAddNode &)
 Process node data received from a peer Call with a lock.
 
bool takeTxRootNode (Slice const &data, SHAMapAddNode &)
 Process AS root node received from a peer Call with a lock.
 
bool takeAsRootNode (Slice const &data, SHAMapAddNode &)
 Process AS root node received from a peer Call with a lock.
 
std::vector< uint256neededTxHashes (int max, SHAMapSyncFilter *filter) const
 
std::vector< uint256neededStateHashes (int max, SHAMapSyncFilter *filter) const
 
void invokeOnTimer ()
 Calls onTimer() if in the right state.
 

Static Private Member Functions

static auto & getCounter () noexcept
 

Private Attributes

clock_typem_clock
 
clock_type::time_point mLastAction
 
std::shared_ptr< LedgermLedger
 
bool mHaveHeader
 
bool mHaveState
 
bool mHaveTransactions
 
bool mSignaled
 
bool mByHash
 
std::uint32_t mSeq
 
Reason const mReason
 
std::set< uint256mRecentNodes
 
SHAMapAddNode mStats
 
std::mutex mReceivedDataLock
 
std::vector< std::pair< std::weak_ptr< Peer >, std::shared_ptr< protocol::TMLedgerData > > > mReceivedData
 
bool mReceiveDispatched
 
std::unique_ptr< PeerSetmPeerSet
 
boost::asio::basic_waitable_timer< std::chrono::steady_clocktimer_
 

Detailed Description

Definition at line 18 of file InboundLedger.h.

Member Typedef Documentation

◆ clock_type

Definition at line 23 of file InboundLedger.h.

◆ neededHash_t

using ripple::InboundLedger::neededHash_t = std::pair<protocol::TMGetObjectByHash::ObjectType, uint256>

Definition at line 82 of file InboundLedger.h.

◆ ScopedLockType

Definition at line 64 of file TimeoutCounter.h.

Member Enumeration Documentation

◆ Reason

enum class ripple::InboundLedger::Reason
strong
Enumerator
HISTORY 
GENERIC 
CONSENSUS 

Definition at line 26 of file InboundLedger.h.

◆ TriggerReason

enum class ripple::InboundLedger::TriggerReason
strongprivate
Enumerator
added 
reply 
timeout 

Definition at line 105 of file InboundLedger.h.

Constructor & Destructor Documentation

◆ InboundLedger()

ripple::InboundLedger::InboundLedger ( Application app,
uint256 const &  hash,
std::uint32_t  seq,
Reason  reason,
clock_type clock,
std::unique_ptr< PeerSet peerSet 
)

Definition at line 57 of file InboundLedger.cpp.

◆ ~InboundLedger()

ripple::InboundLedger::~InboundLedger ( )

Definition at line 161 of file InboundLedger.cpp.

Member Function Documentation

◆ update()

void ripple::InboundLedger::update ( std::uint32_t  seq)

Definition at line 130 of file InboundLedger.cpp.

◆ isComplete()

bool ripple::InboundLedger::isComplete ( ) const

Returns true if we got all the data.

Definition at line 48 of file InboundLedger.h.

◆ isFailed()

bool ripple::InboundLedger::isFailed ( ) const

Returns false if we failed to get the data.

Definition at line 55 of file InboundLedger.h.

◆ getLedger()

std::shared_ptr< Ledger const > ripple::InboundLedger::getLedger ( ) const

Definition at line 61 of file InboundLedger.h.

◆ getSeq()

std::uint32_t ripple::InboundLedger::getSeq ( ) const

Definition at line 67 of file InboundLedger.h.

◆ checkLocal()

bool ripple::InboundLedger::checkLocal ( )

Definition at line 143 of file InboundLedger.cpp.

◆ init()

void ripple::InboundLedger::init ( ScopedLockType collectionLock)

Definition at line 86 of file InboundLedger.cpp.

◆ gotData()

bool ripple::InboundLedger::gotData ( std::weak_ptr< Peer peer,
std::shared_ptr< protocol::TMLedgerData > const &  data 
)

Stash a TMLedgerData received from a peer for later processing Returns 'true' if we need to dispatch.

Definition at line 1028 of file InboundLedger.cpp.

◆ getJson()

Json::Value ripple::InboundLedger::getJson ( int  )

Return a Json::objectValue.

Definition at line 1287 of file InboundLedger.cpp.

◆ runData()

void ripple::InboundLedger::runData ( )

Process pending TMLedgerData Query the a random sample of the 'best' peers.

Definition at line 1240 of file InboundLedger.cpp.

◆ touch()

void ripple::InboundLedger::touch ( )

Definition at line 93 of file InboundLedger.h.

◆ getLastAction()

clock_type::time_point ripple::InboundLedger::getLastAction ( ) const

Definition at line 99 of file InboundLedger.h.

◆ filterNodes()

void ripple::InboundLedger::filterNodes ( std::vector< std::pair< SHAMapNodeID, uint256 > > &  nodes,
TriggerReason  reason 
)
private

Definition at line 754 of file InboundLedger.cpp.

◆ trigger()

void ripple::InboundLedger::trigger ( std::shared_ptr< Peer > const &  peer,
TriggerReason  reason 
)
private

Request more nodes, perhaps from a specific peer.

Definition at line 472 of file InboundLedger.cpp.

◆ getNeededHashes()

std::vector< InboundLedger::neededHash_t > ripple::InboundLedger::getNeededHashes ( )
private

Definition at line 988 of file InboundLedger.cpp.

◆ addPeers()

void ripple::InboundLedger::addPeers ( )
private

Add more peers to the set, if possible.

Definition at line 398 of file InboundLedger.cpp.

◆ tryDB()

void ripple::InboundLedger::tryDB ( NodeStore::Database srcDB)
private

Definition at line 222 of file InboundLedger.cpp.

◆ done()

void ripple::InboundLedger::done ( )
private

Definition at line 418 of file InboundLedger.cpp.

◆ onTimer()

void ripple::InboundLedger::onTimer ( bool  progress,
ScopedLockType peerSetLock 
)
overrideprivatevirtual

Called with a lock by the PeerSet when the timer expires.

Implements ripple::TimeoutCounter.

Definition at line 347 of file InboundLedger.cpp.

◆ getPeerCount()

std::size_t ripple::InboundLedger::getPeerCount ( ) const
private

Definition at line 121 of file InboundLedger.cpp.

◆ pmDowncast()

std::weak_ptr< TimeoutCounter > ripple::InboundLedger::pmDowncast ( )
overrideprivatevirtual

Return a weak pointer to this.

Implements ripple::TimeoutCounter.

Definition at line 412 of file InboundLedger.cpp.

◆ processData()

int ripple::InboundLedger::processData ( std::shared_ptr< Peer peer,
protocol::TMLedgerData &  data 
)
private

Process one TMLedgerData Returns the number of useful nodes.

Definition at line 1055 of file InboundLedger.cpp.

◆ takeHeader()

bool ripple::InboundLedger::takeHeader ( std::string const &  data)
private

Take ledger header data Call with a lock.

Definition at line 800 of file InboundLedger.cpp.

◆ receiveNode()

void ripple::InboundLedger::receiveNode ( protocol::TMLedgerData &  packet,
SHAMapAddNode san 
)
private

Process node data received from a peer Call with a lock.

Definition at line 847 of file InboundLedger.cpp.

◆ takeTxRootNode()

bool ripple::InboundLedger::takeTxRootNode ( Slice const &  data,
SHAMapAddNode san 
)
private

Process AS root node received from a peer Call with a lock.

Definition at line 964 of file InboundLedger.cpp.

◆ takeAsRootNode()

bool ripple::InboundLedger::takeAsRootNode ( Slice const &  data,
SHAMapAddNode san 
)
private

Process AS root node received from a peer Call with a lock.

Definition at line 937 of file InboundLedger.cpp.

◆ neededTxHashes()

std::vector< uint256 > ripple::InboundLedger::neededTxHashes ( int  max,
SHAMapSyncFilter filter 
) const
private

Definition at line 207 of file InboundLedger.cpp.

◆ neededStateHashes()

std::vector< uint256 > ripple::InboundLedger::neededStateHashes ( int  max,
SHAMapSyncFilter filter 
) const
private

Definition at line 213 of file InboundLedger.cpp.

◆ cancel()

void ripple::TimeoutCounter::cancel ( )
virtualinherited

Cancel the task by marking it as failed if the task is not done.

Note
this function does not attempt to cancel the scheduled timer or to remove the queued job if any. When the timer expires or the queued job starts, however, the code will see that the task is done and returns immediately, if it can lock the weak pointer of the task.

Definition at line 99 of file TimeoutCounter.cpp.

◆ setTimer()

void ripple::TimeoutCounter::setTimer ( ScopedLockType sl)
protectedinherited

Schedule a call to queueJob() after mTimerInterval.

Definition at line 31 of file TimeoutCounter.cpp.

◆ queueJob()

void ripple::TimeoutCounter::queueJob ( ScopedLockType sl)
protectedinherited

Queue a job to call invokeOnTimer().

Definition at line 50 of file TimeoutCounter.cpp.

◆ isDone()

bool ripple::TimeoutCounter::isDone ( ) const
protectedinherited

Definition at line 99 of file TimeoutCounter.h.

◆ invokeOnTimer()

void ripple::TimeoutCounter::invokeOnTimer ( )
privateinherited

Calls onTimer() if in the right state.

Only called by queueJob().

Definition at line 74 of file TimeoutCounter.cpp.

◆ getCounter()

static auto & ripple::CountedObject< InboundLedger >::getCounter ( )
staticprivatenoexceptinherited

Definition at line 110 of file CountedObject.h.

Member Data Documentation

◆ m_clock

clock_type& ripple::InboundLedger::m_clock
private

Definition at line 157 of file InboundLedger.h.

◆ mLastAction

clock_type::time_point ripple::InboundLedger::mLastAction
private

Definition at line 158 of file InboundLedger.h.

◆ mLedger

std::shared_ptr<Ledger> ripple::InboundLedger::mLedger
private

Definition at line 160 of file InboundLedger.h.

◆ mHaveHeader

bool ripple::InboundLedger::mHaveHeader
private

Definition at line 161 of file InboundLedger.h.

◆ mHaveState

bool ripple::InboundLedger::mHaveState
private

Definition at line 162 of file InboundLedger.h.

◆ mHaveTransactions

bool ripple::InboundLedger::mHaveTransactions
private

Definition at line 163 of file InboundLedger.h.

◆ mSignaled

bool ripple::InboundLedger::mSignaled
private

Definition at line 164 of file InboundLedger.h.

◆ mByHash

bool ripple::InboundLedger::mByHash
private

Definition at line 165 of file InboundLedger.h.

◆ mSeq

std::uint32_t ripple::InboundLedger::mSeq
private

Definition at line 166 of file InboundLedger.h.

◆ mReason

Reason const ripple::InboundLedger::mReason
private

Definition at line 167 of file InboundLedger.h.

◆ mRecentNodes

std::set<uint256> ripple::InboundLedger::mRecentNodes
private

Definition at line 169 of file InboundLedger.h.

◆ mStats

SHAMapAddNode ripple::InboundLedger::mStats
private

Definition at line 171 of file InboundLedger.h.

◆ mReceivedDataLock

std::mutex ripple::InboundLedger::mReceivedDataLock
private

Definition at line 174 of file InboundLedger.h.

◆ mReceivedData

std::vector< std::pair<std::weak_ptr<Peer>, std::shared_ptr<protocol::TMLedgerData> > > ripple::InboundLedger::mReceivedData
private

Definition at line 177 of file InboundLedger.h.

◆ mReceiveDispatched

bool ripple::InboundLedger::mReceiveDispatched
private

Definition at line 178 of file InboundLedger.h.

◆ mPeerSet

std::unique_ptr<PeerSet> ripple::InboundLedger::mPeerSet
private

Definition at line 179 of file InboundLedger.h.

◆ app_

Application& ripple::TimeoutCounter::app_
protectedinherited

Definition at line 106 of file TimeoutCounter.h.

◆ journal_

beast::Journal ripple::TimeoutCounter::journal_
protectedinherited

Definition at line 107 of file TimeoutCounter.h.

◆ mtx_

std::recursive_mutex ripple::TimeoutCounter::mtx_
mutableprotectedinherited

Definition at line 108 of file TimeoutCounter.h.

◆ hash_

uint256 const ripple::TimeoutCounter::hash_
protectedinherited

The hash of the object (in practice, always a ledger) we are trying to fetch.

Definition at line 112 of file TimeoutCounter.h.

◆ timeouts_

int ripple::TimeoutCounter::timeouts_
protectedinherited

Definition at line 113 of file TimeoutCounter.h.

◆ complete_

bool ripple::TimeoutCounter::complete_
protectedinherited

Definition at line 114 of file TimeoutCounter.h.

◆ failed_

bool ripple::TimeoutCounter::failed_
protectedinherited

Definition at line 115 of file TimeoutCounter.h.

◆ progress_

bool ripple::TimeoutCounter::progress_
protectedinherited

Whether forward progress has been made.

Definition at line 117 of file TimeoutCounter.h.

◆ timerInterval_

std::chrono::milliseconds ripple::TimeoutCounter::timerInterval_
protectedinherited

The minimum time to wait between calls to execute().

Definition at line 119 of file TimeoutCounter.h.

◆ queueJobParameter_

QueueJobParameter ripple::TimeoutCounter::queueJobParameter_
protectedinherited

Definition at line 121 of file TimeoutCounter.h.

◆ timer_

boost::asio::basic_waitable_timer<std::chrono::steady_clock> ripple::TimeoutCounter::timer_
privateinherited

Definition at line 130 of file TimeoutCounter.h.