Merge branch 'master' of github.com:jedmccaleb/NewCoin

Conflicts:
	src/RPCServer.cpp
This commit is contained in:
jed
2012-10-24 13:10:17 -07:00
13 changed files with 205 additions and 159 deletions

View File

@@ -72,7 +72,6 @@ void Application::run()
if (!theConfig.DEBUG_LOGFILE.empty())
{ // Let DEBUG messages go to the file but only WARNING or higher to regular output
Log::setLogFile(theConfig.DEBUG_LOGFILE);
Log::setMinSeverity(lsWARNING);
LogPartition::setSeverity(lsDEBUG);
}
@@ -212,7 +211,7 @@ void Application::startNewLedger()
Ledger::pointer secondLedger = boost::make_shared<Ledger>(true, boost::ref(*firstLedger));
secondLedger->setClosed();
secondLedger->setAccepted();
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)));
mMasterLedger.pushLedger(secondLedger, boost::make_shared<Ledger>(true, boost::ref(*secondLedger)), false);
assert(!!secondLedger->getAccountState(rootAddress));
mNetOps.setLastCloseTime(secondLedger->getCloseTimeNC());
}

View File

@@ -339,6 +339,7 @@ uint256 Ledger::getHash()
void Ledger::saveAcceptedLedger(bool fromConsensus)
{ // can be called in a different thread
cLog(lsTRACE) << "saveAcceptedLedger " << (fromConsensus ? "fromConsensus" : "fromAcquire") << getLedgerSeq();
static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;");
static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;");
static boost::format AcctTransExists("SELECT LedgerSeq FROM AccountTransactions WHERE TransId = '%s';");
@@ -434,9 +435,7 @@ void Ledger::saveAcceptedLedger(bool fromConsensus)
theApp->getOPs().pubLedger(shared_from_this());
if(theConfig.FULL_HISTORY)
{
// WRITEME: check for seamless ledger history
}
theApp->getMasterLedger().checkLedgerGap(shared_from_this());
}
@@ -509,7 +508,15 @@ Ledger::pointer Ledger::loadByHash(const uint256& ledgerHash)
Ledger::pointer Ledger::getLastFullLedger()
{
return getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;");
try
{
return getSQL("SELECT * from Ledgers order by LedgerSeq desc limit 1;");
}
catch (SHAMapMissingNode&)
{
cLog(lsWARNING) << "Database contains ledger with missing nodes";
return Ledger::pointer();
}
}
void Ledger::addJson(Json::Value& ret, int options)

View File

