diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 65730e8177..b96589212a 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -790,6 +790,14 @@ void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire) } } } + + std::vector peerList = theApp->getConnectionPool().getPeerVector(); + BOOST_FOREACH(Peer::ref peer, peerList) + { + if (peer->hasTxSet(acquire->getHash()) + acquire->peerHash(peer); + } + acquire->resetTimer(); } diff --git a/src/Peer.cpp b/src/Peer.cpp index db4ca281b4..2397071ae1 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -744,8 +744,11 @@ void Peer::recvHaveTxSet(newcoin::TMHaveTransactionSet& packet) punishPeer(PP_INVALID_REQUEST); return; } - memcpy(hashes.begin(), packet.hash().data(), 32); - if (!theApp->getOPs().hasTXSet(shared_from_this(), hashes, packet.status())) + uint256 hash; + memcpy(hash.begin(), packet.hash().data(), 32); + if (packet.status() == newcoin::tsHAVE) + addTxSet(hash); + if (!theApp->getOPs().hasTXSet(shared_from_this(), hash, packet.status())) punishPeer(PP_UNWANTED_DATA); } @@ -1142,11 +1145,29 @@ void Peer::addLedger(const uint256& hash) BOOST_FOREACH(const uint256& ledger, mRecentLedgers) if (ledger == hash) return; - if (mRecentLedgers.size() == 16) + if (mRecentLedgers.size() == 128) mRecentLedgers.pop_front(); mRecentLedgers.push_back(hash); } +bool Peer::hasTxSet(const uint256& hash) const +{ + BOOST_FOREACH(const uint256& set, mRecentTxSets) + if (set == hash) + return true; + return false; +} + +void Peer::addTxSet(const uint256& hash) +{ + BOOST_FOREACH(const uint256& set, mRecentTxSets) + if (set == hash) + return; + if (mRecentTxSets.size() == 128) + mRecentTxSets.pop_front(); + mRecentTxSets.push_back(hash); +} + // Get session information we can sign to prevent man in the middle attack. // (both sides get the same information, neither side controls it) void Peer::getSessionCookie(std::string& strDst) diff --git a/src/Peer.h b/src/Peer.h index ae4abf7307..0b28a1dc9b 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -46,6 +46,7 @@ private: uint256 mClosedLedgerHash, mPreviousLedgerHash; std::list mRecentLedgers; + std::list mRecentTxSets; boost::asio::ssl::stream mSocketSsl; @@ -118,6 +119,7 @@ protected: void getSessionCookie(std::string& strDst); void addLedger(const uint256& ledger); + void addTxSet(const uint256& TxSet); public: @@ -157,6 +159,7 @@ public: uint256 getClosedLedgerHash() const { return mClosedLedgerHash; } bool hasLedger(const uint256& hash) const; + bool hasTxSet(const uint256& hash) const; NewcoinAddress getNodePublic() const { return mNodePublic; } void cycleStatus() { mPreviousLedgerHash = mClosedLedgerHash; mClosedLedgerHash.zero(); } };