rippled
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
ripple::SkipListAcquire Class Referencefinal

Manage the retrieval of a skip list in a ledger from the network. More...

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

Classes

struct  SkipListData
 

Public Types

using OnSkipListDataCB = std::function< void(bool successful, uint256 const &hash)>
 A callback used to notify that the SkipList is ready or failed. More...
 

Public Member Functions

 SkipListAcquire (Application &app, InboundLedgers &inboundLedgers, uint256 const &ledgerHash, std::unique_ptr< PeerSet > peerSet)
 Constructor. More...
 
 ~SkipListAcquire () override
 
void init (int numPeers)
 Start the SkipListAcquire task. More...
 
void processData (std::uint32_t ledgerSeq, boost::intrusive_ptr< SHAMapItem const > const &item)
 Process the data extracted from a peer's reply. More...
 
void addDataCallback (OnSkipListDataCB &&cb)
 Add a callback that will be called when the skipList is ready or failed. More...
 
std::shared_ptr< SkipListData const > getData () const
 
virtual void cancel ()
 Cancel the task by marking it as failed if the task is not done. More...
 
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. More...
 
void queueJob (ScopedLockType &)
 Queue a job to call invokeOnTimer(). More...
 
bool isDone () const
 

Protected Attributes

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

Private Member Functions

void onTimer (bool progress, ScopedLockType &peerSetLock) override
 Hook called from invokeOnTimer(). More...
 
std::weak_ptr< TimeoutCounterpmDowncast () override
 Return a weak pointer to this. More...
 
void trigger (std::size_t limit, ScopedLockType &sl)
 Trigger another round. More...
 
void retrieveSkipList (std::shared_ptr< Ledger const > const &ledger, ScopedLockType &sl)
 Retrieve the skip list from the ledger. More...
 
void onSkipListAcquired (std::vector< uint256 > const &skipList, std::uint32_t ledgerSeq, ScopedLockType &sl)
 Process the skip list. More...
 
void notify (ScopedLockType &sl)
 Call the OnSkipListDataCB callbacks. More...
 
void invokeOnTimer ()
 Calls onTimer() if in the right state. More...
 

Static Private Member Functions

static auto & getCounter () noexcept
 

Private Attributes

InboundLedgersinboundLedgers_
 
std::unique_ptr< PeerSetpeerSet_
 
std::vector< OnSkipListDataCBdataReadyCallbacks_
 
std::shared_ptr< SkipListData const > data_
 
std::uint32_t noFeaturePeerCount_ = 0
 
bool fallBack_ = false
 
boost::asio::basic_waitable_timer< std::chrono::steady_clocktimer_
 

Friends

class test::LedgerReplayClient
 

Detailed Description

Manage the retrieval of a skip list in a ledger from the network.

Before asking peers, always check if the local node has the ledger.

Definition at line 41 of file SkipListAcquire.h.

Member Typedef Documentation

◆ OnSkipListDataCB

using ripple::SkipListAcquire::OnSkipListDataCB = std::function<void(bool successful, uint256 const& hash)>

A callback used to notify that the SkipList is ready or failed.

Parameters
successfulif the skipList data was acquired successfully
hashhash of the ledger that has the skipList

Definition at line 53 of file SkipListAcquire.h.

◆ ScopedLockType

Definition at line 81 of file TimeoutCounter.h.

Constructor & Destructor Documentation

◆ SkipListAcquire()

ripple::SkipListAcquire::SkipListAcquire ( Application app,
InboundLedgers inboundLedgers,
uint256 const &  ledgerHash,
std::unique_ptr< PeerSet peerSet 
)

Constructor.

Parameters
appApplication reference
inboundLedgersInboundLedgers reference
ledgerHashhash of the ledger that has the skip list
peerSetmanage a set of peers that we will ask for the skip list

Definition at line 29 of file SkipListAcquire.cpp.

◆ ~SkipListAcquire()

ripple::SkipListAcquire::~SkipListAcquire ( )
override

Definition at line 48 of file SkipListAcquire.cpp.

Member Function Documentation

◆ init()

void ripple::SkipListAcquire::init ( int  numPeers)

Start the SkipListAcquire task.

Parameters
numPeersnumber of peers to try initially

Definition at line 54 of file SkipListAcquire.cpp.

◆ processData()

void ripple::SkipListAcquire::processData ( std::uint32_t  ledgerSeq,
boost::intrusive_ptr< SHAMapItem const > const &  item 
)

Process the data extracted from a peer's reply.

Parameters
ledgerSeqsequence number of the ledger that has the skip list
itemholder of the skip list
Note
ledgerSeq and item must have been verified against the ledger hash

Definition at line 138 of file SkipListAcquire.cpp.

◆ addDataCallback()

void ripple::SkipListAcquire::addDataCallback ( OnSkipListDataCB &&  cb)

Add a callback that will be called when the skipList is ready or failed.

Note
the callback will be called once and only once unless this object is destructed before the call.

Definition at line 171 of file SkipListAcquire.cpp.

◆ getData()

std::shared_ptr< SkipListAcquire::SkipListData const > ripple::SkipListAcquire::getData ( ) const

Definition at line 184 of file SkipListAcquire.cpp.

