mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 19:45:53 +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__
|
#define __LEDGERACQUIRE__
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "boost/enable_shared_from_this.hpp"
|
||||||
#include "boost/function.hpp"
|
#include "boost/function.hpp"
|
||||||
|
|
||||||
#include "Ledger.h"
|
#include "Ledger.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
|
||||||
class LedgerAcquire
|
class LedgerAcquire : public boost::enable_shared_from_this<LedgerAcquire>
|
||||||
{ // A ledger we are trying to acquire
|
{ // A ledger we are trying to acquire
|
||||||
public:
|
public:
|
||||||
typedef boost::shared_ptr<LedgerAcquire> pointer;
|
typedef boost::shared_ptr<LedgerAcquire> pointer;
|
||||||
@@ -18,12 +20,14 @@ protected:
|
|||||||
Ledger::pointer mLedger;
|
Ledger::pointer mLedger;
|
||||||
uint256 mHash;
|
uint256 mHash;
|
||||||
bool mComplete, mFailed, mHaveBase, mHaveState, mHaveTransactions;
|
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
|
std::list<boost::weak_ptr<Peer> > mPeers; // peers known to have this ledger
|
||||||
|
|
||||||
void done(void);
|
void done();
|
||||||
void timerEntry(void);
|
void trigger(bool timer);
|
||||||
|
|
||||||
|
static void timerEntry(boost::weak_ptr<LedgerAcquire>);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LedgerAcquire(const uint256& hash);
|
LedgerAcquire(const uint256& hash);
|
||||||
@@ -36,13 +40,14 @@ public:
|
|||||||
bool isTransComplete() const { return mHaveTransactions; }
|
bool isTransComplete() const { return mHaveTransactions; }
|
||||||
Ledger::pointer getLedger() { return mLedger; }
|
Ledger::pointer getLedger() { return mLedger; }
|
||||||
|
|
||||||
void addTrigger(boost::function<LedgerAcquire::pointer>);
|
void addOnComplete(boost::function<void (LedgerAcquire::pointer)>);
|
||||||
|
|
||||||
void peerHash(Peer::pointer);
|
void peerHas(Peer::pointer);
|
||||||
void takeBase(std::vector<unsigned char> data);
|
void badPeer(Peer::pointer);
|
||||||
void takeTxNode(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
bool takeBase(std::vector<unsigned char> data);
|
||||||
void takeAsNode(std::list<uint160> hashes, std::list<std::vector<unsigned char> > data);
|
bool takeTxNode(std::list<uint256> hashes, std::list<std::vector<unsigned char> > data);
|
||||||
void takeTx(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
|
class LedgerAcquireMaster
|
||||||
|
|||||||
Reference in New Issue
Block a user