mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Outline of the LedgerAcquire class and its tracking class.
This commit is contained in:
98
LedgerAcquire.cpp
Normal file
98
LedgerAcquire.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
|
||||
#include "boost/foreach.hpp"
|
||||
|
||||
#include "Application.h"
|
||||
#include "LedgerAcquire.h"
|
||||
|
||||
LedgerAcquire::LedgerAcquire(const uint256& hash) : mHash(hash),
|
||||
mComplete(false), mFailed(false), mHaveBase(false), mHaveState(false), mHaveTransactions(false)
|
||||
{
|
||||
}
|
||||
|
||||
void LedgerAcquire::done()
|
||||
{
|
||||
std::vector< boost::function<void (LedgerAcquire::pointer)> > triggers;
|
||||
|
||||
mLock.lock();
|
||||
triggers=mOnComplete;
|
||||
mLock.unlock();
|
||||
|
||||
for(int i=0; i<triggers.size(); i++)
|
||||
triggers[i](shared_from_this());
|
||||
}
|
||||
|
||||
|
||||
void LedgerAcquire::timerEntry(boost::weak_ptr<LedgerAcquire> wptr)
|
||||
{
|
||||
LedgerAcquire::pointer ptr=wptr.lock();
|
||||
if(ptr) ptr->trigger(true);
|
||||
}
|
||||
|
||||
void LedgerAcquire::addOnComplete(boost::function<void (LedgerAcquire::pointer)> trigger)
|
||||
{
|
||||
mLock.lock();
|
||||
mOnComplete.push_back(trigger);
|
||||
mLock.unlock();
|
||||
}
|
||||
|
||||
void LedgerAcquire::trigger(bool timer)
|
||||
{
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
void LedgerAcquire::peerHas(Peer::pointer)
|
||||
{
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
void LedgerAcquire::badPeer(Peer::pointer)
|
||||
{
|
||||
// WRITEME
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeBase(std::vector<unsigned char> data)
|
||||
{
|
||||
// WRITEME
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeTxNode(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data)
|
||||
{
|
||||
// WRITEME
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeAsNode(std::list<uint160> hashes, std::list<std::vector<unsigned char> > data)
|
||||
{
|
||||
// WRITEME
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeTx(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data)
|
||||
{
|
||||
// WRITEME
|
||||
return true;
|
||||
}
|
||||
|
||||
LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
LedgerAcquire::pointer& ptr=mLedgers[hash];
|
||||
if(!ptr) ptr=LedgerAcquire::pointer(new LedgerAcquire(hash));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
LedgerAcquire::pointer LedgerAcquireMaster::find(const uint256& hash)
|
||||
{
|
||||
LedgerAcquire::pointer ret;
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
std::map<uint256, LedgerAcquire::pointer>::iterator it=mLedgers.find(hash);
|
||||
if(it!=mLedgers.end()) ret=it->second;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool LedgerAcquireMaster::hasLedger(const uint256& hash)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
return mLedgers.find(hash)!=mLedgers.end();
|
||||
}
|
||||
@@ -2,13 +2,15 @@
|
||||
#define __LEDGERACQUIRE__
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "boost/enable_shared_from_this.hpp"
|
||||
#include "boost/function.hpp"
|
||||
|
||||
#include "Ledger.h"
|
||||
#include "Peer.h"
|
||||
|
||||
class LedgerAcquire
|
||||
class LedgerAcquire : public boost::enable_shared_from_this<LedgerAcquire>
|
||||
{ // A ledger we are trying to acquire
|
||||
public:
|
||||
typedef boost::shared_ptr<LedgerAcquire> pointer;
|
||||
@@ -18,12 +20,14 @@ protected:
|
||||
Ledger::pointer mLedger;
|
||||
uint256 mHash;
|
||||
bool mComplete, mFailed, mHaveBase, mHaveState, mHaveTransactions;
|
||||
std::vector< boost::function<LedgerAcquire::pointer> > mOnComplete;
|
||||
std::vector< boost::function<void (LedgerAcquire::pointer)> > mOnComplete;
|
||||
|
||||
std::list<boost::weak_ptr<Peer> > mPeers; // peers known to have this ledger
|
||||
|
||||
void done(void);
|
||||
void timerEntry(void);
|
||||
void done();
|
||||
void trigger(bool timer);
|
||||
|
||||
static void timerEntry(boost::weak_ptr<LedgerAcquire>);
|
||||
|
||||
public:
|
||||
LedgerAcquire(const uint256& hash);
|
||||
@@ -36,13 +40,14 @@ public:
|
||||
bool isTransComplete() const { return mHaveTransactions; }
|
||||
Ledger::pointer getLedger() { return mLedger; }
|
||||
|
||||
void addTrigger(boost::function<LedgerAcquire::pointer>);
|
||||
void addOnComplete(boost::function<void (LedgerAcquire::pointer)>);
|
||||
|
||||
void peerHash(Peer::pointer);
|
||||
void takeBase(std::vector<unsigned char> data);
|
||||
void takeTxNode(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
||||
void takeAsNode(std::list<uint160> hashes, std::list<std::vector<unsigned char> > data);
|
||||
void takeTx(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
||||
void peerHas(Peer::pointer);
|
||||
void badPeer(Peer::pointer);
|
||||
bool takeBase(std::vector<unsigned char> data);
|
||||
bool takeTxNode(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
||||
bool takeAsNode(std::list<uint160> hashes, std::list<std::vector<unsigned char> > data);
|
||||
bool takeTx(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
||||
};
|
||||
|
||||
class LedgerAcquireMaster
|
||||
|
||||
Reference in New Issue
Block a user