diff --git a/TODO.txt b/TODO.txt index 19783aad5..a2b044da4 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,6 +2,8 @@ RIPPLE TODO -------------------------------------------------------------------------------- +- Make sure the leak detector output appears on Linux and FreeBSD debug builds. + - Create SharedData , move all load related state variables currently protected by separated mutexes in different classes into the LoadState, and use read/write locking semantics to update the values. Later, use Listeners diff --git a/modules/ripple_basics/utility/ripple_IniFile.cpp b/modules/ripple_basics/utility/ripple_IniFile.cpp index 81b512f9e..8f60104d8 100644 --- a/modules/ripple_basics/utility/ripple_IniFile.cpp +++ b/modules/ripple_basics/utility/ripple_IniFile.cpp @@ -62,13 +62,13 @@ Section ParseSection (const std::string& strInput, const bool bTrim) void SectionEntriesPrint (std::vector* vspEntries, const std::string& strSection) { - std::cerr << "[" << strSection << "]" << std::endl; + Log::out() << "[" << strSection << "]"; if (vspEntries) { BOOST_FOREACH (std::string & strValue, *vspEntries) { - std::cerr << strValue << std::endl; + Log::out() << strValue; } } } diff --git a/modules/ripple_basics/utility/ripple_Log.cpp b/modules/ripple_basics/utility/ripple_Log.cpp index 0e79bda06..8ed47cd61 100644 --- a/modules/ripple_basics/utility/ripple_Log.cpp +++ b/modules/ripple_basics/utility/ripple_Log.cpp @@ -139,13 +139,33 @@ Log::~Log () logMsg += "..."; } + print (logMsg, mSeverity >= sMinSeverity); +} + +void Log::print (std::string const& text, bool toStdErr) +{ boost::recursive_mutex::scoped_lock sl (sLock); - if (mSeverity >= sMinSeverity) - std::cerr << logMsg << std::endl; - + // Always write to the log file if it is open. + // if (outStream != NULL) - (*outStream) << logMsg << std::endl; + { + (*outStream) << text << std::endl; + } + + if (toStdErr) + { + if (beast_isRunningUnderDebugger ()) + { + // Send it to the attached debugger's Output window + // + Logger::outputDebugString (text); + } + else + { + std::cerr << text << std::endl; + } + } } std::string Log::rotateLog (void) diff --git a/modules/ripple_basics/utility/ripple_Log.h b/modules/ripple_basics/utility/ripple_Log.h index cb362c312..62f441c86 100644 --- a/modules/ripple_basics/utility/ripple_Log.h +++ b/modules/ripple_basics/utility/ripple_Log.h @@ -117,6 +117,63 @@ public: static std::string rotateLog (); +public: + /** Write to log output. + + All logging eventually goes through this function. If a + debugger is attached, the string goes to the debugging console, + else it goes to the standard error output. If a log file is + open, then the message is additionally written to the open log + file. + + The text should not contain a newline, it will be automatically + added as needed. + + @note This acquires a global mutex. + + @param text The text to write. + @param toStdErr `true` to also write to std::cerr + */ + static void print (std::string const& text, + bool toStdErr = true); + + /** Output stream for logging + + This is a convenient replacement for writing to `std::cerr`. + + Usage: + + @code + + Log::out () << "item1" << 2; + + @endcode + + It is not necessary to append a newline. + */ + class out + { + public: + out () + { + } + + ~out () + { + Log::print (m_ss.str ()); + } + + template + out& operator<< (T t) + { + m_ss << t; + return *this; + } + + private: + std::stringstream m_ss; + }; + private: enum { diff --git a/modules/ripple_basics/utility/ripple_RandomNumbers.cpp b/modules/ripple_basics/utility/ripple_RandomNumbers.cpp index 23202c7a4..a3bd8108b 100644 --- a/modules/ripple_basics/utility/ripple_RandomNumbers.cpp +++ b/modules/ripple_basics/utility/ripple_RandomNumbers.cpp @@ -37,7 +37,7 @@ void RandomNumbers::fillBytes (void* destinationBuffer, int numberOfBytes) if (! initialize ()) { char const* message = "Unable to add system entropy"; - std::cerr << message << std::endl; + Log::out() << message; throw std::runtime_error (message); } } @@ -75,7 +75,7 @@ bool RandomNumbers::platformAddEntropy () if (!CryptGetDefaultProviderA (PROV_RSA_FULL, NULL, CRYPT_MACHINE_DEFAULT, name, &count)) { #ifdef BEAST_DEBUG - std::cerr << "Unable to get default crypto provider" << std::endl; + Log::out() << "Unable to get default crypto provider"; #endif return false; } @@ -83,7 +83,7 @@ bool RandomNumbers::platformAddEntropy () if (!CryptAcquireContextA (&cryptoHandle, NULL, name, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) { #ifdef BEAST_DEBUG - std::cerr << "Unable to acquire crypto provider" << std::endl; + Log::out() << "Unable to acquire crypto provider"; #endif return false; } @@ -91,7 +91,7 @@ bool RandomNumbers::platformAddEntropy () if (!CryptGenRandom (cryptoHandle, 128, reinterpret_cast (rand))) { #ifdef BEAST_DEBUG - std::cerr << "Unable to get entropy from crypto provider" << std::endl; + Log::out() << "Unable to get entropy from crypto provider"; #endif CryptReleaseContext (cryptoHandle, 0); return false; @@ -115,7 +115,7 @@ bool RandomNumbers::platformAddEntropy () if (!reader.is_open ()) { #ifdef BEAST_DEBUG - std::cerr << "Unable to open random source" << std::endl; + Log::out() << "Unable to open random source"; #endif return false; } @@ -127,7 +127,7 @@ bool RandomNumbers::platformAddEntropy () if (bytesRead == 0) { #ifdef BEAST_DEBUG - std::cerr << "Unable to read from random source" << std::endl; + Log::out() << "Unable to read from random source"; #endif return false; } diff --git a/modules/ripple_basics/utility/ripple_StringUtilities.cpp b/modules/ripple_basics/utility/ripple_StringUtilities.cpp index 58812c268..5813164a0 100644 --- a/modules/ripple_basics/utility/ripple_StringUtilities.cpp +++ b/modules/ripple_basics/utility/ripple_StringUtilities.cpp @@ -188,6 +188,7 @@ extern std::string urlEncode (const std::string& strSrc) // IP Port parsing // // <-- iPort: "" = -1 +// VFALCO TODO Make this not require boost... and especially boost::asio bool parseIpPort (const std::string& strSource, std::string& strIP, int& iPort) { boost::smatch smMatch; @@ -235,10 +236,10 @@ bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& s boost::algorithm::to_lower (strScheme); iPort = strPort.empty () ? -1 : lexical_cast_s (strPort); - // std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPort << "' : " << iPort << " : '" << strPath << "'" << std::endl; + // Log::out() << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPort << "' : " << iPort << " : '" << strPath << "'"; } - // std::cerr << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'" << std::endl; + // Log::out() << strUrl << " : " << bMatch << " : '" << strDomain << "' : '" << strPath << "'"; return bMatch; } @@ -261,3 +262,12 @@ bool parseQuality (const std::string& strSource, uint32& uQuality) return !!uQuality; } + +std::string addressToString (void const* address) +{ + // VFALCO TODO Clean this up, use uintptr_t and only produce a 32 bit + // output on 32 bit platforms + // + return strHex (static_cast (address) - static_cast (0)); +} + diff --git a/modules/ripple_basics/utility/ripple_StringUtilities.h b/modules/ripple_basics/utility/ripple_StringUtilities.h index ffa766a81..3ddcf75ae 100644 --- a/modules/ripple_basics/utility/ripple_StringUtilities.h +++ b/modules/ripple_basics/utility/ripple_StringUtilities.h @@ -208,6 +208,10 @@ template std::string lexical_cast_it (const T& t) bool parseUrl (const std::string& strUrl, std::string& strScheme, std::string& strDomain, int& iPort, std::string& strPath); -#endif +#define ADDRESS(p) strHex(uint64( ((char*) p) - ((char*) 0))) -// vim:ts=4 +/** Convert a pointer address to a string for display purposes. +*/ +extern std::string addressToString (void const* address); + +#endif diff --git a/modules/ripple_core/functional/ripple_Config.cpp b/modules/ripple_core/functional/ripple_Config.cpp index 1bedd0094..b30f5c21f 100644 --- a/modules/ripple_core/functional/ripple_Config.cpp +++ b/modules/ripple_core/functional/ripple_Config.cpp @@ -197,9 +197,9 @@ void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet) // Update default values load (); - // std::cerr << "CONFIG FILE: " << CONFIG_FILE << std::endl; - // std::cerr << "CONFIG DIR: " << CONFIG_DIR << std::endl; - // std::cerr << "DATA DIR: " << DATA_DIR << std::endl; + // Log::out() << "CONFIG FILE: " << CONFIG_FILE; + // Log::out() << "CONFIG DIR: " << CONFIG_DIR; + // Log::out() << "DATA DIR: " << DATA_DIR; boost::filesystem::create_directories (DATA_DIR, ec); @@ -274,13 +274,13 @@ Config::Config () void Config::load () { if (!QUIET) - std::cerr << "Loading: " << CONFIG_FILE << std::endl; + Log::out() << "Loading: " << CONFIG_FILE; std::ifstream ifsConfig (CONFIG_FILE.c_str (), std::ios::in); if (!ifsConfig) { - std::cerr << "Failed to open '" << CONFIG_FILE << "'." << std::endl; + Log::out() << "Failed to open '" << CONFIG_FILE << "'."; } else { @@ -291,7 +291,7 @@ void Config::load () if (ifsConfig.bad ()) { - std::cerr << "Failed to read '" << CONFIG_FILE << "'." << std::endl; + Log::out() << "Failed to read '" << CONFIG_FILE << "'."; } else { diff --git a/modules/ripple_data/crypto/ripple_CKeyECIES.cpp b/modules/ripple_data/crypto/ripple_CKeyECIES.cpp index 0903e0127..1c4ba5184 100644 --- a/modules/ripple_data/crypto/ripple_CKeyECIES.cpp +++ b/modules/ripple_data/crypto/ripple_CKeyECIES.cpp @@ -277,7 +277,7 @@ bool checkECIES (void) if ((i % 100) == 0) { // generate new keys every 100 times - // std::cerr << "new keys" << std::endl; + // Log::out() << "new keys"; senderPriv.MakeNewKey (); recipientPriv.MakeNewKey (); @@ -307,7 +307,7 @@ bool checkECIES (void) return false; } - // std::cerr << "Msg(" << msglen << ") ok " << ciphertext.size() << std::endl; + //Log::out() << "Msg(" << msglen << ") ok " << ciphertext.size(); } return true; diff --git a/modules/ripple_data/protocol/ripple_PackedMessage.cpp b/modules/ripple_data/protocol/ripple_PackedMessage.cpp index 978c91eb3..4b2dc3873 100644 --- a/modules/ripple_data/protocol/ripple_PackedMessage.cpp +++ b/modules/ripple_data/protocol/ripple_PackedMessage.cpp @@ -19,7 +19,7 @@ PackedMessage::PackedMessage (::google::protobuf::Message const& message, int ty message.SerializeToArray (&mBuffer [PackedMessage::kHeaderBytes], messageBytes); #ifdef BEAST_DEBUG - // std::cerr << "PackedMessage: type=" << type << ", datalen=" << msg_size << std::endl; + //Log::out() << "PackedMessage: type=" << type << ", datalen=" << msg_size; #endif } } diff --git a/modules/ripple_data/protocol/ripple_RippleAddress.cpp b/modules/ripple_data/protocol/ripple_RippleAddress.cpp index 1c15d9022..05c143741 100644 --- a/modules/ripple_data/protocol/ripple_RippleAddress.cpp +++ b/modules/ripple_data/protocol/ripple_RippleAddress.cpp @@ -814,17 +814,17 @@ bool RippleAddress::setSeedGeneric (const std::string& strText) } else if (setSeed (strText)) { - // std::cerr << "Recognized seed." << std::endl; + // Log::out() << "Recognized seed."; nothing (); } else if (1 == setSeed1751 (strText)) { - // std::cerr << "Recognized 1751 seed." << std::endl; + // Log::out() << "Recognized 1751 seed."; nothing (); } else { - // std::cerr << "Creating seed from pass phrase." << std::endl; + // Log::out() << "Creating seed from pass phrase."; setSeed (CKey::PassPhraseToKey (strText)); } diff --git a/modules/ripple_data/protocol/ripple_STAmount.cpp b/modules/ripple_data/protocol/ripple_STAmount.cpp index 76a16e97f..7a586f949 100644 --- a/modules/ripple_data/protocol/ripple_STAmount.cpp +++ b/modules/ripple_data/protocol/ripple_STAmount.cpp @@ -50,7 +50,7 @@ bool STAmount::currencyFromString (uint160& uDstCurrency, const std::string& sCu // std::string sIso; // sIso.assign(vucIso.begin(), vucIso.end()); - // std::cerr << "currency: " << sIso << std::endl; + // Log::out() << "currency: " << sIso; Serializer s; diff --git a/modules/ripple_data/protocol/ripple_SerializedTypes.cpp b/modules/ripple_data/protocol/ripple_SerializedTypes.cpp index 189502971..aa92e9bd6 100644 --- a/modules/ripple_data/protocol/ripple_SerializedTypes.cpp +++ b/modules/ripple_data/protocol/ripple_SerializedTypes.cpp @@ -25,6 +25,8 @@ SerializedType& SerializedType::operator= (const SerializedType& t) void STPathSet::printDebug () { + // VFALCO NOTE Can't use Log::out() because of std::endl + // for (int i = 0; i < value.size (); i++) { std::cerr << i << ": "; @@ -45,13 +47,13 @@ void STPathSet::printDebug () void STPath::printDebug () { - std::cerr << "STPath:" << std::endl; + Log::out() << "STPath:"; for (int i = 0; i < mPath.size (); i++) { RippleAddress nad; nad.setAccountID (mPath[i].mAccountID); - std::cerr << " " << i << ": " << nad.humanAccountID () << std::endl; + Log::out() << " " << i << ": " << nad.humanAccountID (); } } diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index d00594638..cf18272c8 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -1014,10 +1014,10 @@ void callRPC ( // Connect to localhost if (!theConfig.QUIET) { - std::cerr << "Connecting to: " << strIp << ":" << iPort << std::endl; - // std::cerr << "Username: " << strUsername << ":" << strPassword << std::endl; - // std::cerr << "Path: " << strPath << std::endl; - // std::cerr << "Method: " << strMethod << std::endl; + Log::out() << "Connecting to: " << strIp << ":" << iPort; + // Log::out() << "Username: " << strUsername << ":" << strPassword; + // Log::out() << "Path: " << strPath; + // Log::out() << "Method: " << strMethod; } // HTTP basic authentication diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 26e0532d2..d97d767d5 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -268,7 +268,7 @@ bool Ledger::hasAccount (const RippleAddress& accountID) AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID) { #ifdef BEAST_DEBUG - // std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl; + // Log::out() << "Ledger:getAccountState(" << accountID.humanAccountID() << ")"; #endif SLE::pointer sle = getSLEi (Ledger::getAccountRootIndex (accountID)); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 3bb78ca21..644e17b46 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -275,9 +275,9 @@ Json::Value RPCHandler::transactionSign (Json::Value params, bool bSubmit, bool // ... or the master key must have been used. && raSrcAddressID.getAccountID () != naAccountPublic.getAccountID ()) { - // std::cerr << "iIndex: " << iIndex << std::endl; - // std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl; - // std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl; + // Log::out() << "iIndex: " << iIndex; + // Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()); + // Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()); return rpcError (rpcSRC_ACT_NOT_FOUND); } @@ -493,9 +493,9 @@ Json::Value RPCHandler::authorize (Ledger::ref lrLedger, if (asSrc->haveAuthorizedKey () && (asSrc->getAuthorizedKey ().getAccountID () != naAccountPublic.getAccountID ())) { - // std::cerr << "iIndex: " << iIndex << std::endl; - // std::cerr << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()) << std::endl; - // std::cerr << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()) << std::endl; + // Log::out() << "iIndex: " << iIndex; + // Log::out() << "sfAuthorizedKey: " << strHex(asSrc->getAuthorizedKey().getAccountID()); + // Log::out() << "naAccountPublic: " << strHex(naAccountPublic.getAccountID()); return rpcError (rpcPASSWD_CHANGED); } @@ -2113,7 +2113,7 @@ Json::Value RPCHandler::doValidationSeed (Json::Value params, LoadType* loadType if (!params.isMember ("secret")) { - std::cerr << "Unset validation seed." << std::endl; + Log::out() << "Unset validation seed."; theConfig.VALIDATION_SEED.clear (); theConfig.VALIDATION_PUB.clear (); diff --git a/src/cpp/ripple/RPCServer.cpp b/src/cpp/ripple/RPCServer.cpp index b5671a665..1bbc88cec 100644 --- a/src/cpp/ripple/RPCServer.cpp +++ b/src/cpp/ripple/RPCServer.cpp @@ -18,7 +18,7 @@ RPCServer::RPCServer (boost::asio::io_service& io_service, boost::asio::ssl::con void RPCServer::connected () { - //std::cerr << "RPC request" << std::endl; + //Log::out() << "RPC request"; boost::asio::async_read_until (mSocket, mLineBuffer, "\r\n", mStrand.wrap (boost::bind (&RPCServer::handle_read_line, shared_from_this (), boost::asio::placeholders::error))); } @@ -178,7 +178,7 @@ bool RPCServer::parseAcceptRate (const std::string& sAcceptRate) void RPCServer::handle_write (const boost::system::error_code& e) { - //std::cerr << "async_write complete " << e << std::endl; + //Log::out() << "async_write complete " << e; if (!e) { diff --git a/src/cpp/ripple/RegularKeySetTransactor.cpp b/src/cpp/ripple/RegularKeySetTransactor.cpp index fae42620f..e97a85cf3 100644 --- a/src/cpp/ripple/RegularKeySetTransactor.cpp +++ b/src/cpp/ripple/RegularKeySetTransactor.cpp @@ -22,7 +22,7 @@ uint64 RegularKeySetTransactor::calculateBaseFee () TER RegularKeySetTransactor::doApply () { - std::cerr << "RegularKeySet>" << std::endl; + Log::out() << "RegularKeySet>"; const uint32 uTxFlags = mTxn.getFlags (); @@ -50,7 +50,7 @@ TER RegularKeySetTransactor::doApply () mTxnAccount->makeFieldAbsent (sfRegularKey); } - std::cerr << "RegularKeySet<" << std::endl; + Log::out() << "RegularKeySet<"; return tesSUCCESS; } diff --git a/src/cpp/ripple/WalletAddTransactor.cpp b/src/cpp/ripple/WalletAddTransactor.cpp index 91aeea9b4..cd0d3bf3d 100644 --- a/src/cpp/ripple/WalletAddTransactor.cpp +++ b/src/cpp/ripple/WalletAddTransactor.cpp @@ -8,7 +8,7 @@ SETUP_LOG (WalletAddTransactor) TER WalletAddTransactor::doApply () { - std::cerr << "WalletAdd>" << std::endl; + Log::out() << "WalletAdd>"; Blob const vucPubKey = mTxn.getFieldVL (sfPublicKey); Blob const vucSignature = mTxn.getFieldVL (sfSignature); @@ -28,7 +28,7 @@ TER WalletAddTransactor::doApply () // FIXME: This should be moved to the transaction's signature check logic and cached if (!naMasterPubKey.accountPublicVerify (Serializer::getSHA512Half (uAuthKeyID.begin (), uAuthKeyID.size ()), vucSignature)) { - std::cerr << "WalletAdd: unauthorized: bad signature " << std::endl; + Log::out() << "WalletAdd: unauthorized: bad signature "; return tefBAD_ADD_AUTH; } @@ -37,7 +37,7 @@ TER WalletAddTransactor::doApply () if (sleDst) { - std::cerr << "WalletAdd: account already created" << std::endl; + Log::out() << "WalletAdd: account already created"; return tefCREATED; } @@ -71,7 +71,7 @@ TER WalletAddTransactor::doApply () sleDst->setFieldAmount (sfBalance, saDstAmount); sleDst->setFieldAccount (sfRegularKey, uAuthKeyID); - std::cerr << "WalletAdd<" << std::endl; + Log::out() << "WalletAdd<"; return tesSUCCESS; } diff --git a/src/cpp/ripple/ripple_LocalCredentials.cpp b/src/cpp/ripple/ripple_LocalCredentials.cpp index b2b744026..a72c39f9b 100644 --- a/src/cpp/ripple/ripple_LocalCredentials.cpp +++ b/src/cpp/ripple/ripple_LocalCredentials.cpp @@ -24,7 +24,7 @@ void LocalCredentials::start () } if (!theConfig.QUIET) - std::cerr << "NodeIdentity: " << mNodePublicKey.humanNodePublic () << std::endl; + Log::out() << "NodeIdentity: " << mNodePublicKey.humanNodePublic (); getApp().getUNL ().start (); } @@ -67,7 +67,7 @@ bool LocalCredentials::nodeIdentityLoad () bool LocalCredentials::nodeIdentityCreate () { if (!theConfig.QUIET) - std::cerr << "NodeIdentity: Creating." << std::endl; + Log::out() << "NodeIdentity: Creating."; // // Generate the public and private key @@ -114,7 +114,7 @@ bool LocalCredentials::nodeIdentityCreate () // XXX Check error result. if (!theConfig.QUIET) - std::cerr << "NodeIdentity: Created." << std::endl; + Log::out() << "NodeIdentity: Created."; return true; } diff --git a/src/cpp/ripple/ripple_Main.cpp b/src/cpp/ripple/ripple_Main.cpp index 9a56d212e..d9f955294 100644 --- a/src/cpp/ripple/ripple_Main.cpp +++ b/src/cpp/ripple/ripple_Main.cpp @@ -26,7 +26,7 @@ void startServer () const Json::Value& jvCommand = theConfig.RPC_STARTUP[i]; if (!theConfig.QUIET) - std::cerr << "Startup RPC: " << jvCommand << std::endl; + Log::out() << "Startup RPC: " << jvCommand; RPCHandler rhHandler (&getApp().getOPs ()); @@ -35,7 +35,7 @@ void startServer () Json::Value jvResult = rhHandler.doCommand (jvCommand, RPCHandler::ADMIN, &loadType); if (!theConfig.QUIET) - std::cerr << "Result: " << jvResult << std::endl; + Log::out() << "Result: " << jvResult; } } @@ -187,7 +187,7 @@ int rippleMain (int argc, char** argv) if (! RandomNumbers::getInstance ().initialize ()) { - std::cerr << "Unable to add system entropy" << std::endl; + Log::out() << "Unable to add system entropy"; iResult = 2; } diff --git a/src/cpp/ripple/ripple_Peer.cpp b/src/cpp/ripple/ripple_Peer.cpp index c771a4dd6..401d496c7 100644 --- a/src/cpp/ripple/ripple_Peer.cpp +++ b/src/cpp/ripple/ripple_Peer.cpp @@ -4,9 +4,6 @@ */ //============================================================================== -// VFALCO TODO make this an inline function -#define ADDRESS(p) strHex(uint64( ((char*) p) - ((char*) 0))) - SETUP_LOG (Peer) class PeerImp; @@ -207,7 +204,7 @@ PeerImp::PeerImp (boost::asio::io_service& io_service, boost::asio::ssl::context mActivityTimer (io_service), mIOStrand (io_service) { - WriteLog (lsDEBUG, Peer) << "CREATING PEER: " << ADDRESS (this); + WriteLog (lsDEBUG, Peer) << "CREATING PEER: " << addressToString (this); } void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_transferred) @@ -215,7 +212,7 @@ void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_ // Call on IO strand #ifdef BEAST_DEBUG // if (!error) - // std::cerr << "PeerImp::handleWrite bytes: "<< bytes_transferred << std::endl; + // Log::out() << "PeerImp::handleWrite bytes: "<< bytes_transferred; #endif mSendingPacket.reset (); @@ -227,7 +224,7 @@ void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_ } else if (error) { - WriteLog (lsINFO, Peer) << "Peer: Write: Error: " << ADDRESS (this) << ": bytes=" << bytes_transferred << ": " << error.category ().name () << ": " << error.message () << ": " << error; + WriteLog (lsINFO, Peer) << "Peer: Write: Error: " << addressToString (this) << ": bytes=" << bytes_transferred << ": " << error.category ().name () << ": " << error.message () << ": " << error; detach ("hw", true); } @@ -249,7 +246,7 @@ void PeerImp::setIpPort (const std::string& strIP, int iPort) mLoad.rename (strIP); WriteLog (lsDEBUG, Peer) << "Peer: Set: " - << ADDRESS (this) << "> " + << addressToString (this) << "> " << (mNodePublic.isValid () ? mNodePublic.humanNodePublic () : "-") << " " << getIP () << " " << getPort (); } @@ -272,7 +269,7 @@ void PeerImp::detach (const char* rsn, bool onIOStrand) CondLog (mCluster, lsWARNING, Peer) << "Cluster peer detach \"" << mNodeName << "\": " << rsn; /* WriteLog (lsDEBUG, Peer) << "Peer: Detach: " - << ADDRESS(this) << "> " + << addressToString(this) << "> " << rsn << ": " << (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort(); */ @@ -302,7 +299,7 @@ void PeerImp::detach (const char* rsn, bool onIOStrand) /* WriteLog (lsDEBUG, Peer) << "Peer: Detach: " - << ADDRESS(this) << "< " + << addressToString(this) << "< " << rsn << ": " << (mNodePublic.isValid() ? mNodePublic.humanNodePublic() : "-") << " " << getIP() << " " << getPort(); */ @@ -346,7 +343,7 @@ void PeerImp::handleVerifyTimer (const boost::system::error_code& ecResult) if (ecResult == boost::asio::error::operation_aborted) { // Timer canceled because deadline no longer needed. - // std::cerr << "Deadline cancelled." << std::endl; + // Log::out() << "Deadline cancelled."; nothing (); // Aborter is done. } @@ -405,7 +402,7 @@ void PeerImp::connect (const std::string& strIp, int iPort) if (!err) { - WriteLog (lsINFO, Peer) << "Peer: Connect: Outbound: " << ADDRESS (this) << ": " << mIpPort.first << " " << mIpPort.second; + WriteLog (lsINFO, Peer) << "Peer: Connect: Outbound: " << addressToString (this) << ": " << mIpPort.first << " " << mIpPort.second; boost::asio::async_connect ( getSocket (), @@ -488,7 +485,7 @@ void PeerImp::connected (const boost::system::error_code& error) { // Not redundant ip and port, handshake, and start. - WriteLog (lsINFO, Peer) << "Peer: Inbound: Accepted: " << ADDRESS (this) << ": " << strIp << " " << iPort; + WriteLog (lsINFO, Peer) << "Peer: Inbound: Accepted: " << addressToString (this) << ": " << strIp << " " << iPort; mSocketSsl.set_verify_mode (boost::asio::ssl::verify_none); @@ -498,7 +495,7 @@ void PeerImp::connected (const boost::system::error_code& error) } else if (!mDetaching) { - WriteLog (lsINFO, Peer) << "Peer: Inbound: Error: " << ADDRESS (this) << ": " << strIp << " " << iPort << " : " << error.category ().name () << ": " << error.message () << ": " << error; + WriteLog (lsINFO, Peer) << "Peer: Inbound: Error: " << addressToString (this) << ": " << strIp << " " << iPort << " : " << error.category ().name () << ": " << error.message () << ": " << error; detach ("ctd", false); } @@ -641,10 +638,10 @@ void PeerImp::processReadBuffer () // must not hold peer lock int type = PackedMessage::getType (mReadbuf); #ifdef BEAST_DEBUG - // std::cerr << "PRB(" << type << "), len=" << (mReadbuf.size()-PackedMessage::kHeaderBytes) << std::endl; + // Log::out() << "PRB(" << type << "), len=" << (mReadbuf.size()-PackedMessage::kHeaderBytes); #endif - // std::cerr << "PeerImp::processReadBuffer: " << mIpPort.first << " " << mIpPort.second << std::endl; + // Log::out() << "PeerImp::processReadBuffer: " << mIpPort.first << " " << mIpPort.second; LoadEvent::autoptr event (getApp().getJobQueue ().getLoadEventAP (jtPEER, "PeerImp::read")); @@ -1136,8 +1133,9 @@ void PeerImp::recvTransaction (protocol::TMTransaction& packet, ScopedLock& Mast catch (...) { #ifdef BEAST_DEBUG - std::cerr << "Transaction from peer fails validity tests" << std::endl; + Log::out() << "Transaction from peer fails validity tests"; Json::StyledStreamWriter w; + // VFALCO NOTE This bypasses the Log bottleneck w.write (std::cerr, tx->getJson (0)); #endif return; @@ -1430,7 +1428,7 @@ void PeerImp::recvGetPeers (protocol::TMGetPeers& packet, ScopedLock& MasterLock addr->set_ipv4 (inet_addr (strIP.c_str ())); addr->set_ipv4port (iPort); - //WriteLog (lsINFO, Peer) << "Peer: Teaching: " << ADDRESS(this) << ": " << n << ": " << strIP << " " << iPort; + //WriteLog (lsINFO, Peer) << "Peer: Teaching: " << addressToString(this) << ": " << n << ": " << strIP << " " << iPort; } PackedMessage::pointer message = boost::make_shared (peers, protocol::mtPEERS); @@ -1452,7 +1450,7 @@ void PeerImp::recvPeers (protocol::TMPeers& packet) if (strIP != "0.0.0.0" && strIP != "127.0.0.1") { - //WriteLog (lsINFO, Peer) << "Peer: Learning: " << ADDRESS(this) << ": " << i << ": " << strIP << " " << iPort; + //WriteLog (lsINFO, Peer) << "Peer: Learning: " << addressToString(this) << ": " << i << ": " << strIP << " " << iPort; getApp().getPeers ().savePeer (strIP, iPort, IUniqueNodeList::vsTold); } @@ -2310,7 +2308,7 @@ Json::Value PeerImp::getJson () { Json::Value ret (Json::objectValue); - //ret["this"] = ADDRESS(this); + //ret["this"] = addressToString(this); ret["public_key"] = mNodePublic.ToString (); ret["ip"] = mIpPortConnect.first; //ret["port"] = mIpPortConnect.second; diff --git a/src/cpp/ripple/ripple_Peers.cpp b/src/cpp/ripple/ripple_Peers.cpp index e1a7bdc93..a58b9eca5 100644 --- a/src/cpp/ripple/ripple_Peers.cpp +++ b/src/cpp/ripple/ripple_Peers.cpp @@ -196,7 +196,7 @@ bool Peers::savePeer (const std::string& strIp, int iPort, char code) } else { - std::cerr << "Error saving Peer" << std::endl; + Log::out() << "Error saving Peer"; } if (bNew) diff --git a/src/cpp/ripple/ripple_SHAMapNode.cpp b/src/cpp/ripple/ripple_SHAMapNode.cpp index 6b4049f8d..dcd8c0b3d 100644 --- a/src/cpp/ripple/ripple_SHAMapNode.cpp +++ b/src/cpp/ripple/ripple_SHAMapNode.cpp @@ -138,8 +138,8 @@ int SHAMapNode::selectBranch (uint256 const& hash) const if ((hash & smMasks[mDepth]) != mNodeID) { - std::cerr << "selectBranch(" << getString () << std::endl; - std::cerr << " " << hash << " off branch" << std::endl; + Log::out() << "selectBranch(" << getString (); + Log::out() << " " << hash << " off branch"; assert (false); return -1; // does not go under this node } diff --git a/src/cpp/ripple/ripple_SHAMapTreeNode.cpp b/src/cpp/ripple/ripple_SHAMapTreeNode.cpp index 75e9cf804..1398ea5d0 100644 --- a/src/cpp/ripple/ripple_SHAMapTreeNode.cpp +++ b/src/cpp/ripple/ripple_SHAMapTreeNode.cpp @@ -38,8 +38,8 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, uint3 if ((type < 0) || (type > 4)) { #ifdef BEAST_DEBUG - std::cerr << "Invalid wire format node" << std::endl; - std::cerr << strHex (rawNode) << std::endl; + Log::out() << "Invalid wire format node"; + Log::out() << strHex (rawNode); assert (false); #endif throw std::runtime_error ("invalid node AW type");