From 76d4a91814f531f164e31581592530218360cd62 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 25 Oct 2012 19:59:05 -0700 Subject: [PATCH] Cleanups. --- src/LedgerConsensus.cpp | 20 +++++++++++--------- src/NetworkOPs.cpp | 2 +- src/Peer.cpp | 4 +--- src/RPCHandler.cpp | 6 +++--- src/SHAMap.h | 3 ++- src/SNTPClient.cpp | 6 +++--- src/SerializedTransaction.cpp | 5 ++--- src/Serializer.cpp | 29 +++++++++++++++++++---------- src/Transaction.cpp | 2 +- 9 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index dea7aabb4..e0917da0e 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -84,8 +84,8 @@ void TransactionAcquire::trigger(Peer::ref peer, bool timer) ripple::TMGetLedger tmGL; tmGL.set_ledgerhash(mHash.begin(), mHash.size()); tmGL.set_itype(ripple::liTS_CANDIDATE); - for (std::vector::iterator it = nodeIDs.begin(); it != nodeIDs.end(); ++it) - *(tmGL.add_nodeids()) = it->getRawString(); + BOOST_FOREACH(SHAMapNode& it, nodeIDs) + *(tmGL.add_nodeids()) = it.getRawString(); sendRequest(tmGL, peer); } } @@ -410,17 +410,19 @@ void LedgerConsensus::createDisputes(SHAMap::ref m1, SHAMap::ref m2) { SHAMap::SHAMapDiff differences; m1->compare(m2, differences, 16384); - for (SHAMap::SHAMapDiff::iterator pos = differences.begin(), end = differences.end(); pos != end; ++pos) + + typedef std::pair u256_diff_pair; + BOOST_FOREACH (u256_diff_pair& pos, differences) { // create disputed transactions (from the ledger that has them) - if (pos->second.first) + if (pos.second.first) { // transaction is in first map - assert(!pos->second.second); - addDisputedTransaction(pos->first, pos->second.first->peekData()); + assert(!pos.second.second); + addDisputedTransaction(pos.first, pos.second.first->peekData()); } - else if (pos->second.second) + else if (pos.second.second) { // transaction is in second map - assert(!pos->second.first); - addDisputedTransaction(pos->first, pos->second.second->peekData()); + assert(!pos.second.first); + addDisputedTransaction(pos.first, pos.second.second->peekData()); } else // No other disagreement over a transaction should be possible assert(false); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index f2fa89c7c..1c64fecec 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -678,7 +678,7 @@ bool NetworkOPs::haveConsensusObject() bool ledgerChange = checkLastClosedLedger(peerList, networkClosed); if (!ledgerChange) { - cLog(lsWARNING) << "Beginning consensus due to peer action"; + cLog(lsINFO) << "Beginning consensus due to peer action"; beginConsensus(networkClosed, mLedgerMaster->getCurrentLedger()); } return mConsensus; diff --git a/src/Peer.cpp b/src/Peer.cpp index a92e79446..8dd7a5c8c 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -688,9 +688,7 @@ void Peer::recvHello(ripple::TMHello& packet) void Peer::recvTransaction(ripple::TMTransaction& packet) { -#ifdef DEBUG - std::cerr << "Got transaction from peer" << std::endl; -#endif + cLog(lsDEBUG) << "Got transaction from peer"; Transaction::pointer tx; #ifndef TRUST_NETWORK diff --git a/src/RPCHandler.cpp b/src/RPCHandler.cpp index 43aad83c5..c6c8e9dba 100644 --- a/src/RPCHandler.cpp +++ b/src/RPCHandler.cpp @@ -2612,9 +2612,9 @@ Json::Value RPCHandler::doLogLevel(const Json::Value& params) ret["base"] = Log::severityToString(Log::getMinSeverity()); std::vector< std::pair > logTable = LogPartition::getSeverities(); - for (std::vector< std::pair >::iterator it = logTable.begin(); - it != logTable.end(); ++it) - ret[it->first] = it->second; + typedef std::pair stringPair; + BOOST_FOREACH(const stringPair& it, logTable) + ret[it.first] = it.second; return ret; } diff --git a/src/SHAMap.h b/src/SHAMap.h index 6973f6ce3..107d3d8b6 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -282,7 +282,8 @@ public: typedef boost::shared_ptr pointer; typedef const boost::shared_ptr& ref; - typedef std::map > SHAMapDiff; + typedef std::pair SHAMapDiffItem; + typedef std::map SHAMapDiff; typedef boost::unordered_map SHADirtyMap; private: diff --git a/src/SNTPClient.cpp b/src/SNTPClient.cpp index cdafc0698..d9663d134 100644 --- a/src/SNTPClient.cpp +++ b/src/SNTPClient.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -200,9 +201,8 @@ void SNTPClient::init(const std::vector& servers) Log(lsINFO) << "SNTP: no server specified"; return; } - do - addServer(*it++); - while (it != servers.end()); + BOOST_FOREACH(const std::string& it, servers) + addServer(it); queryAll(); } diff --git a/src/SerializedTransaction.cpp b/src/SerializedTransaction.cpp index 34df4f863..d6b7a0291 100644 --- a/src/SerializedTransaction.cpp +++ b/src/SerializedTransaction.cpp @@ -77,10 +77,9 @@ std::vector SerializedTransaction::getAffectedAccounts() const { bool found = false; RippleAddress na = sa->getValueNCA(); - for (std::vector::iterator it = accounts.begin(), end = accounts.end(); - it != end; ++it) + BOOST_FOREACH(const RippleAddress& it, accounts) { - if (*it == na) + if (it == na) { found = true; break; diff --git a/src/Serializer.cpp b/src/Serializer.cpp index efce6138c..8b67d3b65 100644 --- a/src/Serializer.cpp +++ b/src/Serializer.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "key.h" #include "Log.h" @@ -376,11 +377,13 @@ int Serializer::addTaggedList(const std::list& list) if (size > 255) return -1; int ret = add8(size); if (size != 0) - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) + { + BOOST_FOREACH(const TaggedListItem& it, list) { - add8(it->first); - addVL(it->second); + add8(it.first); + addVL(it.second); } + } return ret; } @@ -390,11 +393,13 @@ int Serializer::addTaggedList(const std::vector& list) if (size > 255) return -1; int ret = add8(size); if (size != 0) - for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) + { + BOOST_FOREACH(const TaggedListItem& it, list) { - add8(it->first); - addVL(it->second); + add8(it.first); + addVL(it.second); } + } return ret; } @@ -404,8 +409,10 @@ int Serializer::getTaggedListLength(const std::list& list) if (size > 255) return -1; int ret = 1; if (size != 0) - for (std::list::const_iterator it = list.begin(); it != list.end(); ++it) - ret += 1 + it->second.size() + Serializer::encodeLengthLength(it->second.size()); + { + BOOST_FOREACH(const TaggedListItem& it, list) + ret += 1 + it.second.size() + Serializer::encodeLengthLength(it.second.size()); + } return ret; } @@ -415,8 +422,10 @@ int Serializer::getTaggedListLength(const std::vector& list) if (size > 255) return -1; int ret = 1; if (size != 0) - for (std::vector::const_iterator it = list.begin(); it != list.end(); ++it) - ret += 1 + it->second.size() + Serializer::encodeLengthLength(it->second.size()); + { + BOOST_FOREACH(const TaggedListItem& it, list) + ret += 1 + it.second.size() + Serializer::encodeLengthLength(it.second.size()); + } return ret; } diff --git a/src/Transaction.cpp b/src/Transaction.cpp index a9f8be1a2..2fca62742 100644 --- a/src/Transaction.cpp +++ b/src/Transaction.cpp @@ -705,7 +705,7 @@ bool Transaction::convertToTransactions(uint32 firstLedgerSeq, uint32 secondLedg std::map >& outMap) { // convert a straight SHAMap payload difference to a transaction difference table // return value: true=ledgers are valid, false=a ledger is invalid - std::map >::const_iterator it; + SHAMap::SHAMapDiff::const_iterator it; for(it = inMap.begin(); it != inMap.end(); ++it) { const uint256& id = it->first;