@@ -580,10 +580,9 @@ bool LedgerAcquireMaster::gotLedgerData(ripple::TMLedgerData& packet, Peer::ref
return false;
}
LedgerAcquireSet::LedgerAcquireSet(Ledger::ref targetLedger, Ledger::ref currentLedger) :
LedgerAcquireSet::LedgerAcquireSet(Ledger::ref targetLedger) :
mTargetLedger(targetLedger), mCheckComplete(true)
{
updateCurrentLedger(currentLedger);
}
void LedgerAcquireSet::updateCurrentLedger(Ledger::pointer currentLedger)
@@ -591,23 +590,25 @@ void LedgerAcquireSet::updateCurrentLedger(Ledger::pointer currentLedger)
while (1)
{
if ((currentLedger->getHash() == mTargetLedger->getHash()) ||
(currentLedger->getParentHash() == mTargetLedger->getHash()))
{ // We have completed acquiring the set
done();
return;
}
while (mTargetLedger->getLedgerSeq() >= currentLedger->getLedgerSeq())
{ // We need to back up our target
mTargetLedger = theApp->getMasterLedger().getLedgerByHash(mTargetLedger->getParentHash());
if (!mTargetLedger)
{
cLog(lsWARNING) << "LedgerAcquireSet encountered a non-present target ledger";
if (mTargetLedger)
{
if ((currentLedger->getHash() == mTargetLedger->getHash()) ||
(currentLedger->getParentHash() == mTargetLedger->getHash()))
{ // We have completed acquiring the set
done();
return;
}
while (mTargetLedger->getLedgerSeq() >= currentLedger->getLedgerSeq())
{ // We need to back up our target
mTargetLedger = theApp->getMasterLedger().getLedgerByHash(mTargetLedger->getParentHash());
if (!mTargetLedger)
{
cLog(lsWARNING) << "LedgerAcquireSet encountered a non-present target ledger";
done();
return;
}
}
}
Ledger::pointer nextLedger =
@@ -646,7 +647,10 @@ void LedgerAcquireSet::onComplete(boost::weak_ptr<LedgerAcquireSet> set, LedgerA
if (acquired->isComplete())
{
Ledger::pointer ledger = acquired->getLedger();
assert(ledger);
cLog(lsDEBUG) << "LedgerAcquireSet::onComplete " << ledger->getLedgerSeq();
ledger->setAccepted();
theApp->getMasterLedger().checkLedgerGap(ledger);
lSet->updateCurrentLedger(ledger);
}
else

View File

@@ -111,14 +111,14 @@ protected:
LedgerAcquire::pointer mCurrentLedger; // ledger we are acquiring
bool mCheckComplete; // should we check to make sure we have all nodes
void updateCurrentLedger(Ledger::pointer currentLedger);
void done();
void addPeers();
static void onComplete(boost::weak_ptr<LedgerAcquireSet>, LedgerAcquire::pointer);
public:
LedgerAcquireSet(Ledger::ref targetLedger, Ledger::ref currentLedger);
LedgerAcquireSet(Ledger::ref targetLedger);
void updateCurrentLedger(Ledger::pointer currentLedger);
};
class LedgerAcquireMaster
@@ -137,10 +137,13 @@ public:
void dropLedger(const uint256& ledgerHash);
bool gotLedgerData(ripple::TMLedgerData& packet, Peer::ref);
void killSet(const LedgerAcquireSet&)
{ mAcquireSet = LedgerAcquireSet::pointer(); }
bool hasSet() { return !!mAcquireSet; }
void killSet(const LedgerAcquireSet&) { mAcquireSet = LedgerAcquireSet::pointer(); }
void makeSet(Ledger::ref target, Ledger::ref current)
{ mAcquireSet = boost::make_shared<LedgerAcquireSet>(boost::ref(target), boost::ref(current)); }
{
mAcquireSet = boost::make_shared<LedgerAcquireSet>(boost::ref(target));
mAcquireSet->updateCurrentLedger(current);
}
};
#endif

View File

@@ -1186,7 +1186,7 @@ void LedgerConsensus::accept(SHAMap::ref set)
cLog(lsINFO) << "Applying transactions from current ledger";
applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, newLCL,
failedTransactions, true);
theApp->getMasterLedger().pushLedger(newLCL, newOL);
theApp->getMasterLedger().pushLedger(newLCL, newOL, true);
mNewLedgerHash = newLCL->getHash();
mState = lcsACCEPTED;
sl.unlock();

View File

@@ -7,6 +7,8 @@
#include "NewcoinAddress.h"
#include "Log.h"
SETUP_LOG();
uint32 LedgerMaster::getCurrentLedgerIndex()
{
return mCurrentLedger->getLedgerSeq();
@@ -22,12 +24,12 @@ void LedgerMaster::pushLedger(Ledger::ref newLedger)
{
// Caller should already have properly assembled this ledger into "ready-to-close" form --
// all candidate transactions must already be applied
Log(lsINFO) << "PushLedger: " << newLedger->getHash();
ScopedLock sl(mLock);
cLog(lsINFO) << "PushLedger: " << newLedger->getHash();
boost::recursive_mutex::scoped_lock ml(mLock);
if (!!mFinalizedLedger)
{
mFinalizedLedger->setClosed();
Log(lsTRACE) << "Finalizes: " << mFinalizedLedger->getHash();
cLog(lsTRACE) << "Finalizes: " << mFinalizedLedger->getHash();
}
mFinalizedLedger = mCurrentLedger;
mCurrentLedger = newLedger;
@@ -36,7 +38,7 @@ void LedgerMaster::pushLedger(Ledger::ref newLedger)
mLastFullLedger = newLedger;
}
void LedgerMaster::pushLedger(Ledger::ref newLCL, Ledger::ref newOL)
void LedgerMaster::pushLedger(Ledger::ref newLCL, Ledger::ref newOL, bool fromConsensus)
{
assert(newLCL->isClosed() && newLCL->isAccepted());
assert(!newOL->isClosed() && !newOL->isAccepted());
@@ -45,14 +47,14 @@ void LedgerMaster::pushLedger(Ledger::ref newLCL, Ledger::ref newOL)
{
assert(newLCL->isClosed());
assert(newLCL->isImmutable());
mLedgerHistory.addAcceptedLedger(newLCL, false);
mLedgerHistory.addAcceptedLedger(newLCL, fromConsensus);
if (mLastFullLedger && (newLCL->getParentHash() == mLastFullLedger->getHash()))
mLastFullLedger = newLCL;
Log(lsINFO) << "StashAccepted: " << newLCL->getHash();
cLog(lsINFO) << "StashAccepted: " << newLCL->getHash();
}
boost::recursive_mutex::scoped_lock ml(mLock);
mFinalizedLedger = newLCL;
ScopedLock sl(mLock);
mCurrentLedger = newOL;
mEngine.setLedger(newOL);
}
@@ -60,11 +62,15 @@ void LedgerMaster::pushLedger(Ledger::ref newLCL, Ledger::ref newOL)
void LedgerMaster::switchLedgers(Ledger::ref lastClosed, Ledger::ref current)
{
assert(lastClosed && current);
mFinalizedLedger = lastClosed;
mFinalizedLedger->setClosed();
mFinalizedLedger->setAccepted();
mCurrentLedger = current;
{
boost::recursive_mutex::scoped_lock ml(mLock);
mFinalizedLedger = lastClosed;
mFinalizedLedger->setClosed();
mFinalizedLedger->setAccepted();
mCurrentLedger = current;
}
assert(!mCurrentLedger->isClosed());
mEngine.setLedger(mCurrentLedger);
}
@@ -77,7 +83,6 @@ void LedgerMaster::storeLedger(Ledger::ref ledger)
}
Ledger::pointer LedgerMaster::closeLedger()
{
boost::recursive_mutex::scoped_lock sl(mLock);
@@ -94,5 +99,29 @@ TER LedgerMaster::doTransaction(const SerializedTransaction& txn, TransactionEng
return result;
}
void LedgerMaster::checkLedgerGap(Ledger::ref ledger)
{
cLog(lsTRACE) << "Checking for ledger gap";
boost::recursive_mutex::scoped_lock sl(mLock);
if (mLastFullLedger && (ledger->getParentHash() == mLastFullLedger->getHash()))
{
mLastFullLedger = ledger;
cLog(lsTRACE) << "Perfect fit, no gap";
return;
}
if (theApp->getMasterLedgerAcquire().hasSet())
return;
if (mLastFullLedger && (ledger->getLedgerSeq() < mLastFullLedger->getLedgerSeq()))
return;
// we have a gap or discontinuity
cLog(lsWARNING) << "Ledger gap found " <<
(mLastFullLedger ? mLastFullLedger->getLedgerSeq() : 0) << " - " << ledger->getLedgerSeq();
theApp->getMasterLedgerAcquire().makeSet(mLastFullLedger, ledger);
}
// vim:ts=4

View File

@@ -47,14 +47,17 @@ public:
TER doTransaction(const SerializedTransaction& txn, TransactionEngineParams params);
void pushLedger(Ledger::ref newLedger);
void pushLedger(Ledger::ref newLCL, Ledger::ref newOL);
void pushLedger(Ledger::ref newLCL, Ledger::ref newOL, bool fromConsensus);
void storeLedger(Ledger::ref);
void setLastFullLedger(Ledger::ref ledger)
{
boost::recursive_mutex::scoped_lock ml(mLock);
mLastFullLedger = ledger;
}
void checkLedgerGap(Ledger::ref ledger);
void switchLedgers(Ledger::ref lastClosed, Ledger::ref newCurrent);
Ledger::pointer closeLedger();

View File

@@ -101,11 +101,12 @@ std::string Log::rotateLog(void)
}
void Log::setMinSeverity(LogSeverity s)
void Log::setMinSeverity(LogSeverity s, bool all)
{
boost::recursive_mutex::scoped_lock sl(sLock);
sMinSeverity = s;
LogPartition::setSeverity(s);
if (all)
LogPartition::setSeverity(s);
}
LogSeverity Log::getMinSeverity()

View File

@@ -96,7 +96,7 @@ public:
static LogSeverity stringToSeverity(const std::string&);
static LogSeverity getMinSeverity();
static void setMinSeverity(LogSeverity);
static void setMinSeverity(LogSeverity, bool all);
static void setLogFile(boost::filesystem::path);
static std::string rotateLog(void);
};

