From b144fa48b576cf78ed8581a6e41c875effd8c2b3 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 28 May 2012 13:06:45 -0700 Subject: [PATCH] More ledger consensus work. IHAVE broadcast logic. --- src/LedgerConsensus.cpp | 29 ++++++++++++++++++++--------- src/LedgerConsensus.h | 1 + 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 4039b8c3f3..a2eff8f8aa 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -30,10 +30,10 @@ void TransactionAcquire::trigger(Peer::pointer peer) return; if (!mHaveRoot) { - boost::shared_ptr tmGL = boost::make_shared(); - tmGL->set_ledgerhash(mHash.begin(), mHash.size()); - tmGL->set_itype(newcoin::liTS_CANDIDATE); - *(tmGL->add_nodeids()) = SHAMapNode().getRawString(); + newcoin::TMGetLedger tmGL; + tmGL.set_ledgerhash(mHash.begin(), mHash.size()); + tmGL.set_itype(newcoin::liTS_CANDIDATE); + *(tmGL.add_nodeids()) = SHAMapNode().getRawString(); sendRequest(tmGL, peer); } if (mHaveRoot) @@ -50,11 +50,11 @@ void TransactionAcquire::trigger(Peer::pointer peer) } else { - boost::shared_ptr tmGL = boost::make_shared(); - tmGL->set_ledgerhash(mHash.begin(), mHash.size()); - tmGL->set_itype(newcoin::liTS_CANDIDATE); + newcoin::TMGetLedger tmGL; + tmGL.set_ledgerhash(mHash.begin(), mHash.size()); + tmGL.set_itype(newcoin::liTS_CANDIDATE); for (std::vector::iterator it = nodeIDs.begin(); it != nodeIDs.end(); ++it) - *(tmGL->add_nodeids()) = it->getRawString(); + *(tmGL.add_nodeids()) = it->getRawString(); if (peer) sendRequest(tmGL, peer); else @@ -204,7 +204,18 @@ void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map) if (!peers.empty()) adjustCount(map, peers); - // WRITEME: broadcast an IHAVE for this set + std::vector hashes; + hashes.push_back(hash); + sendHaveTxSet(hashes); +} + +void LedgerConsensus::sendHaveTxSet(const std::vector& hashes) +{ + newcoin::TMHaveTransactionSet set; + for (std::vector::const_iterator it = hashes.begin(), end = hashes.end(); it != end; ++it) + set.add_hashes(it->begin(), 256 / 8); + PackedMessage::pointer packet = boost::make_shared(set, newcoin::mtHAVE_SET); + theApp->getConnectionPool().relayMessage(NULL, packet); } void LedgerConsensus::adjustCount(SHAMap::pointer map, const std::vector& peers) diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 2de63dd695..dc15a3851b 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -102,6 +102,7 @@ protected: void addPosition(LedgerProposal&, bool ours); void removePosition(LedgerProposal&, bool ours); + void sendHaveTxSet(const std::vector& txSetHashes); int getThreshold(); public: