diff --git a/LedgerAcquire.cpp b/LedgerAcquire.cpp index 21b4709d38..7523419d87 100644 --- a/LedgerAcquire.cpp +++ b/LedgerAcquire.cpp @@ -1,5 +1,6 @@ #include "boost/foreach.hpp" +#include "boost/make_shared.hpp" #include "Application.h" #include "LedgerAcquire.h" @@ -7,6 +8,7 @@ LedgerAcquire::LedgerAcquire(const uint256& hash) : mHash(hash), mComplete(false), mFailed(false), mHaveBase(false), mHaveState(false), mHaveTransactions(false) { + ; } void LedgerAcquire::done() @@ -37,7 +39,50 @@ void LedgerAcquire::addOnComplete(boost::function void LedgerAcquire::trigger(bool timer) { - // WRITEME + if(mComplete || mFailed) return; + + if(!mHaveBase) + { + boost::shared_ptr tmGL=boost::make_shared(); + tmGL->set_ledgerhash(mHash.begin(), mHash.size()); + tmGL->set_itype(newcoin::liBASE); + sendRequest(tmGL); + } + + if(mHaveBase && !mHaveTransactions) + { + // WRITEME + } + + if(mHaveBase && !mHaveState) + { + // WRITEME + } + + if(timer) + { + // WRITEME + } +} + +void LedgerAcquire::sendRequest(boost::shared_ptr tmGL) +{ + if(!mPeers.size()) return; + + PackedMessage::pointer packet=boost::make_shared(tmGL, newcoin::mtGET_LEDGER); + + std::list >::iterator it=mPeers.begin(); + while(it!=mPeers.end()) + { + if(it->expired()) + mPeers.erase(it++); + else + { // FIXME: Possible race if peer has error + // FIXME: Track last peer sent to and time sent + it->lock()->sendPacket(packet); + return; + } + } } void LedgerAcquire::peerHas(Peer::pointer ptr) diff --git a/LedgerAcquire.h b/LedgerAcquire.h index 1d85bfaeda..7550b5311c 100644 --- a/LedgerAcquire.h +++ b/LedgerAcquire.h @@ -9,6 +9,7 @@ #include "Ledger.h" #include "Peer.h" +#include "newcoin.pb.h" class LedgerAcquire : public boost::enable_shared_from_this { // A ledger we are trying to acquire @@ -28,6 +29,7 @@ protected: void trigger(bool timer); static void timerEntry(boost::weak_ptr); + void sendRequest(boost::shared_ptr message); public: LedgerAcquire(const uint256& hash);