View File

@@ -219,7 +219,7 @@ void Peer::handleConnect(const boost::system::error_code& error, boost::asio::ip
}
else
{
std::cerr << "Connect peer: success." << std::endl;
cLog(lsINFO) << "Connect peer: success.";
mSocketSsl.set_verify_mode(boost::asio::ssl::verify_none);

View File

@@ -1,13 +1,10 @@
// XXX Dynamically limit fetching by distance.
// XXX Want a limit of 2000 validators.
#include "Application.h"
#include "HttpsClient.h"
#include "Log.h"
#include "ParseSection.h"
#include "Serializer.h"
#include "UniqueNodeList.h"
#include "utils.h"
#include <fstream>
#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/asio.hpp>
@@ -17,8 +14,14 @@
#include <boost/mem_fn.hpp>
#include <boost/regex.hpp>
#include <fstream>
#include <iostream>
#include "Application.h"
#include "HttpsClient.h"
#include "Log.h"
#include "ParseSection.h"
#include "Serializer.h"
#include "utils.h"
SETUP_LOG();
#define VALIDATORS_FETCH_SECONDS 30
#define VALIDATORS_FILE_PATH "/" VALIDATORS_FILE_NAME
@@ -42,8 +45,6 @@
#define MIN(x,y) ((x)<(y)?(x):(y))
#endif
SETUP_LOG();
UniqueNodeList::UniqueNodeList(boost::asio::io_service& io_service) :
mdtScoreTimer(io_service),
mFetchActive(0),
@@ -57,8 +58,8 @@ void UniqueNodeList::start()
{
miscLoad();
std::cerr << "Validator fetch updated: " << mtpFetchUpdated << std::endl;
std::cerr << "Validator score updated: " << mtpScoreUpdated << std::endl;
Log(lsDEBUG) << "Validator fetch updated: " << mtpFetchUpdated;
Log(lsDEBUG) << "Validator score updated: " << mtpScoreUpdated;
fetchNext(); // Start fetching.
scoreNext(false); // Start scoring.
@@ -136,17 +137,18 @@ bool UniqueNodeList::scoreRound(std::vector<scoreNode>& vsnNodes)
}
}
std::cerr << "midway: " << std::endl;
BOOST_FOREACH(scoreNode& sn, vsnNodes)
if (sLog(lsTRACE))
{
std::cerr << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","))
<< std::endl;
Log(lsTRACE) << "midway: ";
BOOST_FOREACH(scoreNode& sn, vsnNodes)
{
Log(lsTRACE) << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","));
}
}
// Add roundScore to score.
@@ -160,17 +162,18 @@ bool UniqueNodeList::scoreRound(std::vector<scoreNode>& vsnNodes)
sn.iRoundScore = 0;
}
std::cerr << "finish: " << std::endl;
BOOST_FOREACH(scoreNode& sn, vsnNodes)
if (sLog(lsTRACE))
{
std::cerr << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","))
<< std::endl;
Log(lsTRACE) << "finish: ";
BOOST_FOREACH(scoreNode& sn, vsnNodes)
{
Log(lsTRACE) << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","));
}
}
return bDist;
@@ -283,21 +286,23 @@ void UniqueNodeList::scoreCompute()
}
// For debugging, print out initial scores.
BOOST_FOREACH(scoreNode& sn, vsnNodes)
if (sLog(lsTRACE))
{
std::cerr << str(boost::format("%s| %d, %d, %d")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed)
<< std::endl;
BOOST_FOREACH(scoreNode& sn, vsnNodes)
{
Log(lsTRACE) << str(boost::format("%s| %d, %d, %d")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed);
}
}
// std::cerr << str(boost::format("vsnNodes.size=%d") % vsnNodes.size()) << std::endl;
// cLog(lsTRACE) << str(boost::format("vsnNodes.size=%d") % vsnNodes.size());
// Step through growing list of nodes adding each validation list.
// - Each validator may have provided referals. Add those referals as validators.
for (int iNode=0; iNode != vsnNodes.size(); iNode++)
for (int iNode = 0; iNode != vsnNodes.size(); ++iNode)
{
scoreNode& sn = vsnNodes[iNode];
std::string& strValidator = sn.strValidator;
@@ -342,7 +347,7 @@ void UniqueNodeList::scoreCompute()
iReferral = itEntry->second;
}
// std::cerr << str(boost::format("%s: Public=%s iReferral=%d") % strValidator % strReferral % iReferral) << std::endl;
// cLog(lsTRACE) << str(boost::format("%s: Public=%s iReferral=%d") % strValidator % strReferral % iReferral);
}
else
@@ -353,7 +358,7 @@ void UniqueNodeList::scoreCompute()
? -1 // We ignore domains we can't find entires for.
: itEntry->second;
// std::cerr << str(boost::format("%s: Domain=%s iReferral=%d") % strValidator % strReferral % iReferral) << std::endl;
// cLog(lsTRACE) << str(boost::format("%s: Domain=%s iReferral=%d") % strValidator % strReferral % iReferral);
}
if (iReferral >= 0 && iNode != iReferral)
@@ -369,17 +374,18 @@ void UniqueNodeList::scoreCompute()
for (int i = SCORE_ROUNDS; bDist && i--;)
bDist = scoreRound(vsnNodes);
std::cerr << "Scored:" << std::endl;
BOOST_FOREACH(scoreNode& sn, vsnNodes)
if (sLog(lsTRACE))
{
std::cerr << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","))
<< std::endl;
Log(lsTRACE) << "Scored:";
BOOST_FOREACH(scoreNode& sn, vsnNodes)
{
Log(lsTRACE) << str(boost::format("%s| %d, %d, %d: [%s]")
% sn.strValidator
% sn.iScore
% sn.iRoundScore
% sn.iRoundSeed
% strJoin(sn.viReferrals.begin(), sn.viReferrals.end(), ","));
}
}
// Persist validator scores.
@@ -454,7 +460,7 @@ void UniqueNodeList::scoreCompute()
{
umValidators[db->getStrBinary("Validator")] = db->getInt("Count");
// std::cerr << strValidator << ":" << db->getInt("Count") << std::endl;
// cLog(lsTRACE) << strValidator << ":" << db->getInt("Count");
}
}
@@ -529,11 +535,11 @@ void UniqueNodeList::scoreTimerHandler(const boost::system::error_code& err)
mtpScoreNext = boost::posix_time::ptime(boost::posix_time::not_a_date_time); // Timer not set.
mtpScoreStart = boost::posix_time::second_clock::universal_time(); // Scoring.
std::cerr << "Scoring: Start" << std::endl;
cLog(lsTRACE) << "Scoring: Start";
scoreCompute();
std::cerr << "Scoring: End" << std::endl;
cLog(lsTRACE) << "Scoring: End";
// Save update time.
mtpScoreUpdated = mtpScoreStart;
@@ -553,7 +559,7 @@ void UniqueNodeList::scoreTimerHandler(const boost::system::error_code& err)
// <-- bNow: true, to force scoring for debugging.
void UniqueNodeList::scoreNext(bool bNow)
{
// std::cerr << str(boost::format("scoreNext: mtpFetchUpdated=%s mtpScoreStart=%s mtpScoreUpdated=%s mtpScoreNext=%s") % mtpFetchUpdated % mtpScoreStart % mtpScoreUpdated % mtpScoreNext) << std::endl;
// cLog(lsTRACE) << str(boost::format("scoreNext: mtpFetchUpdated=%s mtpScoreStart=%s mtpScoreUpdated=%s mtpScoreNext=%s") % mtpFetchUpdated % mtpScoreStart % mtpScoreUpdated % mtpScoreNext);
bool bCanScore = mtpScoreStart.is_not_a_date_time() // Not scoring.
&& !mtpFetchUpdated.is_not_a_date_time(); // Something to score.
@@ -572,7 +578,7 @@ void UniqueNodeList::scoreNext(bool bNow)
mtpScoreNext = boost::posix_time::second_clock::universal_time() // Past now too.
+ boost::posix_time::seconds(bNow ? 0 : SCORE_DELAY_SECONDS);
// std::cerr << str(boost::format("scoreNext: @%s") % mtpScoreNext) << std::endl;
// cLog(lsTRACE) << str(boost::format("scoreNext: @%s") % mtpScoreNext);
mdtScoreTimer.expires_at(mtpScoreNext);
mdtScoreTimer.async_wait(boost::bind(&UniqueNodeList::scoreTimerHandler, this, _1));
}
@@ -652,10 +658,9 @@ void UniqueNodeList::processIps(const std::string& strSite, const NewcoinAddress
}
else
{
std::cerr
cLog(lsTRACE)
<< str(boost::format("Validator: '%s' ["SECTION_IPS"]: rejecting '%s'")
% strSite % strReferral)
<< std::endl;
% strSite % strReferral);
}
}
@@ -684,12 +689,11 @@ int UniqueNodeList::processValidators(const std::string& strSite, const std::str
std::string strNodePublic = naNodePublic.isValid() ? naNodePublic.humanNodePublic() : strValidatorsSrc;
int iValues = 0;
std::cerr
cLog(lsTRACE)
<< str(boost::format("Validator: '%s' : '%s' : processing %d validators.")
% strSite
% strValidatorsSrc
% ( pmtVecStrValidators ? pmtVecStrValidators->size() : 0))
<< std::endl;
% ( pmtVecStrValidators ? pmtVecStrValidators->size() : 0));
// Remove all current Validator's entries in ValidatorReferrals
{
@@ -876,7 +880,7 @@ void UniqueNodeList::processFile(const std::string& strDomain, const NewcoinAddr
if ((pvCurrencies = sectionEntries(secSite, SECTION_CURRENCIES)) && pvCurrencies->size())
{
// XXX Process currencies.
std::cerr << "Ignoring currencies: not implemented." << std::endl;
cLog(lsWARNING) << "Ignoring currencies: not implemented.";
}
getValidatorsUrl(naNodePublic, secSite);
@@ -890,15 +894,14 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
if (bGood)
{
std::cerr << boost::format("Validator: '%s' received " NODE_FILE_NAME ".") % strDomain << std::endl;
cLog(lsTRACE) << boost::format("Validator: '%s' received " NODE_FILE_NAME ".") % strDomain;
}
else
{
std::cerr
cLog(lsTRACE)
<< boost::format("Validator: '%s' unable to retrieve " NODE_FILE_NAME ": %s")
% strDomain
% err.message()
<< std::endl;
% err.message();
}
//
@@ -910,21 +913,19 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
{
bGood = false;
std::cerr
cLog(lsTRACE)
<< boost::format("Validator: '%s' bad " NODE_FILE_NAME " missing single entry for " SECTION_DOMAIN ".")
% strDomain
<< std::endl;
% strDomain;
}
if (bGood && strSite != strDomain)
{
bGood = false;
std::cerr
cLog(lsTRACE)
<< boost::format("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_DOMAIN " does not match: %s")
% strDomain
% strSite
<< std::endl;
% strSite;
}
//
@@ -937,10 +938,9 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
// Bad [validation_public_key] section.
bGood = false;
std::cerr
cLog(lsTRACE)
<< boost::format("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_PUBLIC_KEY " does not have single entry.")
% strDomain
<< std::endl;
% strDomain;
}
NewcoinAddress naNodePublic;
@@ -950,16 +950,15 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
// Bad public key.
bGood = false;
std::cerr
cLog(lsTRACE)
<< boost::format("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_PUBLIC_KEY " is bad: ")
% strDomain
% strNodePublicKey
<< std::endl;
% strNodePublicKey;
}
if (bGood)
{
// std::cerr << boost::format("naNodePublic: '%s'") % naNodePublic.humanNodePublic() << std::endl;
// cLog(lsTRACE) << boost::format("naNodePublic: '%s'") % naNodePublic.humanNodePublic();
seedDomain sdCurrent;
@@ -975,7 +974,7 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
// XXX Only if no other refs to keep it arround, other wise we have an attack vector.
sdCurrent.naPublicKey = naNodePublic;
// std::cerr << boost::format("sdCurrent.naPublicKey: '%s'") % sdCurrent.naPublicKey.humanNodePublic() << std::endl;
// cLog(lsTRACE) << boost::format("sdCurrent.naPublicKey: '%s'") % sdCurrent.naPublicKey.humanNodePublic();
sdCurrent.tpFetch = boost::posix_time::second_clock::universal_time();
sdCurrent.iSha256 = iSha256;
@@ -984,12 +983,12 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
if (bChangedB)
{
std::cerr << boost::format("Validator: '%s' processing new " NODE_FILE_NAME ".") % strDomain << std::endl;
cLog(lsTRACE) << boost::format("Validator: '%s' processing new " NODE_FILE_NAME ".") % strDomain;
processFile(strDomain, naNodePublic, secSite);
}
else
{
std::cerr << boost::format("Validator: '%s' no change for " NODE_FILE_NAME ".") % strDomain << std::endl;
cLog(lsTRACE) << boost::format("Validator: '%s' no change for " NODE_FILE_NAME ".") % strDomain;
fetchFinish();
}
}
@@ -1005,7 +1004,7 @@ void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::sy
// Get the ripple.txt and process it.
void UniqueNodeList::fetchProcess(std::string strDomain)
{
std::cerr << "Fetching '" NODE_FILE_NAME "' from '" << strDomain << "'." << std::endl;
cLog(lsTRACE) << "Fetching '" NODE_FILE_NAME "' from '" << strDomain << "'.";
std::deque<std::string> deqSites;
@@ -1030,7 +1029,7 @@ void UniqueNodeList::fetchTimerHandler(const boost::system::error_code& err)
if (!err)
{
// Time to check for another fetch.
std::cerr << "fetchTimerHandler" << std::endl;
cLog(lsTRACE) << "fetchTimerHandler";
fetchNext();
}
}
@@ -1064,7 +1063,7 @@ void UniqueNodeList::fetchNext()
tpNext = ptFromSeconds(iNext);
tpNow = boost::posix_time::second_clock::universal_time();
std::cerr << str(boost::format("fetchNext: iNext=%s tpNext=%s tpNow=%s") % iNext % tpNext % tpNow) << std::endl;
cLog(lsTRACE) << str(boost::format("fetchNext: iNext=%s tpNext=%s tpNow=%s") % iNext % tpNext % tpNow);
strDomain = db->getStrBinary("Domain");
db->endIterRows();
@@ -1083,13 +1082,13 @@ void UniqueNodeList::fetchNext()
if (strDomain.empty() || bFull)
{
std::cerr << str(boost::format("fetchNext: strDomain=%s bFull=%d") % strDomain % bFull) << std::endl;
cLog(lsTRACE) << str(boost::format("fetchNext: strDomain=%s bFull=%d") % strDomain % bFull);
nothing();
}
else if (tpNext > tpNow)
{
std::cerr << str(boost::format("fetchNext: set timer : strDomain=%s") % strDomain) << std::endl;
cLog(lsTRACE) << str(boost::format("fetchNext: set timer : strDomain=%s") % strDomain);
// Fetch needs to happen in the future. Set a timer to wake us.
mtpFetchNext = tpNext;
@@ -1098,7 +1097,7 @@ void UniqueNodeList::fetchNext()
}
else
{
std::cerr << str(boost::format("fetchNext: fetch now: strDomain=%s tpNext=%s tpNow=%s") % strDomain % tpNext %tpNow) << std::endl;
cLog(lsTRACE) << str(boost::format("fetchNext: fetch now: strDomain=%s tpNext=%s tpNow=%s") % strDomain % tpNext %tpNow);
// Fetch needs to happen now.
mtpFetchNext = boost::posix_time::ptime(boost::posix_time::not_a_date_time);
@@ -1115,7 +1114,7 @@ void UniqueNodeList::fetchNext()
setSeedDomains(sdCurrent, false);
std::cerr << "Validator: '" << strDomain << "' fetching " NODE_FILE_NAME "." << std::endl;
cLog(lsTRACE) << "Validator: '" << strDomain << "' fetching " NODE_FILE_NAME ".";
fetchProcess(strDomain); // Go get it.
@@ -1210,7 +1209,7 @@ void UniqueNodeList::setSeedDomains(const seedDomain& sdSource, bool bNext)
int iScan = iToSeconds(sdSource.tpScan);
int iFetch = iToSeconds(sdSource.tpFetch);
// std::cerr << str(boost::format("setSeedDomains: iNext=%s tpNext=%s") % iNext % sdSource.tpNext) << std::endl;
// cLog(lsTRACE) << str(boost::format("setSeedDomains: iNext=%s tpNext=%s") % iNext % sdSource.tpNext);
std::string strSql = str(boost::format("REPLACE INTO SeedDomains (Domain,PublicKey,Source,Next,Scan,Fetch,Sha256,Comment) VALUES (%s, %s, %s, %d, %d, %d, '%s', %s);")
% db->escape(sdSource.strDomain)
@@ -1228,7 +1227,7 @@ void UniqueNodeList::setSeedDomains(const seedDomain& sdSource, bool bNext)
if (!db->executeSQL(strSql))
{
// XXX Check result.
std::cerr << "setSeedDomains: failed." << std::endl;
cLog(lsWARNING) << "setSeedDomains: failed.";
}
if (bNext && (mtpFetchNext.is_not_a_date_time() || mtpFetchNext > sdSource.tpNext))
@@ -1247,10 +1246,10 @@ void UniqueNodeList::nodeAddDomain(std::string strDomain, validatorSource vsWhy,
boost::to_lower(strDomain);
// YYY Would be best to verify strDomain is a valid domain.
// std::cerr << str(boost::format("nodeAddDomain: '%s' %c '%s'")
// cLog(lsTRACE) << str(boost::format("nodeAddDomain: '%s' %c '%s'")
// % strDomain
// % vsWhy
// % strComment) << std::endl;
// % strComment);
seedDomain sdCurrent;
@@ -1348,7 +1347,7 @@ void UniqueNodeList::setSeedNodes(const seedNode& snSource, bool bNext)
int iScan = iToSeconds(snSource.tpScan);
int iFetch = iToSeconds(snSource.tpFetch);
// std::cerr << str(boost::format("setSeedNodes: iNext=%s tpNext=%s") % iNext % sdSource.tpNext) << std::endl;
// cLog(lsTRACE) << str(boost::format("setSeedNodes: iNext=%s tpNext=%s") % iNext % sdSource.tpNext);
assert(snSource.naPublicKey.isValid());
@@ -1368,7 +1367,7 @@ void UniqueNodeList::setSeedNodes(const seedNode& snSource, bool bNext)
if (!db->executeSQL(strSql))
{
// XXX Check result.
std::cerr << "setSeedNodes: failed." << std::endl;
cLog(lsTRACE) << "setSeedNodes: failed.";
}
}
@@ -1485,21 +1484,21 @@ bool UniqueNodeList::nodeLoad(boost::filesystem::path pConfig)
{
if (pConfig.empty())
{
std::cerr << VALIDATORS_FILE_NAME " path not specified." << std::endl;
cLog(lsINFO) << VALIDATORS_FILE_NAME " path not specified.";
return false;
}
if (!boost::filesystem::exists(pConfig))
{
std::cerr << str(boost::format(VALIDATORS_FILE_NAME " not found: %s") % pConfig) << std::endl;
cLog(lsWARNING) << str(boost::format(VALIDATORS_FILE_NAME " not found: %s") % pConfig);
return false;
}
if (!boost::filesystem::is_regular_file(pConfig))
{
std::cerr << str(boost::format(VALIDATORS_FILE_NAME " not regular file: %s") % pConfig) << std::endl;
cLog(lsWARNING) << str(boost::format(VALIDATORS_FILE_NAME " not regular file: %s") % pConfig);
return false;
}
@@ -1508,7 +1507,7 @@ bool UniqueNodeList::nodeLoad(boost::filesystem::path pConfig)
if (!ifsDefault)
{
std::cerr << str(boost::format(VALIDATORS_FILE_NAME " failed to open: %s") % pConfig) << std::endl;
cLog(lsFATAL) << str(boost::format(VALIDATORS_FILE_NAME " failed to open: %s") % pConfig);
return false;
}
@@ -1520,21 +1519,21 @@ bool UniqueNodeList::nodeLoad(boost::filesystem::path pConfig)
if (ifsDefault.bad())
{
std::cerr << str(boost::format("Failed to read: %s") % pConfig) << std::endl;
cLog(lsFATAL) << str(boost::format("Failed to read: %s") % pConfig);
return false;
}
nodeProcess("local", strValidators, pConfig.string());
std::cerr << str(boost::format("Processing: %s") % pConfig) << std::endl;
cLog(lsTRACE) << str(boost::format("Processing: %s") % pConfig);
return true;
}
void UniqueNodeList::validatorsResponse(const boost::system::error_code& err, std::string strResponse)
{
std::cerr << "Fetch '" VALIDATORS_FILE_NAME "' complete." << std::endl;
cLog(lsTRACE) << "Fetch '" VALIDATORS_FILE_NAME "' complete.";
if (!err)
{
@@ -1542,7 +1541,7 @@ void UniqueNodeList::validatorsResponse(const boost::system::error_code& err, st
}
else
{
std::cerr << "Error: " << err.message() << std::endl;
cLog(lsWARNING) << "Error: " << err.message();
}
}
@@ -1657,7 +1656,7 @@ void UniqueNodeList::nodeProcess(const std::string& strSite, const std::string&
}
else
{
std::cerr << "WARNING: '" VALIDATORS_FILE_NAME "' missing [" SECTION_VALIDATORS "]." << std::endl;
cLog(lsWARNING) << "'" VALIDATORS_FILE_NAME "' missing [" SECTION_VALIDATORS "].";
}
}

View File

@@ -10,7 +10,7 @@
#include "HttpsClient.h"
#include "ParseSection.h"
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
@@ -48,7 +48,7 @@ private:
boost::posix_time::ptime mtpScoreUpdated;
boost::posix_time::ptime mtpFetchUpdated;
boost::recursive_mutex mUNLLock;
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;

View File

@@ -121,9 +121,10 @@ int main(int argc, char* argv[])
{
nothing();
}
else if (argc >= 2 && !strcmp(argv[1], "--test")) {
else if (argc >= 2 && !strcmp(argv[1], "--test"))
{
bTest = true;
Log::setMinSeverity(lsTRACE);
Log::setMinSeverity(lsTRACE, true);
}
else
{
@@ -143,9 +144,9 @@ int main(int argc, char* argv[])
}
if (vm.count("verbose"))
{
Log::setMinSeverity(lsTRACE);
}
Log::setMinSeverity(lsTRACE, true);
else if (!bTest)
Log::setMinSeverity(lsWARNING, true);
if (!iResult)
{