From b9aa8e0a84d9cde20c40d2ccbc4a346902b46c11 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 22 May 2013 15:09:20 -0700 Subject: [PATCH] Add ripple_basics unity build module --- modules/ripple_basics/ripple_basics.cpp | 50 ++++++++- newcoin.vcxproj | 133 ++++++++++++++++++++---- src/cpp/ripple/Amount.cpp | 70 ++++++------- src/cpp/ripple/AmountRound.cpp | 41 +++----- src/cpp/ripple/HashedObject.cpp | 39 ++++--- src/cpp/ripple/ParseSection.cpp | 7 +- src/cpp/ripple/ProofOfWork.cpp | 38 ++++--- src/cpp/ripple/RangeSet.cpp | 8 +- src/cpp/ripple/SHAMap.cpp | 56 +++++----- src/cpp/ripple/SHAMapNodes.cpp | 12 +-- src/cpp/ripple/SHAMapSync.cpp | 76 +++++++------- 11 files changed, 328 insertions(+), 202 deletions(-) diff --git a/modules/ripple_basics/ripple_basics.cpp b/modules/ripple_basics/ripple_basics.cpp index 23dfb500a5..bfbca4025c 100644 --- a/modules/ripple_basics/ripple_basics.cpp +++ b/modules/ripple_basics/ripple_basics.cpp @@ -24,4 +24,52 @@ #include "ripple_basics.h" -//#include "src/cpp/ripple/Amount.cpp" +// VFALCO: TODO, clean this up +// This is here for Amount*.cpp +#include "src/cpp/ripple/bignum.h" +#if (ULONG_MAX > UINT_MAX) +#define BN_add_word64(bn, word) BN_add_word(bn, word) +#define BN_sub_word64(bn, word) BN_sub_word(bn, word) +#define BN_mul_word64(bn, word) BN_mul_word(bn, word) +#define BN_div_word64(bn, word) BN_div_word(bn, word) +#else +#include "src/cpp/ripple/BigNum64.h" +#endif + +static const uint64 tenTo14 = 100000000000000ull; +static const uint64 tenTo14m1 = tenTo14 - 1; +static const uint64 tenTo17 = tenTo14 * 1000; +static const uint64 tenTo17m1 = tenTo17 - 1; + +// VFALCO: TODO, fix these warnings! +#ifdef _MSC_VER +//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length" +#pragma warning (disable: 4018) // signed/unsigned mismatch +#pragma warning (disable: 4244) // conversion, possible loss of data +#endif + +#include "src/cpp/ripple/Log.cpp" + +#include "src/cpp/ripple/Amount.cpp" +#include "src/cpp/ripple/AmountRound.cpp" +#include "src/cpp/ripple/BitcoinUtil.cpp" // no log +#include "src/cpp/ripple/DeterministicKeys.cpp" +#include "src/cpp/ripple/ECIES.cpp" // no log +#include "src/cpp/ripple/FieldNames.cpp" // no log +#include "src/cpp/ripple/HashedObject.cpp" +#include "src/cpp/ripple/PackedMessage.cpp" // no log +#include "src/cpp/ripple/ParameterTable.cpp" // no log +#include "src/cpp/ripple/ParseSection.cpp" +#include "src/cpp/ripple/PlatRand.cpp" // no log +#include "src/cpp/ripple/ProofOfWork.cpp" +#include "src/cpp/ripple/RangeSet.cpp" +#include "src/cpp/ripple/rfc1751.cpp" // no log +#include "src/cpp/ripple/SHAMap.cpp" +#include "src/cpp/ripple/SHAMapDiff.cpp" // no log +#include "src/cpp/ripple/SHAMapNodes.cpp" // no log +#include "src/cpp/ripple/SHAMapSync.cpp" +#include "src/cpp/ripple/utils.cpp" // no log + +#ifdef _MSC_VER +//#pragma warning (pop) +#endif diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 7c19ffcbbe..51998c117c 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -535,10 +535,25 @@ true true - - + + true + true + true + true + + + true + true + true + true + - + + true + true + true + true + true true @@ -566,16 +581,36 @@ true - - + + true + true + true + true + + + true + true + true + true + true true true true - - + + true + true + true + true + + + true + true + true + true + true @@ -642,7 +677,12 @@ - + + true + true + true + true + @@ -682,9 +722,24 @@ true true - - - + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + @@ -696,16 +751,36 @@ - - - + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + true true true true - + + true + true + true + true + @@ -793,10 +868,30 @@ true true - - - - + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + diff --git a/src/cpp/ripple/Amount.cpp b/src/cpp/ripple/Amount.cpp index 9c1775c711..ec4e45430c 100644 --- a/src/cpp/ripple/Amount.cpp +++ b/src/cpp/ripple/Amount.cpp @@ -14,11 +14,9 @@ #include "SerializedTypes.h" #include "utils.h" -SETUP_LOG(); - uint64 STAmount::uRateOne = STAmount::getRate(STAmount(1), STAmount(1)); -static const uint64 tenTo14 = 100000000000000ull; -static const uint64 tenTo17 = tenTo14 * 1000; + + #if (ULONG_MAX > UINT_MAX) #define BN_add_word64(bn, word) BN_add_word(bn, word) @@ -107,7 +105,7 @@ bool STAmount::bSetJson(const Json::Value& jvSource) } catch (const std::exception& e) { - cLog(lsINFO) + WriteLog (lsINFO, STAmount) << boost::str(boost::format("bSetJson(): caught: %s") % e.what()); @@ -122,7 +120,7 @@ STAmount::STAmount(SField::ref n, const Json::Value& v) if (v.isObject()) { - cLog(lsTRACE) + WriteLog (lsTRACE, STAmount) << boost::str(boost::format("value='%s', currency='%s', issuer='%s'") % v["value"].asString() % v["currency"].asString() @@ -272,7 +270,7 @@ bool STAmount::setValue(const std::string& sAmount) if (!boost::regex_match(sAmount, smMatch, reNumber)) { - cLog(lsWARNING) << "Number not valid: \"" << sAmount << "\""; + WriteLog (lsWARNING, STAmount) << "Number not valid: \"" << sAmount << "\""; return false; } @@ -283,7 +281,7 @@ bool STAmount::setValue(const std::string& sAmount) { if ((smMatch[2].length() + smMatch[4].length()) > 32) { - cLog(lsWARNING) << "Overlong number: " << sAmount; + WriteLog (lsWARNING, STAmount) << "Overlong number: " << sAmount; return false; } @@ -310,11 +308,11 @@ bool STAmount::setValue(const std::string& sAmount) } catch (...) { - cLog(lsWARNING) << "Number not parsed: \"" << sAmount << "\""; + WriteLog (lsWARNING, STAmount) << "Number not parsed: \"" << sAmount << "\""; return false; } - cLog(lsTRACE) << "Float \"" << sAmount << "\" parsed to " << mValue << " : " << mOffset; + WriteLog (lsTRACE, STAmount) << "Float \"" << sAmount << "\" parsed to " << mValue << " : " << mOffset; if (mIsNative) { @@ -351,7 +349,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // if (!currencyFromString(mCurrency, sCurrency)) { - cLog(lsINFO) << "Currency malformed: " << sCurrency; + WriteLog (lsINFO, STAmount) << "Currency malformed: " << sCurrency; return false; } @@ -366,7 +364,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // Issuer must be "" or a valid account string. if (!naIssuerID.setAccountID(sIssuer)) { - cLog(lsINFO) << "Issuer malformed: " << sIssuer; + WriteLog (lsINFO, STAmount) << "Issuer malformed: " << sIssuer; return false; } @@ -376,7 +374,7 @@ bool STAmount::setFullValue(const std::string& sAmount, const std::string& sCurr // Stamps not must have an issuer. if (mIsNative && !mIssuer.isZero()) { - cLog(lsINFO) << "Issuer specified for XRP: " << sIssuer; + WriteLog (lsINFO, STAmount) << "Issuer specified for XRP: " << sIssuer; return false; } @@ -1034,17 +1032,17 @@ bool STAmount::applyOffer( ? saOfferFunds // As is. : STAmount::divide(saOfferFunds, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uOfferPaysRate, -9)); // Reduce by offer fees. - cLog(lsINFO) << "applyOffer: uOfferPaysRate=" << uOfferPaysRate; - cLog(lsINFO) << "applyOffer: saOfferFundsAvailable=" << saOfferFundsAvailable.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: uOfferPaysRate=" << uOfferPaysRate; + WriteLog (lsINFO, STAmount) << "applyOffer: saOfferFundsAvailable=" << saOfferFundsAvailable.getFullText(); // Limit taker funds available, by transfer fees. STAmount saTakerFundsAvailable = QUALITY_ONE == uTakerPaysRate ? saTakerFunds // As is. : STAmount::divide(saTakerFunds, STAmount(CURRENCY_ONE, ACCOUNT_ONE, uTakerPaysRate, -9)); // Reduce by taker fees. - cLog(lsINFO) << "applyOffer: TAKER_FEES=" << STAmount(CURRENCY_ONE, ACCOUNT_ONE, uTakerPaysRate, -9).getFullText(); - cLog(lsINFO) << "applyOffer: uTakerPaysRate=" << uTakerPaysRate; - cLog(lsINFO) << "applyOffer: saTakerFundsAvailable=" << saTakerFundsAvailable.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: TAKER_FEES=" << STAmount(CURRENCY_ONE, ACCOUNT_ONE, uTakerPaysRate, -9).getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: uTakerPaysRate=" << uTakerPaysRate; + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerFundsAvailable=" << saTakerFundsAvailable.getFullText(); STAmount saOfferPaysAvailable; // Amount offer can pay out, limited by offer and offerer funds. STAmount saOfferGetsAvailable; // Amount offer would get, limited by offer funds. @@ -1064,24 +1062,24 @@ bool STAmount::applyOffer( saOfferGetsAvailable = std::min(saOfferGets, mulRound(saOfferPaysAvailable, saOfferRate, saOfferGets, true)); } - cLog(lsINFO) << "applyOffer: saOfferPaysAvailable=" << saOfferFundsAvailable.getFullText(); - cLog(lsINFO) << "applyOffer: saOfferGetsAvailable=" << saOfferGetsAvailable.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saOfferPaysAvailable=" << saOfferFundsAvailable.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saOfferGetsAvailable=" << saOfferGetsAvailable.getFullText(); STAmount saTakerPaysAvailable = std::min(saTakerPays, saTakerFundsAvailable); - cLog(lsINFO) << "applyOffer: saTakerPaysAvailable=" << saTakerPaysAvailable.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerPaysAvailable=" << saTakerPaysAvailable.getFullText(); // Limited = limited by other sides raw numbers. // Taker can't pay more to offer than offer can get. STAmount saTakerPaysLimited = std::min(saTakerPaysAvailable, saOfferGetsAvailable); - cLog(lsINFO) << "applyOffer: saTakerPaysLimited=" << saTakerPaysLimited.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerPaysLimited=" << saTakerPaysLimited.getFullText(); // Align saTakerGetsLimited with saTakerPaysLimited. STAmount saTakerGetsLimited = saTakerPaysLimited >= saOfferGetsAvailable ? saOfferPaysAvailable // Potentially take entire offer. Avoid math shenanigans. : std::min(saOfferPaysAvailable, divRound(saTakerPaysLimited, saOfferRate, saTakerGets, true)); // Taker a portion of offer. - cLog(lsINFO) << "applyOffer: saOfferRate=" << saOfferRate.getFullText(); - cLog(lsINFO) << "applyOffer: saTakerGetsLimited=" << saTakerGetsLimited.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saOfferRate=" << saOfferRate.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerGetsLimited=" << saTakerGetsLimited.getFullText(); // Got & Paid = Calculated by price and transfered without fees. // Compute from got as when !bSell, we want got to be exact to finish off offer if possible. @@ -1094,8 +1092,8 @@ bool STAmount::applyOffer( : std::min(saOfferGetsAvailable, mulRound(saTakerGot, saOfferRate, saTakerFunds, true)); saTakerPaid = std::min(saTakerPaid, saTakerPaysAvailable); // Due to rounding must clamp. - cLog(lsINFO) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); - cLog(lsINFO) << "applyOffer: saTakerPaid=" << saTakerPaid.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerPaid=" << saTakerPaid.getFullText(); if (uTakerPaysRate == QUALITY_ONE) { @@ -1106,17 +1104,17 @@ bool STAmount::applyOffer( // Compute fees in a rounding safe way. STAmount saTransferRate = STAmount(CURRENCY_ONE, ACCOUNT_ONE, uTakerPaysRate, -9); - cLog(lsINFO) << "applyOffer: saTransferRate=" << saTransferRate.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTransferRate=" << saTransferRate.getFullText(); // TakerCost includes transfer fees. STAmount saTakerCost = STAmount::mulRound(saTakerPaid, saTransferRate, true); - cLog(lsINFO) << "applyOffer: saTakerCost=" << saTakerCost.getFullText(); - cLog(lsINFO) << "applyOffer: saTakerFunds=" << saTakerFunds.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerCost=" << saTakerCost.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerFunds=" << saTakerFunds.getFullText(); saTakerIssuerFee = saTakerCost > saTakerFunds ? saTakerFunds-saTakerPaid // Not enough funds to cover fee, stiff issuer the rounding error. : saTakerCost-saTakerPaid; - cLog(lsINFO) << "applyOffer: saTakerIssuerFee=" << saTakerIssuerFee.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerIssuerFee=" << saTakerIssuerFee.getFullText(); assert(!saTakerIssuerFee.isNegative()); } @@ -1134,7 +1132,7 @@ bool STAmount::applyOffer( : saOfferCost-saTakerGot; } - cLog(lsINFO) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); + WriteLog (lsINFO, STAmount) << "applyOffer: saTakerGot=" << saTakerGot.getFullText(); return saTakerGot >= saOfferPaysAvailable; // True, if consumed offer. } @@ -1436,7 +1434,7 @@ BOOST_AUTO_TEST_CASE( CustomCurrency_test ) BOOST_FAIL("STAmount multiply fail 4"); if (STAmount::divide(STAmount(CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount(3), CURRENCY_ONE, ACCOUNT_ONE).getText() != "20") { - cLog(lsFATAL) << "60/3 = " << + WriteLog (lsFATAL, STAmount) << "60/3 = " << STAmount::divide(STAmount(CURRENCY_ONE, ACCOUNT_ONE, 60), STAmount(3), CURRENCY_ONE, ACCOUNT_ONE).getText(); BOOST_FAIL("STAmount divide fail"); @@ -1475,7 +1473,7 @@ static bool roundTest(int n, int d, int m) if (res == cmp) return true; cmp.throwComparable(res); - cLog(lsWARNING) << "(" << num.getText() << "/" << den.getText() << ") X " << mul.getText() << " = " + WriteLog (lsWARNING, STAmount) << "(" << num.getText() << "/" << den.getText() << ") X " << mul.getText() << " = " << res.getText() << " not " << cmp.getText(); BOOST_FAIL("Round fail"); return false; @@ -1492,7 +1490,7 @@ static void mulTest(int a, int b) STAmount prod2(CURRENCY_ONE, ACCOUNT_ONE, static_cast(a) * static_cast(b)); if (prod1 != prod2) { - cLog(lsWARNING) << "nn(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() + WriteLog (lsWARNING, STAmount) << "nn(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() << " not " << prod2.getFullText(); BOOST_WARN("Multiplication result is not exact"); } @@ -1500,7 +1498,7 @@ static void mulTest(int a, int b) prod1 = STAmount::multiply(aa, bb, CURRENCY_ONE, ACCOUNT_ONE); if (prod1 != prod2) { - cLog(lsWARNING) << "n(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() + WriteLog (lsWARNING, STAmount) << "n(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText() << " not " << prod2.getFullText(); BOOST_WARN("Multiplication result is not exact"); } @@ -1518,7 +1516,7 @@ BOOST_AUTO_TEST_CASE( CurrencyMulDivTests ) b.setuint64(r); if (b.getuint64() != r) { - cLog(lsFATAL) << r << " != " << b.getuint64() << " " << b.ToString(16); + WriteLog (lsFATAL, STAmount) << r << " != " << b.getuint64() << " " << b.ToString(16); BOOST_FAIL("setull64/getull64 failure"); } } diff --git a/src/cpp/ripple/AmountRound.cpp b/src/cpp/ripple/AmountRound.cpp index 9e02fb23e0..39d6a162a3 100644 --- a/src/cpp/ripple/AmountRound.cpp +++ b/src/cpp/ripple/AmountRound.cpp @@ -4,8 +4,6 @@ #include "SerializedTypes.h" #include "Log.h" -SETUP_LOG(); - #if (ULONG_MAX > UINT_MAX) #define BN_add_word64(bn, word) BN_add_word(bn, word) #define BN_sub_word64(bn, word) BN_sub_word(bn, word) @@ -15,11 +13,6 @@ SETUP_LOG(); #include "BigNum64.h" #endif -static const uint64 tenTo14 = 100000000000000ull; -static const uint64 tenTo14m1 = tenTo14 - 1; -static const uint64 tenTo17 = tenTo14 * 1000; -static const uint64 tenTo17m1 = tenTo17 - 1; - // CAUTION: This is early code and is *NOT* ready for real use yet. static void canonicalizeRound(bool isNative, uint64& value, int& offset, bool roundUp) @@ -27,7 +20,7 @@ static void canonicalizeRound(bool isNative, uint64& value, int& offset, bool ro if (!roundUp) // canonicalize already rounds down return; - cLog(lsTRACE) << "canonicalize< " << value << ":" << offset << (roundUp ? " up" : " down"); + WriteLog (lsTRACE, STAmount) << "canonicalize< " << value << ":" << offset << (roundUp ? " up" : " down"); if (isNative) { if (offset < 0) @@ -55,7 +48,7 @@ static void canonicalizeRound(bool isNative, uint64& value, int& offset, bool ro value /= 10; ++offset; } - cLog(lsTRACE) << "canonicalize> " << value << ":" << offset << (roundUp ? " up" : " down"); + WriteLog (lsTRACE, STAmount) << "canonicalize> " << value << ":" << offset << (roundUp ? " up" : " down"); } STAmount STAmount::addRound(const STAmount& v1, const STAmount& v2, bool roundUp) @@ -307,37 +300,37 @@ BOOST_AUTO_TEST_CASE( amountRound_test ) STAmount oneThird1 = STAmount::divRound(one, three, CURRENCY_ONE, ACCOUNT_ONE, false); STAmount oneThird2 = STAmount::divide(one, three, CURRENCY_ONE, ACCOUNT_ONE); STAmount oneThird3 = STAmount::divRound(one, three, CURRENCY_ONE, ACCOUNT_ONE, true); - cLog(lsINFO) << oneThird1; - cLog(lsINFO) << oneThird2; - cLog(lsINFO) << oneThird3; + WriteLog (lsINFO, STAmount) << oneThird1; + WriteLog (lsINFO, STAmount) << oneThird2; + WriteLog (lsINFO, STAmount) << oneThird3; STAmount twoThird1 = STAmount::divRound(two, three, CURRENCY_ONE, ACCOUNT_ONE, false); STAmount twoThird2 = STAmount::divide(two, three, CURRENCY_ONE, ACCOUNT_ONE); STAmount twoThird3 = STAmount::divRound(two, three, CURRENCY_ONE, ACCOUNT_ONE, true); - cLog(lsINFO) << twoThird1; - cLog(lsINFO) << twoThird2; - cLog(lsINFO) << twoThird3; + WriteLog (lsINFO, STAmount) << twoThird1; + WriteLog (lsINFO, STAmount) << twoThird2; + WriteLog (lsINFO, STAmount) << twoThird3; STAmount oneA = STAmount::mulRound(oneThird1, three, CURRENCY_ONE, ACCOUNT_ONE, false); STAmount oneB = STAmount::multiply(oneThird2, three, CURRENCY_ONE, ACCOUNT_ONE); STAmount oneC = STAmount::mulRound(oneThird3, three, CURRENCY_ONE, ACCOUNT_ONE, true); - cLog(lsINFO) << oneA; - cLog(lsINFO) << oneB; - cLog(lsINFO) << oneC; + WriteLog (lsINFO, STAmount) << oneA; + WriteLog (lsINFO, STAmount) << oneB; + WriteLog (lsINFO, STAmount) << oneC; STAmount fourThirdsA = STAmount::addRound(twoThird2, twoThird2, false); STAmount fourThirdsB = twoThird2 + twoThird2; STAmount fourThirdsC = STAmount::addRound(twoThird2, twoThird2, true); - cLog(lsINFO) << fourThirdsA; - cLog(lsINFO) << fourThirdsB; - cLog(lsINFO) << fourThirdsC; + WriteLog (lsINFO, STAmount) << fourThirdsA; + WriteLog (lsINFO, STAmount) << fourThirdsB; + WriteLog (lsINFO, STAmount) << fourThirdsC; STAmount dripTest1 = STAmount::mulRound(twoThird2, two, uint160(), uint160(), false); STAmount dripTest2 = STAmount::multiply(twoThird2, two, uint160(), uint160()); STAmount dripTest3 = STAmount::mulRound(twoThird2, two, uint160(), uint160(), true); - cLog(lsINFO) << dripTest1; - cLog(lsINFO) << dripTest2; - cLog(lsINFO) << dripTest3; + WriteLog (lsINFO, STAmount) << dripTest1; + WriteLog (lsINFO, STAmount) << dripTest2; + WriteLog (lsINFO, STAmount) << dripTest3; } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index 03bb62415c..8c71b57861 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -14,7 +14,6 @@ #include "Application.h" #include "Log.h" -SETUP_LOG(); DECLARE_INSTANCE(HashedObject); HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) : @@ -29,13 +28,13 @@ HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) : mLevelDB = false; else { - cLog(lsFATAL) << "Incorrect database selection"; + WriteLog (lsFATAL, HashedObject) << "Incorrect database selection"; assert(false); } #ifndef USE_LEVELDB if (mLevelDB) { - cLog(lsFATAL) << "LevelDB has been selected but not compiled"; + WriteLog (lsFATAL) << "LevelDB has been selected but not compiled"; assert(false); } #endif @@ -140,7 +139,7 @@ void HashedObjectStore::bulkWriteLevelDB(Job &) leveldb::Status st = theApp->getHashNodeLDB()->Write(leveldb::WriteOptions(), &batch); if (!st.ok()) { - cLog(lsFATAL) << "Failed to store hash node"; + WriteLog (lsFATAL, HashedObject) << "Failed to store hash node"; assert(false); } } @@ -174,7 +173,7 @@ HashedObject::pointer HashedObjectStore::retrieveLevelDB(const uint256& hash) bufPtr + 9, sData.size() - 9, hash); mCache.canonicalize(hash, obj); - cLog(lsTRACE) << "HOS: " << hash << " fetch: in db"; + WriteLog (lsTRACE, HashedObject) << "HOS: " << hash << " fetch: in db"; return obj; } @@ -185,12 +184,12 @@ bool HashedObjectStore::storeSQLite(HashedObjectType type, uint32 index, { // return: false = already in cache, true = added to cache if (!theApp->getHashNodeDB()) { - cLog(lsTRACE) << "HOS: no db"; + WriteLog (lsTRACE, HashedObject) << "HOS: no db"; return true; } if (mCache.touch(hash)) { - cLog(lsTRACE) << "HOS: " << hash << " store: incache"; + WriteLog (lsTRACE, HashedObject) << "HOS: " << hash << " store: incache"; return false; } assert(hash == Serializer::getSHA512Half(data)); @@ -198,7 +197,7 @@ bool HashedObjectStore::storeSQLite(HashedObjectType type, uint32 index, HashedObject::pointer object = boost::make_shared(type, index, data, hash); if (!mCache.canonicalize(hash, object)) { -// cLog(lsTRACE) << "Queuing write for " << hash; +// WriteLog (lsTRACE, HashedObject) << "Queuing write for " << hash; boost::mutex::scoped_lock sl(mWriteMutex); mWriteSet.push_back(object); if (!mWritePending) @@ -209,7 +208,7 @@ bool HashedObjectStore::storeSQLite(HashedObjectType type, uint32 index, } } // else -// cLog(lsTRACE) << "HOS: already had " << hash; +// WriteLog (lsTRACE, HashedObject) << "HOS: already had " << hash; mNegativeCache.del(hash); return true; } @@ -234,7 +233,7 @@ void HashedObjectStore::bulkWriteSQLite(Job&) return; } } -// cLog(lsTRACE) << "HOS: writing " << set.size(); +// WriteLog (lsTRACE, HashedObject) << "HOS: writing " << set.size(); #ifndef NO_SQLITE3_PREPARE @@ -269,7 +268,7 @@ void HashedObjectStore::bulkWriteSQLite(Job&) int ret = pSt.step(); if (!pSt.isDone(ret)) { - cLog(lsFATAL) << "Error saving hashed object " << ret; + WriteLog (lsFATAL, HashedObject) << "Error saving hashed object " << ret; assert(false); } pSt.reset(); @@ -343,7 +342,7 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash) { pSt.reset(); mNegativeCache.add(hash); - cLog(lsTRACE) << "HOS: " << hash <<" fetch: not in db"; + WriteLog (lsTRACE, HashedObject) << "HOS: " << hash <<" fetch: not in db"; return obj; } @@ -394,7 +393,7 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash) case 'N': htype = hotTRANSACTION_NODE; break; default: assert(false); - cLog(lsERROR) << "Invalid hashed object"; + WriteLog (lsERROR, HashedObject) << "Invalid hashed object"; mNegativeCache.add(hash); return obj; } @@ -402,7 +401,7 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash) obj = boost::make_shared(htype, index, data, hash); mCache.canonicalize(hash, obj); - cLog(lsTRACE) << "HOS: " << hash << " fetch: in db"; + WriteLog (lsTRACE, HashedObject) << "HOS: " << hash << " fetch: in db"; return obj; } @@ -410,7 +409,7 @@ HashedObject::pointer HashedObjectStore::retrieveSQLite(const uint256& hash) int HashedObjectStore::import(const std::string& file) { - cLog(lsWARNING) << "Hashed object import from \"" << file << "\"."; + WriteLog (lsWARNING, HashedObject) << "Hashed object import from \"" << file << "\"."; UPTR_T importDB(new SqliteDatabase(file.c_str())); importDB->connect(); @@ -427,7 +426,7 @@ int HashedObjectStore::import(const std::string& file) hash.SetHexExact(hashStr); if (hash.isZero()) { - cLog(lsWARNING) << "zero hash found in import table"; + WriteLog (lsWARNING, HashedObject) << "zero hash found in import table"; } else { @@ -453,7 +452,7 @@ int HashedObjectStore::import(const std::string& file) case 'N': htype = hotTRANSACTION_NODE; break; default: assert(false); - cLog(lsERROR) << "Invalid hashed object"; + WriteLog (lsERROR, HashedObject) << "Invalid hashed object"; } *(bufPtr + 8) = static_cast(htype); @@ -462,18 +461,18 @@ int HashedObjectStore::import(const std::string& file) leveldb::Slice(reinterpret_cast(bufPtr), rawData.size())); if (!st.ok()) { - cLog(lsFATAL) << "Failed to store hash node"; + WriteLog (lsFATAL, HashedObject) << "Failed to store hash node"; assert(false); } ++count; } if ((count % 10000) == 0) { - cLog(lsINFO) << "Import in progress: " << count; + WriteLog (lsINFO, HashedObject) << "Import in progress: " << count; } } - cLog(lsWARNING) << "Imported " << count << " nodes"; + WriteLog (lsWARNING, HashedObject) << "Imported " << count << " nodes"; return count; } diff --git a/src/cpp/ripple/ParseSection.cpp b/src/cpp/ripple/ParseSection.cpp index 12bdded4b7..8be2648f63 100644 --- a/src/cpp/ripple/ParseSection.cpp +++ b/src/cpp/ripple/ParseSection.cpp @@ -8,7 +8,10 @@ #define SECTION_DEFAULT_NAME "" -SETUP_LOG(); +// for logging +struct ParseSectionLog +{ +}; section ParseSection(const std::string& strInput, const bool bTrim) { @@ -118,7 +121,7 @@ bool sectionSingleB(section& secSource, const std::string& strSection, std::stri } else if (pmtEntries) { - cLog(lsWARNING) << boost::str(boost::format("Section [%s]: requires 1 line not %d lines.") + WriteLog (lsWARNING, ParseSectionLog) << boost::str(boost::format("Section [%s]: requires 1 line not %d lines.") % strSection % pmtEntries->size()); } diff --git a/src/cpp/ripple/ProofOfWork.cpp b/src/cpp/ripple/ProofOfWork.cpp index b38a23ab91..16368f3267 100644 --- a/src/cpp/ripple/ProofOfWork.cpp +++ b/src/cpp/ripple/ProofOfWork.cpp @@ -12,8 +12,6 @@ #include "Serializer.h" #include "Log.h" -SETUP_LOG(); - bool powResultInfo(POWResult powCode, std::string& strToken, std::string& strHuman) { @@ -66,7 +64,7 @@ bool ProofOfWork::isValid() const { if ((mIterations <= sMaxIterations) && (mTarget >= sMinTarget)) return true; - cLog(lsWARNING) << "Invalid PoW: " << mIterations << ", " << mTarget; + WriteLog (lsWARNING, ProofOfWork) << "Invalid PoW: " << mIterations << ", " << mTarget; return false; } @@ -74,10 +72,10 @@ uint64 ProofOfWork::getDifficulty(const uint256& target, int iterations) { // calculate the approximate number of hashes required to solve this proof of work if ((iterations > sMaxIterations) || (target < sMinTarget)) { - cLog(lsINFO) << "Iterations:" << iterations; - cLog(lsINFO) << "MaxIterat: " << sMaxIterations; - cLog(lsINFO) << "Target: " << target; - cLog(lsINFO) << "MinTarget: " << sMinTarget; + WriteLog (lsINFO, ProofOfWork) << "Iterations:" << iterations; + WriteLog (lsINFO, ProofOfWork) << "MaxIterat: " << sMaxIterations; + WriteLog (lsINFO, ProofOfWork) << "Target: " << target; + WriteLog (lsINFO, ProofOfWork) << "MinTarget: " << sMinTarget; throw std::runtime_error("invalid proof of work target/iteration"); } @@ -195,14 +193,14 @@ POWResult ProofOfWorkGenerator::checkProof(const std::string& token, const uint2 boost::split(fields, token, boost::algorithm::is_any_of("-")); if (fields.size() != 5) { - cLog(lsDEBUG) << "PoW " << token << " is corrupt"; + WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " is corrupt"; return powCORRUPT; } std::string v = mSecret.GetHex() + fields[0] + "-" + fields[1] + "-" + fields[2] + "-" + fields[3]; if (fields[4] != Serializer::getSHA512Half(v).GetHex()) { - cLog(lsDEBUG) << "PoW " << token << " has a bad token"; + WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad token"; return powCORRUPT; } @@ -219,13 +217,13 @@ POWResult ProofOfWorkGenerator::checkProof(const std::string& token, const uint2 boost::mutex::scoped_lock sl(mLock); if ((t * 4) > (now + mValidTime)) { - cLog(lsDEBUG) << "PoW " << token << " has expired"; + WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has expired"; return powEXPIRED; } if (((iterations != mIterations) || (target != mTarget)) && getPowEntry(target, iterations) < (mPowEntry - 2)) { // difficulty has increased more than two times since PoW requested - cLog(lsINFO) << "Difficulty has increased since PoW requested"; + WriteLog (lsINFO, ProofOfWork) << "Difficulty has increased since PoW requested"; return powTOOEASY; } } @@ -233,7 +231,7 @@ POWResult ProofOfWorkGenerator::checkProof(const std::string& token, const uint2 ProofOfWork pow(token, iterations, challenge, target); if (!pow.checkSolution(solution)) { - cLog(lsDEBUG) << "PoW " << token << " has a bad nonce"; + WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad nonce"; return powBADNONCE; } @@ -241,7 +239,7 @@ POWResult ProofOfWorkGenerator::checkProof(const std::string& token, const uint2 boost::mutex::scoped_lock sl(mLock); if (!mSolvedChallenges.insert(powMap_vt(now, challenge)).second) { - cLog(lsDEBUG) << "PoW " << token << " has been reused"; + WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has been reused"; return powREUSED; } } @@ -370,14 +368,14 @@ BOOST_AUTO_TEST_CASE( ProofOfWork_test ) { ProofOfWorkGenerator gen; ProofOfWork pow = gen.getProof(); - cLog(lsINFO) << "Estimated difficulty: " << pow.getDifficulty(); + WriteLog (lsINFO, ProofOfWork) << "Estimated difficulty: " << pow.getDifficulty(); uint256 solution = pow.solve(16777216); if (solution.isZero()) BOOST_FAIL("Unable to solve proof of work"); if (!pow.checkSolution(solution)) BOOST_FAIL("Solution did not check"); - cLog(lsDEBUG) << "A bad nonce error is expected"; + WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected"; POWResult r = gen.checkProof(pow.getToken(), uint256()); if (r != powBADNONCE) { @@ -386,7 +384,7 @@ BOOST_AUTO_TEST_CASE( ProofOfWork_test ) } if (gen.checkProof(pow.getToken(), solution) != powOK) BOOST_FAIL("Solution did not check with issuer"); - cLog(lsDEBUG) << "A reused nonce error is expected"; + WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected"; if (gen.checkProof(pow.getToken(), solution) != powREUSED) BOOST_FAIL("Reuse solution not detected"); @@ -395,16 +393,16 @@ BOOST_AUTO_TEST_CASE( ProofOfWork_test ) { gen.setDifficulty(i); ProofOfWork pow = gen.getProof(); - cLog(lsINFO) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty(); + WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty(); uint256 solution = pow.solve(131072); if (solution.isZero()) - cLog(lsINFO) << "Giving up"; + WriteLog (lsINFO, ProofOfWork) << "Giving up"; else { - cLog(lsINFO) << "Solution found"; + WriteLog (lsINFO, ProofOfWork) << "Solution found"; if (gen.checkProof(pow.getToken(), solution) != powOK) { - cLog(lsFATAL) << "Solution fails"; + WriteLog (lsFATAL, ProofOfWork) << "Solution fails"; } } } diff --git a/src/cpp/ripple/RangeSet.cpp b/src/cpp/ripple/RangeSet.cpp index 43d468807b..93a471a849 100644 --- a/src/cpp/ripple/RangeSet.cpp +++ b/src/cpp/ripple/RangeSet.cpp @@ -6,8 +6,6 @@ #include "Log.h" -SETUP_LOG(); - inline uint32 min(uint32 x, uint32 y) { return (x < y) ? x : y; } inline uint32 max(uint32 x, uint32 y) { return (x > y) ? x : y; } @@ -54,7 +52,7 @@ uint32 RangeSet::getPrev(uint32 v) const uint32 RangeSet::prevMissing(uint32 v) const { // largest number not in the set that is less than the given number - cLog(lsTRACE) << "prevMissing(" << v << ") " << toString(); + WriteLog (lsTRACE, RangeSet) << "prevMissing(" << v << ") " << toString(); for (const_reverse_iterator it = rbegin(); it != rend(); ++it) { if ((upper(it) + 1) < v) @@ -111,7 +109,7 @@ BOOST_AUTO_TEST_SUITE(RangeSet_suite) BOOST_AUTO_TEST_CASE(RangeSet_test) { - cLog(lsTRACE) << "RangeSet test begins"; + WriteLog (lsTRACE, RangeSet) << "RangeSet test begins"; RangeSet r1, r2; @@ -127,7 +125,7 @@ BOOST_AUTO_TEST_CASE(RangeSet_test) // TODO: Traverse functions must be tested - cLog(lsTRACE) << "RangeSet test complete"; + WriteLog (lsTRACE, RangeSet) << "RangeSet test complete"; } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index 7ac25fe968..8e9bcfb899 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -19,8 +19,6 @@ #define STATE_MAP_BUCKETS 1024 #endif -SETUP_LOG(); - DECLARE_INSTANCE(SHAMap); DECLARE_INSTANCE(SHAMapItem); DECLARE_INSTANCE(SHAMapTreeNode); @@ -140,12 +138,12 @@ void SHAMap::dirtyUp(std::stack& stack, const uint256& if (!node->setChildHash(branch, prevHash)) { - cLog(lsFATAL) << "dirtyUp terminates early"; + WriteLog (lsFATAL, SHAMap) << "dirtyUp terminates early"; assert(false); return; } #ifdef ST_DEBUG - cLog(lsTRACE) << "dirtyUp sets branch " << branch << " to " << prevHash; + WriteLog (lsTRACE, SHAMap) << "dirtyUp sets branch " << branch << " to " << prevHash; #endif prevHash = node->getNodeHash(); assert(prevHash.isNonZero()); @@ -213,10 +211,10 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has #ifdef DEBUG if (node->getNodeHash() != hash) { - cLog(lsFATAL) << "Attempt to get node, hash not in tree"; - cLog(lsFATAL) << "ID: " << id; - cLog(lsFATAL) << "TgtHash " << hash; - cLog(lsFATAL) << "NodHash " << node->getNodeHash(); + WriteLog (lsFATAL, SHAMap) << "Attempt to get node, hash not in tree"; + WriteLog (lsFATAL, SHAMap) << "ID: " << id; + WriteLog (lsFATAL, SHAMap) << "TgtHash " << hash; + WriteLog (lsFATAL, SHAMap) << "NodHash " << node->getNodeHash(); throw std::runtime_error("invalid node"); } #endif @@ -351,7 +349,7 @@ SHAMapItem::pointer SHAMap::onlyBelow(SHAMapTreeNode* node) if (!nextNode) { - cLog(lsFATAL) << *node; + WriteLog (lsFATAL, SHAMap) << *node; assert(false); return SHAMapItem::pointer(); } @@ -620,8 +618,8 @@ bool SHAMap::addGiveItem(SHAMapItem::ref item, bool isTransaction, bool hasMeta) boost::make_shared(node->getChildNodeID(branch), item, type, mSeq); if (!mTNByID.emplace(SHAMapNode(*newNode), newNode).second) { - cLog(lsFATAL) << "Node: " << *node; - cLog(lsFATAL) << "NewNode: " << *newNode; + WriteLog (lsFATAL, SHAMap) << "Node: " << *node; + WriteLog (lsFATAL, SHAMap) << "NewNode: " << *newNode; dump(); assert(false); throw std::runtime_error("invalid inner node"); @@ -701,7 +699,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::ref item, bool isTransaction, bool hasMe if (!node->setItem(item, !isTransaction ? SHAMapTreeNode::tnACCOUNT_STATE : (hasMeta ? SHAMapTreeNode::tnTRANSACTION_MD : SHAMapTreeNode::tnTRANSACTION_NM))) { - cLog(lsWARNING) << "SHAMap setItem, no change"; + WriteLog (lsWARNING, SHAMap) << "SHAMap setItem, no change"; return true; } @@ -711,7 +709,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::ref item, bool isTransaction, bool hasMe void SHAMapItem::dump() { - cLog(lsINFO) << "SHAMapItem(" << mTag << ") " << mData.size() << "bytes"; + WriteLog (lsINFO, SHAMap) << "SHAMapItem(" << mTag << ") " << mData.size() << "bytes"; } SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const uint256& hash) @@ -722,7 +720,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui HashedObject::pointer obj(theApp->getHashedObjectStore().retrieve(hash)); if (!obj) { -// cLog(lsTRACE) << "fetchNodeExternal: missing " << hash; +// WriteLog (lsTRACE, SHAMap) << "fetchNodeExternal: missing " << hash; if (mLedgerSeq != 0) { theApp->getOPs().missingNodeInLedger(mLedgerSeq); @@ -737,13 +735,13 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui boost::make_shared(id, obj->getData(), mSeq, snfPREFIX, hash, true); if (id != *ret) { - cLog(lsFATAL) << "id:" << id << ", got:" << *ret; + WriteLog (lsFATAL, SHAMap) << "id:" << id << ", got:" << *ret; assert(false); return SHAMapTreeNode::pointer(); } if (ret->getNodeHash() != hash) { - cLog(lsFATAL) << "Hashes don't match"; + WriteLog (lsFATAL, SHAMap) << "Hashes don't match"; assert(false); return SHAMapTreeNode::pointer(); } @@ -756,7 +754,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui } catch (...) { - cLog(lsWARNING) << "fetchNodeExternal gets an invalid node: " << hash; + WriteLog (lsWARNING, SHAMap) << "fetchNodeExternal gets an invalid node: " << hash; throw SHAMapMissingNode(mType, id, hash); } } @@ -765,14 +763,14 @@ void SHAMap::fetchRoot(const uint256& hash, SHAMapSyncFilter* filter) { if (hash == root->getNodeHash()) return; - if (sLog(lsTRACE)) + if (ShouldLog (lsTRACE, SHAMap)) { if (mType == smtTRANSACTION) - cLog(lsTRACE) << "Fetch root TXN node " << hash; + WriteLog (lsTRACE, SHAMap) << "Fetch root TXN node " << hash; else if (mType == smtSTATE) - cLog(lsTRACE) << "Fetch root STATE node " << hash; + WriteLog (lsTRACE, SHAMap) << "Fetch root STATE node " << hash; else - cLog(lsTRACE) << "Fetch root SHAMap node " << hash; + WriteLog (lsTRACE, SHAMap) << "Fetch root SHAMap node " << hash; } try { @@ -812,9 +810,9 @@ int SHAMap::flushDirty(SHADirtyMap& map, int maxNodes, HashedObjectType t, uint3 #ifdef DEBUG if (s.getSHA512Half() != it->second->getNodeHash()) { - cLog(lsFATAL) << *(it->second); - cLog(lsFATAL) << lexical_cast_i(s.getDataLength()); - cLog(lsFATAL) << s.getSHA512Half() << " != " << it->second->getNodeHash(); + WriteLog (lsFATAL, SHAMap) << *(it->second); + WriteLog (lsFATAL, SHAMap) << lexical_cast_i(s.getDataLength()); + WriteLog (lsFATAL, SHAMap) << s.getSHA512Half() << " != " << it->second->getNodeHash(); assert(false); } #endif @@ -908,13 +906,13 @@ void SHAMap::dropBelow(SHAMapTreeNode* d) void SHAMap::dump(bool hash) { - cLog(lsINFO) << " MAP Contains"; + WriteLog (lsINFO, SHAMap) << " MAP Contains"; boost::recursive_mutex::scoped_lock sl(mLock); for(boost::unordered_map::iterator it = mTNByID.begin(); it != mTNByID.end(); ++it) { - cLog(lsINFO) << it->second->getString(); - tLog(hash, lsINFO) << it->second->getNodeHash(); + WriteLog (lsINFO, SHAMap) << it->second->getString(); + CondLog (hash, lsINFO, SHAMap) << it->second->getNodeHash(); } } @@ -931,7 +929,7 @@ BOOST_AUTO_TEST_SUITE(SHAMap_suite) BOOST_AUTO_TEST_CASE( SHAMap_test ) { // h3 and h4 differ only in the leaf, same terminal node (level 19) - cLog(lsTRACE) << "SHAMap test"; + WriteLog (lsTRACE, SHAMap) << "SHAMap test"; uint256 h1, h2, h3, h4, h5; h1.SetHex("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); h2.SetHex("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe"); @@ -967,7 +965,7 @@ BOOST_AUTO_TEST_CASE( SHAMap_test ) i = sMap.peekNextItem(i->getTag()); if (i) BOOST_FAIL("bad traverse"); - cLog(lsTRACE) << "SHAMap snap test"; + WriteLog (lsTRACE, SHAMap) << "SHAMap snap test"; uint256 mapHash = sMap.getHash(); SHAMap::pointer map2 = sMap.snapShot(false); if (sMap.getHash() != mapHash) BOOST_FAIL("bad snapshot"); diff --git a/src/cpp/ripple/SHAMapNodes.cpp b/src/cpp/ripple/SHAMapNodes.cpp index 1719b3d50f..cc25e65c07 100644 --- a/src/cpp/ripple/SHAMapNodes.cpp +++ b/src/cpp/ripple/SHAMapNodes.cpp @@ -16,8 +16,6 @@ #include "Log.h" #include "HashPrefixes.h" -SETUP_LOG(); - std::string SHAMapNode::getString() const { static boost::format NodeID("NodeID(%s,%s)"); @@ -152,7 +150,7 @@ int SHAMapNode::selectBranch(const uint256& hash) const void SHAMapNode::dump() const { - cLog(lsDEBUG) << getString(); + WriteLog (lsDEBUG, SHAMapNode) << getString(); } SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0), @@ -254,7 +252,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector(u, s.peekData()); @@ -306,7 +304,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector SHAMap::fullBelowCache("fullBelowCache", 65536, 240); @@ -32,7 +30,7 @@ void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vectorisInner()) { - cLog(lsWARNING) << "synching empty tree"; + WriteLog (lsWARNING, SHAMap) << "synching empty tree"; return; } @@ -165,13 +163,13 @@ bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector& nodeI SHAMapTreeNode::pointer node = getNode(wanted); if (!node) { - cLog(lsWARNING) << "peer requested node that is not in the map: " << wanted; + WriteLog (lsWARNING, SHAMap) << "peer requested node that is not in the map: " << wanted; throw std::runtime_error("Peer requested node not in map"); } if (node->isInner() && node->isEmpty()) { - cLog(lsWARNING) << "peer requests empty node"; + WriteLog (lsWARNING, SHAMap) << "peer requests empty node"; return false; } @@ -215,7 +213,7 @@ SMAddNode SHAMap::addRootNode(const std::vector& rootNode, SHANod // we already have a root node if (root->getNodeHash().isNonZero()) { - cLog(lsTRACE) << "got root node, already have one"; + WriteLog (lsTRACE, SHAMap) << "got root node, already have one"; return SMAddNode::okay(); } @@ -254,7 +252,7 @@ SMAddNode SHAMap::addRootNode(const uint256& hash, const std::vectorgetNodeHash().isNonZero()) { - cLog(lsTRACE) << "got root node, already have one"; + WriteLog (lsTRACE, SHAMap) << "got root node, already have one"; assert(root->getNodeHash() == hash); return SMAddNode::okay(); } @@ -288,7 +286,7 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vectorisEmptyBranch(branch)) { - cLog(lsWARNING) << "Add known node for empty branch" << node; + WriteLog (lsWARNING, SHAMap) << "Add known node for empty branch" << node; return SMAddNode::invalid(); } if (fullBelowCache.isPresent(iNode->getChildHash(branch))) @@ -319,9 +317,9 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vectorgetDepth() != (node.getDepth() - 1)) { // Either this node is broken or we didn't request it (yet) - cLog(lsWARNING) << "unable to hook node " << node; - cLog(lsINFO) << " stuck at " << *iNode; - cLog(lsINFO) << "got depth=" << node.getDepth() << ", walked to= " << iNode->getDepth(); + WriteLog (lsWARNING, SHAMap) << "unable to hook node " << node; + WriteLog (lsINFO, SHAMap) << " stuck at " << *iNode; + WriteLog (lsINFO, SHAMap) << "got depth=" << node.getDepth() << ", walked to= " << iNode->getDepth(); return SMAddNode::invalid(); } @@ -329,7 +327,7 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vector(node, rawNode, mSeq - 1, snfWIRE, uZero, false); if (iNode->getChildHash(branch) != newNode->getNodeHash()) { - cLog(lsWARNING) << "Corrupt node recevied"; + WriteLog (lsWARNING, SHAMap) << "Corrupt node recevied"; return SMAddNode::invalid(); } @@ -344,7 +342,7 @@ SMAddNode SHAMap::addKnownNode(const SHAMapNode& node, const std::vectorgetNodeHash() != node->getNodeHash()) { - cLog(lsWARNING) << "node hash mismatch"; + WriteLog (lsWARNING, SHAMap) << "node hash mismatch"; return false; } -// cLog(lsTRACE) << "Comparing inner nodes " << *node; +// WriteLog (lsTRACE) << "Comparing inner nodes " << *node; if (node->getNodeHash() != otherNode->getNodeHash()) return false; @@ -399,7 +397,7 @@ bool SHAMap::deepCompare(SHAMap& other) SHAMapTreeNode::pointer next = getNode(node->getChildNodeID(i), node->getChildHash(i), false); if (!next) { - cLog(lsWARNING) << "unable to fetch inner node"; + WriteLog (lsWARNING, SHAMap) << "unable to fetch inner node"; return false; } stack.push(next); @@ -450,7 +448,7 @@ std::list SHAMap::getFetchPack(SHAMap* have, bool incl (boost::ref(have->mLock), boost::try_to_lock); if (!(*ul2)) { - cLog(lsINFO) << "Unable to create pack due to lock"; + WriteLog (lsINFO, SHAMap) << "Unable to create pack due to lock"; return ret; } } @@ -543,7 +541,7 @@ static bool confuseMap(SHAMap &map, int count) items.push_back(item->getTag()); if (!map.addItem(*item, false, false)) { - cLog(lsFATAL) << "Unable to add item to map"; + WriteLog (lsFATAL, SHAMap) << "Unable to add item to map"; return false; } } @@ -552,14 +550,14 @@ static bool confuseMap(SHAMap &map, int count) { if (!map.delItem(*it)) { - cLog(lsFATAL) << "Unable to remove item from map"; + WriteLog (lsFATAL, SHAMap) << "Unable to remove item from map"; return false; } } if (beforeHash != map.getHash()) { - cLog(lsFATAL) << "Hashes do not match"; + WriteLog (lsFATAL, SHAMap) << "Hashes do not match"; return false; } @@ -590,26 +588,26 @@ BOOST_AUTO_TEST_SUITE( SHAMapSync ) BOOST_AUTO_TEST_CASE( SHAMapSync_test ) { - cLog(lsTRACE) << "begin sync test"; + WriteLog (lsTRACE, SHAMap) << "begin sync test"; unsigned int seed; RAND_pseudo_bytes(reinterpret_cast(&seed), sizeof(seed)); srand(seed); - cLog(lsTRACE) << "Constructing maps"; + WriteLog (lsTRACE, SHAMap) << "Constructing maps"; SHAMap source(smtFREE), destination(smtFREE); // add random data to the source map - cLog(lsTRACE) << "Adding random data"; + WriteLog (lsTRACE, SHAMap) << "Adding random data"; int items = 10000; for (int i = 0; i < items; ++i) source.addItem(*makeRandomAS(), false, false); - cLog(lsTRACE) << "Adding items, then removing them"; + WriteLog (lsTRACE, SHAMap) << "Adding items, then removing them"; if (!confuseMap(source, 500)) BOOST_FAIL("ConfuseMap"); source.setImmutable(); - cLog(lsTRACE) << "SOURCE COMPLETE, SYNCHING"; + WriteLog (lsTRACE, SHAMap) << "SOURCE COMPLETE, SYNCHING"; std::vector nodeIDs, gotNodeIDs; std::list< std::vector > gotNodes; @@ -625,24 +623,24 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) if (!source.getNodeFat(SHAMapNode(), nodeIDs, gotNodes, (rand() % 2) == 0, (rand() % 2) == 0)) { - cLog(lsFATAL) << "GetNodeFat(root) fails"; + WriteLog (lsFATAL, SHAMap) << "GetNodeFat(root) fails"; BOOST_FAIL("GetNodeFat"); } if (gotNodes.size() < 1) { - cLog(lsFATAL) << "Didn't get root node " << gotNodes.size(); + WriteLog (lsFATAL, SHAMap) << "Didn't get root node " << gotNodes.size(); BOOST_FAIL("NodeSize"); } if (!destination.addRootNode(*gotNodes.begin(), snfWIRE, NULL)) { - cLog(lsFATAL) << "AddRootNode fails"; + WriteLog (lsFATAL, SHAMap) << "AddRootNode fails"; BOOST_FAIL("AddRootNode"); } nodeIDs.clear(); gotNodes.clear(); - cLog(lsINFO) << "ROOT COMPLETE, INNER SYNCHING"; + WriteLog (lsINFO, SHAMap) << "ROOT COMPLETE, INNER SYNCHING"; #ifdef SMS_DEBUG int bytes = 0; #endif @@ -656,14 +654,14 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) destination.getMissingNodes(nodeIDs, hashes, 2048, NULL); if (nodeIDs.empty()) break; - cLog(lsINFO) << nodeIDs.size() << " needed nodes"; + WriteLog (lsINFO, SHAMap) << nodeIDs.size() << " needed nodes"; // get as many nodes as possible based on this information for (nodeIDIterator = nodeIDs.begin(); nodeIDIterator != nodeIDs.end(); ++nodeIDIterator) { if (!source.getNodeFat(*nodeIDIterator, gotNodeIDs, gotNodes, (rand() % 2) == 0, (rand() % 2) == 0)) { - cLog(lsFATAL) << "GetNodeFat fails"; + WriteLog (lsFATAL, SHAMap) << "GetNodeFat fails"; BOOST_FAIL("GetNodeFat"); } } @@ -673,11 +671,11 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) if (gotNodeIDs.empty()) { - cLog(lsFATAL) << "No nodes gotten"; + WriteLog (lsFATAL, SHAMap) << "No nodes gotten"; BOOST_FAIL("Got Node ID"); } - cLog(lsTRACE) << gotNodeIDs.size() << " found nodes"; + WriteLog (lsTRACE, SHAMap) << gotNodeIDs.size() << " found nodes"; for (nodeIDIterator = gotNodeIDs.begin(), rawNodeIterator = gotNodes.begin(); nodeIDIterator != gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator) { @@ -687,7 +685,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) #endif if (!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator, NULL)) { - cLog(lsTRACE) << "AddKnownNode fails"; + WriteLog (lsTRACE, SHAMap) << "AddKnownNode fails"; BOOST_FAIL("AddKnownNode"); } } @@ -699,18 +697,18 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) destination.clearSynching(); #ifdef SMS_DEBUG - cLog(lsINFO) << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " << + WriteLog (lsINFO) << "SYNCHING COMPLETE " << items << " items, " << nodes << " nodes, " << bytes / 1024 << " KB"; #endif if (!source.deepCompare(destination)) { - cLog(lsFATAL) << "DeepCompare fails"; + WriteLog (lsFATAL, SHAMap) << "DeepCompare fails"; BOOST_FAIL("Deep Compare"); } #ifdef SMS_DEBUG - cLog(lsINFO) << "SHAMapSync test passed: " << items << " items, " << + WriteLog (lsINFO) << "SHAMapSync test passed: " << items << " items, " << passes << " passes, " << nodes << " nodes"; #endif