Cleanups and extra asserts.

This commit is contained in:
JoelKatz
2013-08-13 11:57:01 -07:00
parent 02c25b049d
commit 28b600cc21
2 changed files with 28 additions and 15 deletions

View File

@@ -364,16 +364,10 @@ void LedgerMaster::tryFill (Ledger::pointer ledger)
void LedgerMaster::getFetchPack (Ledger::ref nextLedger)
{
protocol::TMGetObjectByHash tmBH;
tmBH.set_type (protocol::TMGetObjectByHash::otFETCH_PACK);
tmBH.set_query (true);
tmBH.set_seq (nextLedger->getLedgerSeq());
tmBH.set_ledgerhash (nextLedger->getHash().begin (), 32);
std::vector<Peer::pointer> peerList = getApp().getPeers ().getPeerVector ();
Peer::pointer target;
int count = 0;
std::vector<Peer::pointer> peerList = getApp().getPeers ().getPeerVector ();
BOOST_FOREACH (const Peer::pointer & peer, peerList)
{
if (peer->hasRange (nextLedger->getLedgerSeq() - 1, nextLedger->getLedgerSeq()))
@@ -387,7 +381,12 @@ void LedgerMaster::getFetchPack (Ledger::ref nextLedger)
if (target)
{
protocol::TMGetObjectByHash tmBH;
tmBH.set_query (true);
tmBH.set_type (protocol::TMGetObjectByHash::otFETCH_PACK);
tmBH.set_ledgerhash (nextLedger->getHash().begin (), 32);
PackedMessage::pointer packet = boost::make_shared<PackedMessage> (tmBH, protocol::mtGET_OBJECTS);
target->sendPacket (packet, false);
WriteLog (lsTRACE, LedgerMaster) << "Requested fetch pack for " << nextLedger->getLedgerSeq() - 1;
}

View File

@@ -32,27 +32,34 @@ InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 s
WriteLog (lsDEBUG, InboundLedger) << "Acquiring ledger we already have: " << hash;
}
assert (mLedgers[hash]);
return ptr;
}
InboundLedger::pointer InboundLedgers::find (uint256 const& hash)
{
assert (hash.isNonZero ());
boost::mutex::scoped_lock sl (mLock);
std::map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
if (it != mLedgers.end ())
InboundLedger::pointer ret;
{
it->second->touch ();
return it->second;
boost::mutex::scoped_lock sl (mLock);
std::map<uint256, InboundLedger::pointer>::iterator it = mLedgers.find (hash);
if (it != mLedgers.end ())
{
it->second->touch ();
ret = it->second;
}
}
return InboundLedger::pointer ();
return ret;
}
bool InboundLedgers::hasLedger (uint256 const& hash)
{
assert (hash.isNonZero ());
boost::mutex::scoped_lock sl (mLock);
return mLedgers.find (hash) != mLedgers.end ();
}
@@ -60,6 +67,7 @@ bool InboundLedgers::hasLedger (uint256 const& hash)
void InboundLedgers::dropLedger (uint256 const& hash)
{
assert (hash.isNonZero ());
boost::mutex::scoped_lock sl (mLock);
mLedgers.erase (hash);
}
@@ -254,7 +262,10 @@ void InboundLedgers::gotFetchPack (Job&)
acquires.reserve (mLedgers.size ());
typedef std::pair<uint256, InboundLedger::pointer> u256_acq_pair;
BOOST_FOREACH (const u256_acq_pair & it, mLedgers)
acquires.push_back (it.second);
{
assert (it.second);
acquires.push_back (it.second);
}
}
BOOST_FOREACH (const InboundLedger::pointer & acquire, acquires)
@@ -282,7 +293,10 @@ Json::Value InboundLedgers::getInfo()
acquires.reserve (mLedgers.size ());
BOOST_FOREACH (const u256_acq_pair & it, mLedgers)
acquires.push_back (it);
{
assert (it.second);
acquires.push_back (it);
}
}
BOOST_FOREACH (const u256_acq_pair& it, acquires)