◆ onTimer()

void ripple::SkipListAcquire::onTimer ( bool  progress,
ScopedLockType  
)
overrideprivatevirtual

Hook called from invokeOnTimer().

Implements ripple::TimeoutCounter.

Definition at line 116 of file SkipListAcquire.cpp.

◆ pmDowncast()

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

Return a weak pointer to this.

Implements ripple::TimeoutCounter.

Definition at line 132 of file SkipListAcquire.cpp.

◆ trigger()

void ripple::SkipListAcquire::trigger ( std::size_t  limit,
ScopedLockType sl 
)
private

Trigger another round.

Parameters
limitnumber of new peers to send the request
sllock. this function must be called with the lock

Definition at line 65 of file SkipListAcquire.cpp.

◆ retrieveSkipList()

void ripple::SkipListAcquire::retrieveSkipList ( std::shared_ptr< Ledger const > const &  ledger,
ScopedLockType sl 
)
private

Retrieve the skip list from the ledger.

Parameters
ledgerthe ledger that has the skip list
sllock. this function must be called with the lock

Definition at line 191 of file SkipListAcquire.cpp.

◆ onSkipListAcquired()

void ripple::SkipListAcquire::onSkipListAcquired ( std::vector< uint256 > const &  skipList,
std::uint32_t  ledgerSeq,
ScopedLockType sl 
)
private

Process the skip list.

Parameters
skipListskip list
ledgerSeqsequence number of the ledger that has the skip list
sllock. this function must be called with the lock

Definition at line 213 of file SkipListAcquire.cpp.

◆ notify()

void ripple::SkipListAcquire::notify ( ScopedLockType sl)
private

Call the OnSkipListDataCB callbacks.

Parameters
sllock. this function must be called with the lock

Definition at line 225 of file SkipListAcquire.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 118 of file TimeoutCounter.cpp.

◆ setTimer()

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

Schedule a call to queueJob() after mTimerInterval.

Definition at line 50 of file TimeoutCounter.cpp.

◆ queueJob()

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

Queue a job to call invokeOnTimer().

Definition at line 69 of file TimeoutCounter.cpp.

◆ isDone()

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

Definition at line 116 of file TimeoutCounter.h.

◆ invokeOnTimer()

void ripple::TimeoutCounter::invokeOnTimer ( )
privateinherited

Calls onTimer() if in the right state.

Only called by queueJob().

Definition at line 93 of file TimeoutCounter.cpp.

◆ getCounter()

static auto& ripple::CountedObject< SkipListAcquire >::getCounter
staticprivatenoexceptinherited

Definition at line 128 of file CountedObject.h.

Friends And Related Function Documentation

◆ test::LedgerReplayClient

friend class test::LedgerReplayClient
friend

Definition at line 163 of file SkipListAcquire.h.

Member Data Documentation

◆ inboundLedgers_

InboundLedgers& ripple::SkipListAcquire::inboundLedgers_
private

Definition at line 156 of file SkipListAcquire.h.

◆ peerSet_

std::unique_ptr<PeerSet> ripple::SkipListAcquire::peerSet_
private

Definition at line 157 of file SkipListAcquire.h.

◆ dataReadyCallbacks_

std::vector<OnSkipListDataCB> ripple::SkipListAcquire::dataReadyCallbacks_
private

Definition at line 158 of file SkipListAcquire.h.

◆ data_

std::shared_ptr<SkipListData const> ripple::SkipListAcquire::data_
private

Definition at line 159 of file SkipListAcquire.h.

◆ noFeaturePeerCount_

std::uint32_t ripple::SkipListAcquire::noFeaturePeerCount_ = 0
private

Definition at line 160 of file SkipListAcquire.h.

◆ fallBack_

bool ripple::SkipListAcquire::fallBack_ = false
private

Definition at line 161 of file SkipListAcquire.h.

◆ app_

Application& ripple::TimeoutCounter::app_
protectedinherited

Definition at line 123 of file TimeoutCounter.h.

◆ journal_

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

Definition at line 124 of file TimeoutCounter.h.

◆ mtx_

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

Definition at line 125 of file TimeoutCounter.h.

◆ hash_

const uint256 ripple::TimeoutCounter::hash_
protectedinherited

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

Definition at line 129 of file TimeoutCounter.h.

◆ timeouts_

int ripple::TimeoutCounter::timeouts_
protectedinherited

Definition at line 130 of file TimeoutCounter.h.

◆ complete_

bool ripple::TimeoutCounter::complete_
protectedinherited

Definition at line 131 of file TimeoutCounter.h.

◆ failed_

bool ripple::TimeoutCounter::failed_
protectedinherited

Definition at line 132 of file TimeoutCounter.h.

◆ progress_

bool ripple::TimeoutCounter::progress_
protectedinherited

Whether forward progress has been made.

Definition at line 134 of file TimeoutCounter.h.

◆ timerInterval_

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

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

Definition at line 136 of file TimeoutCounter.h.

◆ queueJobParameter_

QueueJobParameter ripple::TimeoutCounter::queueJobParameter_
protectedinherited

Definition at line 138 of file TimeoutCounter.h.

◆ timer_

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

Definition at line 147 of file TimeoutCounter.h.