Prevent a race condition that can cause us to miss an "I have a transaction

set" message if it arrives as we're in the process of generating a new
last-closed ledger.
This commit is contained in:
JoelKatz
2012-10-04 02:19:47 -07:00
parent f0a9ee4505
commit 414a44b6b5
3 changed files with 35 additions and 3 deletions

View File

@@ -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)