mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Format first-party source according to .clang-format
This commit is contained in:
committed by
manojsdoshi
parent
65dfc5d19e
commit
50760c6935
@@ -17,10 +17,10 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/overlay/Overlay.h>
|
||||
#include <ripple/overlay/PeerSet.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -35,116 +35,128 @@ class InboundLedger;
|
||||
// derived class. Why not just make the timer callback
|
||||
// function pure virtual?
|
||||
//
|
||||
PeerSet::PeerSet (Application& app, uint256 const& hash,
|
||||
std::chrono::milliseconds interval, clock_type& clock,
|
||||
PeerSet::PeerSet(
|
||||
Application& app,
|
||||
uint256 const& hash,
|
||||
std::chrono::milliseconds interval,
|
||||
clock_type& clock,
|
||||
beast::Journal journal)
|
||||
: app_ (app)
|
||||
, m_journal (journal)
|
||||
, m_clock (clock)
|
||||
, mHash (hash)
|
||||
, mTimerInterval (interval)
|
||||
, mTimeouts (0)
|
||||
, mComplete (false)
|
||||
, mFailed (false)
|
||||
, mProgress (false)
|
||||
, mTimer (app_.getIOService ())
|
||||
: app_(app)
|
||||
, m_journal(journal)
|
||||
, m_clock(clock)
|
||||
, mHash(hash)
|
||||
, mTimerInterval(interval)
|
||||
, mTimeouts(0)
|
||||
, mComplete(false)
|
||||
, mFailed(false)
|
||||
, mProgress(false)
|
||||
, mTimer(app_.getIOService())
|
||||
{
|
||||
mLastAction = m_clock.now();
|
||||
assert ((mTimerInterval > 10ms) && (mTimerInterval < 30s));
|
||||
assert((mTimerInterval > 10ms) && (mTimerInterval < 30s));
|
||||
}
|
||||
|
||||
PeerSet::~PeerSet() = default;
|
||||
|
||||
bool PeerSet::insert (std::shared_ptr<Peer> const& ptr)
|
||||
bool
|
||||
PeerSet::insert(std::shared_ptr<Peer> const& ptr)
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
ScopedLockType sl(mLock);
|
||||
|
||||
if (!mPeers.insert (ptr->id ()).second)
|
||||
if (!mPeers.insert(ptr->id()).second)
|
||||
return false;
|
||||
|
||||
newPeer (ptr);
|
||||
newPeer(ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PeerSet::setTimer ()
|
||||
void
|
||||
PeerSet::setTimer()
|
||||
{
|
||||
mTimer.expires_from_now(mTimerInterval);
|
||||
mTimer.async_wait (
|
||||
[wptr=pmDowncast()](boost::system::error_code const& ec)
|
||||
{
|
||||
mTimer.async_wait(
|
||||
[wptr = pmDowncast()](boost::system::error_code const& ec) {
|
||||
if (ec == boost::asio::error::operation_aborted)
|
||||
return;
|
||||
|
||||
if (auto ptr = wptr.lock ())
|
||||
ptr->execute ();
|
||||
if (auto ptr = wptr.lock())
|
||||
ptr->execute();
|
||||
});
|
||||
}
|
||||
|
||||
void PeerSet::invokeOnTimer ()
|
||||
void
|
||||
PeerSet::invokeOnTimer()
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
ScopedLockType sl(mLock);
|
||||
|
||||
if (isDone ())
|
||||
if (isDone())
|
||||
return;
|
||||
|
||||
if (!isProgress())
|
||||
{
|
||||
++mTimeouts;
|
||||
JLOG (m_journal.debug()) << "Timeout(" << mTimeouts
|
||||
<< ") pc=" << mPeers.size () << " acquiring " << mHash;
|
||||
onTimer (false, sl);
|
||||
JLOG(m_journal.debug())
|
||||
<< "Timeout(" << mTimeouts << ") pc=" << mPeers.size()
|
||||
<< " acquiring " << mHash;
|
||||
onTimer(false, sl);
|
||||
}
|
||||
else
|
||||
{
|
||||
mProgress = false;
|
||||
onTimer (true, sl);
|
||||
onTimer(true, sl);
|
||||
}
|
||||
|
||||
if (!isDone ())
|
||||
setTimer ();
|
||||
if (!isDone())
|
||||
setTimer();
|
||||
}
|
||||
|
||||
bool PeerSet::isActive ()
|
||||
bool
|
||||
PeerSet::isActive()
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
return !isDone ();
|
||||
ScopedLockType sl(mLock);
|
||||
return !isDone();
|
||||
}
|
||||
|
||||
void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL, std::shared_ptr<Peer> const& peer)
|
||||
void
|
||||
PeerSet::sendRequest(
|
||||
const protocol::TMGetLedger& tmGL,
|
||||
std::shared_ptr<Peer> const& peer)
|
||||
{
|
||||
if (!peer)
|
||||
sendRequest (tmGL);
|
||||
sendRequest(tmGL);
|
||||
else
|
||||
peer->send (std::make_shared<Message> (tmGL, protocol::mtGET_LEDGER));
|
||||
peer->send(std::make_shared<Message>(tmGL, protocol::mtGET_LEDGER));
|
||||
}
|
||||
|
||||
void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL)
|
||||
void
|
||||
PeerSet::sendRequest(const protocol::TMGetLedger& tmGL)
|
||||
{
|
||||
ScopedLockType sl (mLock);
|
||||
ScopedLockType sl(mLock);
|
||||
|
||||
if (mPeers.empty ())
|
||||
if (mPeers.empty())
|
||||
return;
|
||||
|
||||
auto packet = std::make_shared<Message>(tmGL, protocol::mtGET_LEDGER);
|
||||
|
||||
for (auto id : mPeers)
|
||||
{
|
||||
if (auto peer = app_.overlay ().findPeerByShortID (id))
|
||||
peer->send (packet);
|
||||
if (auto peer = app_.overlay().findPeerByShortID(id))
|
||||
peer->send(packet);
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t PeerSet::getPeerCount () const
|
||||
std::size_t
|
||||
PeerSet::getPeerCount() const
|
||||
{
|
||||
std::size_t ret (0);
|
||||
std::size_t ret(0);
|
||||
|
||||
for (auto id : mPeers)
|
||||
{
|
||||
if (app_.overlay ().findPeerByShortID (id))
|
||||
if (app_.overlay().findPeerByShortID(id))
|
||||
++ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user