rippled
Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
ripple::PeerSet Class Referenceabstract

Supports data retrieval by managing a set of peers. More...

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

Protected Types

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

Protected Member Functions

 PeerSet (Application &app, uint256 const &hash, std::chrono::milliseconds interval, beast::Journal journal)
 
virtual ~PeerSet ()=0
 
void addPeers (std::size_t limit, std::function< bool(std::shared_ptr< Peer > const &)> score)
 Add at most limit peers to this set from the overlay. More...
 
virtual void onPeerAdded (std::shared_ptr< Peer > const &)=0
 Hook called from addPeers(). More...
 
virtual void onTimer (bool progress, ScopedLockType &)=0
 Hook called from invokeOnTimer(). More...
 
virtual void queueJob ()=0
 Queue a job to call invokeOnTimer(). More...
 
virtual std::weak_ptr< PeerSetpmDowncast ()=0
 Return a weak pointer to this. More...
 
bool isDone () const
 
void invokeOnTimer ()
 Calls onTimer() if in the right state. More...
 
void sendRequest (const protocol::TMGetLedger &message, std::shared_ptr< Peer > const &peer)
 Send a GetLedger message to one or all peers. More...
 
void setTimer ()
 Schedule a call to queueJob() after mTimerInterval. More...
 

Protected Attributes

Applicationapp_
 
beast::Journal m_journal
 
std::recursive_mutex mLock
 
const uint256 mHash
 The hash of the object (in practice, always a ledger) we are trying to fetch. More...
 
int mTimeouts
 
bool mComplete
 
bool mFailed
 
bool mProgress
 Whether forward progress has been made. More...
 
std::set< Peer::id_tmPeers
 The identifiers of the peers we are tracking. More...
 

Private Attributes

std::chrono::milliseconds mTimerInterval
 The minimum time to wait between calls to execute(). More...
 
boost::asio::basic_waitable_timer< std::chrono::steady_clockmTimer
 

Detailed Description

Supports data retrieval by managing a set of peers.

When desired data (such as a ledger or a transaction set) is missing locally it can be obtained by querying connected peers. This class manages common aspects of the retrieval. Callers maintain the set by adding and removing peers depending on whether the peers have useful information.

This class is an "active" object. It maintains its own timer and dispatches work to a job queue. Implementations derive from this class and override the abstract hook functions in the base.

The data is represented by its hash.

Definition at line 48 of file PeerSet.h.

Member Typedef Documentation

◆ ScopedLockType

Definition at line 51 of file PeerSet.h.

Constructor & Destructor Documentation

◆ PeerSet()

ripple::PeerSet::PeerSet ( Application app,
uint256 const &  hash,
std::chrono::milliseconds  interval,
beast::Journal  journal 
)
protected

Definition at line 29 of file PeerSet.cpp.

◆ ~PeerSet()

ripple::PeerSet::~PeerSet ( )
protectedpure virtualdefault

Member Function Documentation

◆ addPeers()

void ripple::PeerSet::addPeers ( std::size_t  limit,
std::function< bool(std::shared_ptr< Peer > const &)>  score 
)
protected

Add at most limit peers to this set from the overlay.

Definition at line 50 of file PeerSet.cpp.

◆ onPeerAdded()

virtual void ripple::PeerSet::onPeerAdded ( std::shared_ptr< Peer > const &  )
protectedpure virtual

Hook called from addPeers().

Implemented in ripple::InboundLedger, and ripple::TransactionAcquire.

◆ onTimer()

virtual void ripple::PeerSet::onTimer ( bool  progress,
ScopedLockType  
)
protectedpure virtual

Hook called from invokeOnTimer().

Implemented in ripple::InboundLedger, and ripple::TransactionAcquire.

◆ queueJob()

virtual void ripple::PeerSet::queueJob ( )
protectedpure virtual

Queue a job to call invokeOnTimer().

Implemented in ripple::InboundLedger, and ripple::TransactionAcquire.

◆ pmDowncast()

virtual std::weak_ptr<PeerSet> ripple::PeerSet::pmDowncast ( )
protectedpure virtual

Return a weak pointer to this.

Implemented in ripple::InboundLedger, and ripple::TransactionAcquire.

◆ isDone()

bool ripple::PeerSet::isDone ( ) const
protected

Definition at line 84 of file PeerSet.h.

◆ invokeOnTimer()

void ripple::PeerSet::invokeOnTimer ( )
protected

Calls onTimer() if in the right state.

Definition at line 101 of file PeerSet.cpp.

◆ sendRequest()

void ripple::PeerSet::sendRequest ( const protocol::TMGetLedger &  message,
std::shared_ptr< Peer > const &  peer 
)
protected

Send a GetLedger message to one or all peers.

Definition at line 127 of file PeerSet.cpp.

◆ setTimer()

void ripple::PeerSet::setTimer ( )
protected

Schedule a call to queueJob() after mTimerInterval.

Definition at line 87 of file PeerSet.cpp.

Member Data Documentation

◆ app_

Application& ripple::PeerSet::app_
protected

Definition at line 105 of file PeerSet.h.

◆ m_journal

beast::Journal ripple::PeerSet::m_journal
protected

Definition at line 106 of file PeerSet.h.

◆ mLock

std::recursive_mutex ripple::PeerSet::mLock
protected

Definition at line 108 of file PeerSet.h.

◆ mHash

const uint256 ripple::PeerSet::mHash
protected

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

Definition at line 112 of file PeerSet.h.

◆ mTimeouts

int ripple::PeerSet::mTimeouts
protected

Definition at line 113 of file PeerSet.h.

◆ mComplete

bool ripple::PeerSet::mComplete
protected

Definition at line 114 of file PeerSet.h.

◆ mFailed

bool ripple::PeerSet::mFailed
protected

Definition at line 115 of file PeerSet.h.

◆ mProgress

bool ripple::PeerSet::mProgress
protected

Whether forward progress has been made.

Definition at line 117 of file PeerSet.h.

◆ mPeers

std::set<Peer::id_t> ripple::PeerSet::mPeers
protected

The identifiers of the peers we are tracking.

Definition at line 120 of file PeerSet.h.

◆ mTimerInterval

std::chrono::milliseconds ripple::PeerSet::mTimerInterval
private

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

Definition at line 124 of file PeerSet.h.

◆ mTimer

boost::asio::basic_waitable_timer<std::chrono::steady_clock> ripple::PeerSet::mTimer
private

Definition at line 126 of file PeerSet.h.