Fix platform and debug macros

This commit is contained in:
Vinnie Falco
2013-06-30 10:10:19 -07:00
parent 2fefe6ca8d
commit c35c52ff08
25 changed files with 128 additions and 124 deletions

View File

@@ -267,7 +267,7 @@ bool Ledger::hasAccount (const RippleAddress& accountID)
AccountState::pointer Ledger::getAccountState (const RippleAddress& accountID)
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
// std::cerr << "Ledger:getAccountState(" << accountID.humanAccountID() << ")" << std::endl;
#endif

View File

@@ -355,7 +355,7 @@ Transaction::pointer NetworkOPs::processTransaction (Transaction::pointer trans,
else if (isTelLocal (r) || isTerRetry (r)) // can be retried
getApp().getHashRouter ().setFlag (trans->getID (), SF_RETRY);
#ifdef DEBUG
#ifdef BEAST_DEBUG
if (r != tesSUCCESS)
{

View File

@@ -2000,7 +2000,7 @@ Json::Value RPCHandler::doAccountTransactions (Json::Value params, LoadType* loa
uLedgerMin = uLedgerMax = l->getLedgerSeq ();
}
#ifndef DEBUG
#ifndef BEAST_DEBUG
try
{
@@ -2066,7 +2066,7 @@ Json::Value RPCHandler::doAccountTransactions (Json::Value params, LoadType* loa
return ret;
#ifndef DEBUG
#ifndef BEAST_DEBUG
}
catch (...)
{

View File

@@ -65,7 +65,7 @@ TER TransactionEngine::applyTransaction (const SerializedTransaction& txn, Trans
assert (mLedger);
mNodes.init (mLedger, txn.getTransactionID (), mLedger->getLedgerSeq (), params);
#ifdef DEBUG
#ifdef BEAST_DEBUG
if (1)
{

View File

@@ -367,7 +367,7 @@ void Application::setup ()
m_loadManager->startThread ();
#ifndef WIN32
#if ! BEAST_WIN32
#ifdef SIGINT
if (!theConfig.RUN_STANDALONE)
@@ -385,7 +385,7 @@ void Application::setup ()
if (!theConfig.DEBUG_LOGFILE.empty ())
{
// Let DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose)
// Let BEAST_DEBUG messages go to the file but only WARNING or higher to regular output (unless verbose)
Log::setLogFile (theConfig.DEBUG_LOGFILE);
if (Log::getMinSeverity () > lsDEBUG)

View File

@@ -4,13 +4,13 @@
*/
//==============================================================================
#ifndef RIPPLE_IUNIQUENODELIST_H
#define RIPPLE_IUNIQUENODELIST_H
#ifndef RIPPLE_IUNIQUENODELIST_H_INCLUDED
#define RIPPLE_IUNIQUENODELIST_H_INCLUDED
class IUniqueNodeList
{
public:
typedef enum
enum ValidatorSource
{
vsConfig = 'C', // rippled.cfg
vsInbound = 'I',
@@ -19,7 +19,7 @@ public:
vsTold = 'T',
vsValidator = 'V', // validators.txt
vsWeb = 'W',
} validatorSource;
};
// VFALCO TODO rename this to use the right coding style
typedef long score;
@@ -34,8 +34,8 @@ public:
virtual void start () = 0;
// VFALCO TODO rename all these, the "node" prefix is redundant (lol)
virtual void nodeAddPublic (const RippleAddress& naNodePublic, validatorSource vsWhy, const std::string& strComment) = 0;
virtual void nodeAddDomain (std::string strDomain, validatorSource vsWhy, const std::string& strComment = "") = 0;
virtual void nodeAddPublic (const RippleAddress& naNodePublic, ValidatorSource vsWhy, const std::string& strComment) = 0;
virtual void nodeAddDomain (std::string strDomain, ValidatorSource vsWhy, const std::string& strComment = "") = 0;
virtual void nodeRemovePublic (const RippleAddress& naNodePublic) = 0;
virtual void nodeRemoveDomain (std::string strDomain) = 0;
virtual void nodeReset () = 0;
@@ -52,7 +52,7 @@ public:
virtual Json::Value getUnlJson () = 0;
virtual int iSourceScore (validatorSource vsWhy) = 0;
virtual int iSourceScore (ValidatorSource vsWhy) = 0;
};
#endif

View File

@@ -116,8 +116,8 @@ private:
bool mCluster; // Node in our cluster
RippleAddress mNodePublic; // Node public key of peer.
std::string mNodeName;
ipPort mIpPort;
ipPort mIpPortConnect;
IPAndPortNumber mIpPort;
IPAndPortNumber mIpPortConnect;
uint256 mCookieHash;
uint64 mPeerId;
bool mPrivate; // Keep peer IP private.
@@ -213,7 +213,7 @@ PeerImp::PeerImp (boost::asio::io_service& io_service, boost::asio::ssl::context
void PeerImp::handleWrite (const boost::system::error_code& error, size_t bytes_transferred)
{
// Call on IO strand
#ifdef DEBUG
#ifdef BEAST_DEBUG
// if (!error)
// std::cerr << "PeerImp::handleWrite bytes: "<< bytes_transferred << std::endl;
#endif
@@ -640,7 +640,7 @@ void PeerImp::processReadBuffer ()
{
// must not hold peer lock
int type = PackedMessage::getType (mReadbuf);
#ifdef DEBUG
#ifdef BEAST_DEBUG
// std::cerr << "PRB(" << type << "), len=" << (mReadbuf.size()-PackedMessage::kHeaderBytes) << std::endl;
#endif
@@ -924,7 +924,7 @@ void PeerImp::recvHello (protocol::TMHello& packet)
uint32 minTime = ourTime - 20;
uint32 maxTime = ourTime + 20;
#ifdef DEBUG
#ifdef BEAST_DEBUG
if (packet.has_nettime ())
{
@@ -1135,7 +1135,7 @@ void PeerImp::recvTransaction (protocol::TMTransaction& packet, ScopedLock& Mast
}
catch (...)
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
std::cerr << "Transaction from peer fails validity tests" << std::endl;
Json::StyledStreamWriter w;
w.write (std::cerr, tx->getJson (0));

View File

@@ -8,8 +8,10 @@
#define RIPPLE_PEER_H_INCLUDED
// VFALCO TODO Couldn't this be a struct?
typedef std::pair <std::string, int> ipPort;
typedef std::pair <std::string, int> IPAndPortNumber;
/** Represents a peer connection in the overlay.
*/
class Peer
: public boost::enable_shared_from_this <Peer>
, LeakChecked <Peer>

View File

@@ -88,15 +88,15 @@ private:
int mPhase;
typedef std::pair<RippleAddress, Peer::pointer> naPeer;
typedef std::pair<ipPort, Peer::pointer> pipPeer;
typedef std::map<ipPort, Peer::pointer>::value_type vtPeer;
typedef std::pair<IPAndPortNumber, Peer::pointer> pipPeer;
typedef std::map<IPAndPortNumber, Peer::pointer>::value_type vtPeer;
// Peers we are connecting with and non-thin peers we are connected to.
// Only peers we know the connection ip for are listed.
// We know the ip and port for:
// - All outbound connections
// - Some inbound connections (which we figured out).
boost::unordered_map<ipPort, Peer::pointer> mIpMap;
boost::unordered_map<IPAndPortNumber, Peer::pointer> mIpMap;
// Non-thin peers which we are connected to.
// Peers we have the public key for.
@@ -171,16 +171,16 @@ bool Peers::savePeer (const std::string& strIp, int iPort, char code)
Database* db = getApp().getWalletDB ()->getDB ();
std::string ipPort = sqlEscape (str (boost::format ("%s %d") % strIp % iPort));
std::string ipAndPort = sqlEscape (str (boost::format ("%s %d") % strIp % iPort));
ScopedLock sl (getApp().getWalletDB ()->getDBLock ());
std::string sql = str (boost::format ("SELECT COUNT(*) FROM PeerIps WHERE IpPort=%s;") % ipPort);
std::string sql = str (boost::format ("SELECT COUNT(*) FROM PeerIps WHERE IpPort=%s;") % ipAndPort);
if (db->executeSQL (sql) && db->startIterRows ())
{
if (!db->getInt (0))
{
db->executeSQL (str (boost::format ("INSERT INTO PeerIps (IpPort,Score,Source) values (%s,0,'%c');") % ipPort % code));
db->executeSQL (str (boost::format ("INSERT INTO PeerIps (IpPort,Score,Source) values (%s,0,'%c');") % ipAndPort % code));
bNew = true;
}
else
@@ -416,7 +416,7 @@ void Peers::connectTo (const std::string& strIp, int iPort)
// <-- true, if already connected.
Peer::pointer Peers::peerConnect (const std::string& strIp, int iPort)
{
ipPort pipPeer = make_pair (strIp, iPort);
IPAndPortNumber pipPeer = make_pair (strIp, iPort);
Peer::pointer ppResult;
@@ -648,7 +648,7 @@ bool Peers::peerScanSet (const std::string& strIp, int iPort)
// --> strIp: not empty
void Peers::peerClosed (Peer::ref peer, const std::string& strIp, int iPort)
{
ipPort ipPeer = make_pair (strIp, iPort);
IPAndPortNumber ipPeer = make_pair (strIp, iPort);
bool bScanRefresh = false;
// If the connection was our scan, we are no longer scanning.
@@ -664,7 +664,7 @@ void Peers::peerClosed (Peer::ref peer, const std::string& strIp, int iPort)
bool bRedundant = true;
{
boost::recursive_mutex::scoped_lock sl (mPeerLock);
const boost::unordered_map<ipPort, Peer::pointer>::iterator& itIp = mIpMap.find (ipPeer);
const boost::unordered_map<IPAndPortNumber, Peer::pointer>::iterator& itIp = mIpMap.find (ipPeer);
if (itIp == mIpMap.end ())
{

View File

@@ -208,7 +208,7 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& id, uint256 const& ha
if (node)
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
if (node->getNodeHash () != hash)
{
@@ -925,7 +925,7 @@ int SHAMap::flushDirty (DirtyMap& map, int maxNodes, HashedObjectType t, uint32
s.erase ();
it->second->addRaw (s, snfPREFIX);
#ifdef DEBUG
#ifdef BEAST_DEBUG
if (s.getSHA512Half () != it->second->getNodeHash ())
{

View File

@@ -235,7 +235,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format,
if (!node)
return SHAMapAddNode::invalid ();
#ifdef DEBUG
#ifdef BEAST_DEBUG
node->dump ();
#endif

View File

@@ -4,7 +4,7 @@
*/
//==============================================================================
#ifdef DEBUG
#ifdef BEAST_DEBUG
#define SMS_DEBUG
#endif

View File

@@ -37,7 +37,7 @@ SHAMapTreeNode::SHAMapTreeNode (const SHAMapNode& id, Blob const& rawNode, uint3
if ((type < 0) || (type > 4))
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
std::cerr << "Invalid wire format node" << std::endl;
std::cerr << strHex (rawNode) << std::endl;
assert (false);

View File

@@ -103,7 +103,7 @@ bool SqliteDatabase::executeSQL (const char* sql, bool fail_ok)
{
if (!fail_ok)
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
WriteLog (lsWARNING, SqliteDatabase) << "Perror:" << mHost << ": " << rc;
WriteLog (lsWARNING, SqliteDatabase) << "Statement: " << sql;
WriteLog (lsWARNING, SqliteDatabase) << "Error: " << sqlite3_errmsg (mConnection);
@@ -137,7 +137,7 @@ bool SqliteDatabase::executeSQL (const char* sql, bool fail_ok)
if (!fail_ok)
{
#ifdef DEBUG
#ifdef BEAST_DEBUG
WriteLog (lsWARNING, SqliteDatabase) << "SQL Serror:" << mHost << ": " << rc;
WriteLog (lsWARNING, SqliteDatabase) << "Statement: " << sql;
WriteLog (lsWARNING, SqliteDatabase) << "Error: " << sqlite3_errmsg (mConnection);

View File

@@ -24,24 +24,44 @@
// VFALCO TODO move all function definitions inlined into the class.
class UniqueNodeList : public IUniqueNodeList
{
public:
UniqueNodeList (boost::asio::io_service& io_service);
// Begin processing.
void start ();
void nodeAddPublic (const RippleAddress& naNodePublic, ValidatorSource vsWhy, const std::string& strComment);
void nodeAddDomain (std::string strDomain, ValidatorSource vsWhy, const std::string& strComment = "");
void nodeRemovePublic (const RippleAddress& naNodePublic);
void nodeRemoveDomain (std::string strDomain);
void nodeReset ();
void nodeScore ();
bool nodeInUNL (const RippleAddress& naNodePublic);
bool nodeInCluster (const RippleAddress& naNodePublic);
bool nodeInCluster (const RippleAddress& naNodePublic, std::string& name);
void nodeBootstrap ();
bool nodeLoad (boost::filesystem::path pConfig);
void nodeNetwork ();
Json::Value getUnlJson ();
int iSourceScore (ValidatorSource vsWhy);
private:
// Misc persistent information
boost::posix_time::ptime mtpScoreUpdated;
boost::posix_time::ptime mtpFetchUpdated;
boost::recursive_mutex mUNLLock;
// XXX Make this faster, make this the contents vector unsigned char or raw public key.
// XXX Contents needs to based on score.
boost::unordered_set<std::string> mUNL;
bool miscLoad ();
bool miscSave ();
// VFALCO TODO Rename these structs? Are they objects with static storage?
// This looks like C and not C++...
//
typedef struct
{
std::string strDomain;
RippleAddress naPublicKey;
validatorSource vsSource;
ValidatorSource vsSource;
boost::posix_time::ptime tpNext;
boost::posix_time::ptime tpScan;
boost::posix_time::ptime tpFetch;
@@ -52,7 +72,7 @@ private:
typedef struct
{
RippleAddress naPublicKey;
validatorSource vsSource;
ValidatorSource vsSource;
boost::posix_time::ptime tpNext;
boost::posix_time::ptime tpScan;
boost::posix_time::ptime tpFetch;
@@ -71,10 +91,8 @@ private:
std::vector<int> viReferrals;
} scoreNode;
std::map<RippleAddress, std::string> sClusterNodes;
typedef boost::unordered_map<std::string, int> strIndex;
typedef std::pair<std::string, int> ipPort;
typedef std::pair<std::string, int> IPAndPortNumber;
typedef boost::unordered_map<std::pair< std::string, int>, score> epScore;
void trustedLoad ();
@@ -83,20 +101,10 @@ private:
bool responseFetch (const std::string& strDomain, const boost::system::error_code& err, int iStatus, const std::string& strSiteFile);
boost::posix_time::ptime mtpScoreNext; // When to start scoring.
boost::posix_time::ptime mtpScoreStart; // Time currently started scoring.
boost::asio::deadline_timer mdtScoreTimer; // Timer to start scoring.
void scoreNext (bool bNow); // Update scoring timer.
void scoreCompute ();
void scoreTimerHandler (const boost::system::error_code& err);
boost::mutex mFetchLock;
int mFetchActive; // Count of active fetches.
boost::posix_time::ptime mtpFetchNext; // Time of to start next fetch.
boost::asio::deadline_timer mdtFetchTimer; // Timer to start fetching.
void fetchNext ();
void fetchDirty ();
void fetchFinish ();
@@ -109,7 +117,7 @@ private:
bool responseValidators (const std::string& strValidatorsUrl, const RippleAddress& naNodePublic, Section secSite, const std::string& strSite, const boost::system::error_code& err, int iStatus, const std::string& strValidatorsFile);
void processIps (const std::string& strSite, const RippleAddress& naNodePublic, Section::mapped_type* pmtVecStrIps);
int processValidators (const std::string& strSite, const std::string& strValidatorsSrc, const RippleAddress& naNodePublic, validatorSource vsWhy, Section::mapped_type* pmtVecStrValidators);
int processValidators (const std::string& strSite, const std::string& strValidatorsSrc, const RippleAddress& naNodePublic, ValidatorSource vsWhy, Section::mapped_type* pmtVecStrValidators);
void processFile (const std::string& strDomain, const RippleAddress& naNodePublic, Section secSite);
@@ -122,31 +130,27 @@ private:
bool validatorsResponse (const boost::system::error_code& err, int iStatus, const std::string strResponse);
void nodeProcess (const std::string& strSite, const std::string& strValidators, const std::string& strSource);
public:
UniqueNodeList (boost::asio::io_service& io_service);
private:
// Misc persistent information
boost::posix_time::ptime mtpScoreUpdated;
boost::posix_time::ptime mtpFetchUpdated;
// Begin processing.
void start ();
boost::recursive_mutex mUNLLock;
// XXX Make this faster, make this the contents vector unsigned char or raw public key.
// XXX Contents needs to based on score.
boost::unordered_set<std::string> mUNL;
void nodeAddPublic (const RippleAddress& naNodePublic, validatorSource vsWhy, const std::string& strComment);
void nodeAddDomain (std::string strDomain, validatorSource vsWhy, const std::string& strComment = "");
void nodeRemovePublic (const RippleAddress& naNodePublic);
void nodeRemoveDomain (std::string strDomain);
void nodeReset ();
boost::posix_time::ptime mtpScoreNext; // When to start scoring.
boost::posix_time::ptime mtpScoreStart; // Time currently started scoring.
boost::asio::deadline_timer mdtScoreTimer; // Timer to start scoring.
void nodeScore ();
boost::mutex mFetchLock;
int mFetchActive; // Count of active fetches.
bool nodeInUNL (const RippleAddress& naNodePublic);
bool nodeInCluster (const RippleAddress& naNodePublic);
bool nodeInCluster (const RippleAddress& naNodePublic, std::string& name);
boost::posix_time::ptime mtpFetchNext; // Time of to start next fetch.
boost::asio::deadline_timer mdtFetchTimer; // Timer to start fetching.
void nodeBootstrap ();
bool nodeLoad (boost::filesystem::path pConfig);
void nodeNetwork ();
Json::Value getUnlJson ();
int iSourceScore (validatorSource vsWhy);
std::map<RippleAddress, std::string> sClusterNodes;
};
// VFALCO TODO Replace macros with language constructs
@@ -347,7 +351,7 @@ void UniqueNodeList::scoreCompute ()
std::string strDomain = db->getStrBinary ("Domain");
std::string strPublicKey = db->getStrBinary ("PublicKey");
std::string strSource = db->getStrBinary ("Source");
int iScore = iSourceScore (static_cast<validatorSource> (strSource[0]));
int iScore = iSourceScore (static_cast<ValidatorSource> (strSource[0]));
strIndex::iterator siOld = umPulicIdx.find (strPublicKey);
if (siOld == umPulicIdx.end ())
@@ -393,7 +397,7 @@ void UniqueNodeList::scoreCompute ()
{
std::string strPublicKey = db->getStrBinary ("PublicKey");
std::string strSource = db->getStrBinary ("Source");
int iScore = iSourceScore (static_cast<validatorSource> (strSource[0]));
int iScore = iSourceScore (static_cast<ValidatorSource> (strSource[0]));
strIndex::iterator siOld = umPulicIdx.find (strPublicKey);
if (siOld == umPulicIdx.end ())
@@ -654,7 +658,7 @@ void UniqueNodeList::scoreCompute ()
typedef boost::unordered_map<std::pair< std::string, int>, score>::value_type ipScoreType;
BOOST_FOREACH (ipScoreType & ipScore, umScore)
{
ipPort ipEndpoint = ipScore.first;
IPAndPortNumber ipEndpoint = ipScore.first;
std::string strIpPort = str (boost::format ("%s %d") % ipEndpoint.first % ipEndpoint.second);
score iPoints = ipScore.second;
@@ -829,7 +833,7 @@ void UniqueNodeList::processIps (const std::string& strSite, const RippleAddress
// --> strValidatorsSrc: source details for display
// --> naNodePublic: remote source public key - not valid for local
// --> vsWhy: reason for adding validator to SeedDomains or SeedNodes.
int UniqueNodeList::processValidators (const std::string& strSite, const std::string& strValidatorsSrc, const RippleAddress& naNodePublic, validatorSource vsWhy, Section::mapped_type* pmtVecStrValidators)
int UniqueNodeList::processValidators (const std::string& strSite, const std::string& strValidatorsSrc, const RippleAddress& naNodePublic, ValidatorSource vsWhy, Section::mapped_type* pmtVecStrValidators)
{
Database* db = getApp().getWalletDB ()->getDB ();
std::string strNodePublic = naNodePublic.isValid () ? naNodePublic.humanNodePublic () : strValidatorsSrc;
@@ -1304,7 +1308,7 @@ void UniqueNodeList::fetchNext ()
}
// For each kind of source, have a starting number of points to be distributed.
int UniqueNodeList::iSourceScore (validatorSource vsWhy)
int UniqueNodeList::iSourceScore (ValidatorSource vsWhy)
{
int iScore = 0;
@@ -1339,7 +1343,7 @@ int UniqueNodeList::iSourceScore (validatorSource vsWhy)
break;
default:
throw std::runtime_error ("Internal error: bad validatorSource.");
throw std::runtime_error ("Internal error: bad ValidatorSource.");
}
return iScore;
@@ -1378,7 +1382,7 @@ bool UniqueNodeList::getSeedDomains (const std::string& strDomain, seedDomain& d
}
std::string strSource = db->getStrBinary ("Source");
dstSeedDomain.vsSource = static_cast<validatorSource> (strSource[0]);
dstSeedDomain.vsSource = static_cast<ValidatorSource> (strSource[0]);
iNext = db->getInt ("Next");
dstSeedDomain.tpNext = ptFromSeconds (iNext);
@@ -1444,7 +1448,7 @@ void UniqueNodeList::setSeedDomains (const seedDomain& sdSource, bool bNext)
// Queue a domain for a single attempt fetch a ripple.txt.
// --> strComment: only used on vsManual
// YYY As a lot of these may happen at once, would be nice to wrap multiple calls in a transaction.
void UniqueNodeList::nodeAddDomain (std::string strDomain, validatorSource vsWhy, const std::string& strComment)
void UniqueNodeList::nodeAddDomain (std::string strDomain, ValidatorSource vsWhy, const std::string& strComment)
{
boost::trim (strDomain);
boost::to_lower (strDomain);
@@ -1517,7 +1521,7 @@ bool UniqueNodeList::getSeedNodes (const RippleAddress& naNodePublic, seedNode&
}
strSource = db->getStrBinary ("Source");
dstSeedNode.vsSource = static_cast<validatorSource> (strSource[0]);
dstSeedNode.vsSource = static_cast<ValidatorSource> (strSource[0]);
iNext = db->getInt ("Next");
dstSeedNode.tpNext = ptFromSeconds (iNext);
@@ -1592,7 +1596,7 @@ void UniqueNodeList::setSeedNodes (const seedNode& snSource, bool bNext)
}
// Add a trusted node. Called by RPC or other source.
void UniqueNodeList::nodeAddPublic (const RippleAddress& naNodePublic, validatorSource vsWhy, const std::string& strComment)
void UniqueNodeList::nodeAddPublic (const RippleAddress& naNodePublic, ValidatorSource vsWhy, const std::string& strComment)
{
seedNode snCurrent;