From fb487bdb41f362e4841fb4b8a8868d236b0639d9 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 2 Jun 2013 11:17:46 -0700 Subject: [PATCH] Refactor UniqueNodeList into IUniqueNodeList --- modules/ripple_client/ripple_client.cpp | 25 --- modules/ripple_main/ripple_main.cpp | 18 +- newcoin.vcxproj | 14 +- newcoin.vcxproj.filters | 70 ++++---- src/cpp/ripple/Application.cpp | 4 +- src/cpp/ripple/Application.h | 6 +- src/cpp/ripple/ConnectionPool.cpp | 4 +- src/cpp/ripple/HttpsClient.cpp | 4 +- src/cpp/ripple/Offer.h | 5 + src/cpp/ripple/Peer.cpp | 4 +- src/cpp/ripple/RPCDoor.h | 14 +- src/cpp/ripple/RPCHandler.cpp | 4 +- src/cpp/ripple/UniqueNodeList.h | 167 ------------------ src/cpp/ripple/ripple_IUniqueNodeList.h | 53 ++++++ ...NodeList.cpp => ripple_UniqueNodeList.cpp} | 157 ++++++++++++++-- 15 files changed, 282 insertions(+), 267 deletions(-) delete mode 100644 src/cpp/ripple/UniqueNodeList.h create mode 100644 src/cpp/ripple/ripple_IUniqueNodeList.h rename src/cpp/ripple/{UniqueNodeList.cpp => ripple_UniqueNodeList.cpp} (89%) diff --git a/modules/ripple_client/ripple_client.cpp b/modules/ripple_client/ripple_client.cpp index 27bf4cc5ef..ad6ceb49c4 100644 --- a/modules/ripple_client/ripple_client.cpp +++ b/modules/ripple_client/ripple_client.cpp @@ -23,28 +23,3 @@ */ #include "ripple_client.h" - -#include "../ripple_data/ripple_data.h" - -// 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 -#pragma warning (disable: 4309) // truncation of constant value -#endif - -#include "src/cpp/ripple/HTTPRequest.cpp" -#include "src/cpp/ripple/HttpsClient.cpp" - -#include "src/cpp/ripple/CallRPC.cpp" -#include "src/cpp/ripple/rpc.cpp" -#include "src/cpp/ripple/RPCDoor.cpp" -#include "src/cpp/ripple/RPCErr.cpp" -#include "src/cpp/ripple/RPCHandler.cpp" -#include "src/cpp/ripple/RPCServer.cpp" -#include "src/cpp/ripple/RPCSub.cpp" - -#ifdef _MSC_VER -//#pragma warning (pop) -#endif diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index 6d8212b6ec..5ff475a618 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -130,7 +130,8 @@ #include "src/cpp/ripple/ripple_IFeeVote.h" #include "src/cpp/ripple/ripple_ILoadFeeTrack.h" #include "src/cpp/ripple/ripple_IValidations.h" -#include "src/cpp/ripple/FeatureTable.h" +#include "src/cpp/ripple/ripple_IUniqueNodeList.h" +#include "src/cpp/ripple/FeatureTable.h" // ?? //------------------------------------------------------------------------------ @@ -238,7 +239,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) // sockets #include "src/cpp/ripple/Suppression.cpp" // no log -#include "src/cpp/ripple/UniqueNodeList.cpp" #include "src/cpp/ripple/SNTPClient.cpp" #include "src/cpp/ripple/ConnectionPool.cpp" #include "src/cpp/ripple/NetworkOPs.cpp" @@ -247,6 +247,19 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/WSDoor.cpp" // uses logging in WSConnection.h #include "src/cpp/ripple/ripple_LogWebsockets.cpp" +// http +#include "src/cpp/ripple/HTTPRequest.cpp" +#include "src/cpp/ripple/HttpsClient.cpp" + +// rpc +#include "src/cpp/ripple/CallRPC.cpp" +#include "src/cpp/ripple/rpc.cpp" +#include "src/cpp/ripple/RPCDoor.cpp" +#include "src/cpp/ripple/RPCErr.cpp" +#include "src/cpp/ripple/RPCHandler.cpp" +#include "src/cpp/ripple/RPCServer.cpp" +#include "src/cpp/ripple/RPCSub.cpp" + //------------------------------------------------------------------------------ // Implementation of interfaces @@ -254,6 +267,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/ripple_FeeVote.cpp" #include "src/cpp/ripple/ripple_LoadFeeTrack.cpp" #include "src/cpp/ripple/ripple_Validations.cpp" +#include "src/cpp/ripple/ripple_UniqueNodeList.cpp" //------------------------------------------------------------------------------ diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 04c0f4504d..c67d9a7e43 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -992,6 +992,12 @@ true true + + true + true + true + true + true true @@ -1172,12 +1178,6 @@ true true - - true - true - true - true - true true @@ -1657,6 +1657,7 @@ + @@ -1683,7 +1684,6 @@ - diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 23d1c4db5c..c60ebd198b 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -52,24 +52,15 @@ {84e43f43-816e-4ccd-80c2-38b322904894} - - {97c96b68-70fd-4679-89fc-c1c8c87c265e} - {a5190241-c5bc-4e23-8ef1-6adf757c75e3} {1a379c07-ccf1-4636-8018-2cfc0685edf0} - - {3f351c55-360d-40bc-a136-4944ce572efd} - {6097a179-ddad-4c69-9a34-2e3fc2c9fa1d} - - {29cd2103-d553-4d82-9e6a-224e3b1cb667} - {96cbc9ff-0118-4844-bb4c-05aef58a60b5} @@ -139,6 +130,15 @@ {7f76ce57-c428-487e-97a0-979c0990a81d} + + {3f351c55-360d-40bc-a136-4944ce572efd} + + + {29cd2103-d553-4d82-9e6a-224e3b1cb667} + + + {97c96b68-70fd-4679-89fc-c1c8c87c265e} + @@ -565,25 +565,25 @@ 1. Modules\ripple_main\processing - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client + 2. Empty\ripple_client 1. Modules\ripple_main\transactions @@ -592,7 +592,7 @@ 1. Modules\ripple_main\transactions - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc 1. Modules\ripple_db @@ -610,10 +610,10 @@ 1. Modules\ripple_main - 1. Modules\ripple_client\http + 1. Modules\ripple_main\http - 1. Modules\ripple_client\http + 1. Modules\ripple_main\http 2. Empty\ripple_net @@ -789,9 +789,6 @@ 1. Modules\ripple_main\sockets - - 1. Modules\ripple_main\sockets - 1. Modules\ripple_main\sockets @@ -801,6 +798,9 @@ 0. Third Party Code\beast + + 1. Modules\ripple_main\sockets + @@ -1215,28 +1215,28 @@ 1. Modules\ripple_main\processing - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc - 1. Modules\ripple_client + 2. Empty\ripple_client 1. Modules\ripple_main\transactions @@ -1245,7 +1245,7 @@ 1. Modules\ripple_main\transactions - 1. Modules\ripple_client\rpc + 1. Modules\ripple_main\rpc 1. Modules\ripple_db @@ -1260,10 +1260,10 @@ 1. Modules\ripple_main - 1. Modules\ripple_client\http + 1. Modules\ripple_main\http - 1. Modules\ripple_client\http + 1. Modules\ripple_main\http 2. Empty\ripple_net @@ -1481,10 +1481,10 @@ 1. Modules\ripple_main\sockets - + 1. Modules\ripple_main\sockets - + 1. Modules\ripple_main\sockets diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index d89794e7fa..7be6cb9ccf 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -27,16 +27,18 @@ Application::Application () : mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1) , mIOWork (mIOService) , mAuxWork (mAuxService) - , mUNL (mIOService) , mNetOps (mIOService, &mLedgerMaster) , mTempNodeCache ("NodeCache", 16384, 90) , mHashedObjectStore (16384, 300) , mSLECache ("LedgerEntryCache", 4096, 120) , mSNTPClient (mAuxService) , mJobQueue (mIOService) + // VFALCO: New stuff , mFeeVote (IFeeVote::New (10, 50 * SYSTEM_CURRENCY_PARTS, 12.5 * SYSTEM_CURRENCY_PARTS)) , mFeeTrack (ILoadFeeTrack::New ()) , mValidations (IValidations::New ()) + , mUNL (IUniqueNodeList::New (mIOService)) + // VFALCO: End new stuff , mFeatureTable (2 * 7 * 24 * 60 * 60, 200) // two weeks, 200/256 // VFALCO: TODO replace all NULL with nullptr , mRpcDB (NULL) diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index a102f88207..47a0ad501a 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -8,7 +8,6 @@ #include "../database/database.h" #include "LedgerMaster.h" -#include "UniqueNodeList.h" #include "ConnectionPool.h" #include "FeatureTable.h" #include "LedgerAcquire.h" @@ -33,6 +32,7 @@ class IFeatureTable; class IFeeVote; class ILoadFeeTrack; class IValidations; +class IUniqueNodeList; class RPCDoor; class PeerDoor; @@ -47,7 +47,6 @@ class Application boost::recursive_mutex mMasterLock; Wallet mWallet; - UniqueNodeList mUNL; LedgerMaster mLedgerMaster; LedgerAcquireMaster mMasterLedgerAcquire; TransactionMaster mMasterTransaction; @@ -67,6 +66,7 @@ class Application beast::ScopedPointer mFeeVote; beast::ScopedPointer mFeeTrack; beast::ScopedPointer mValidations; + beast::ScopedPointer mUNL; // VFALCO: End Clean stuff FeatureTable mFeatureTable; @@ -102,7 +102,7 @@ public: ConnectionPool& getConnectionPool() { return mConnectionPool; } - UniqueNodeList& getUNL() { return mUNL; } + IUniqueNodeList& getUNL() { return *mUNL; } Wallet& getWallet() { return mWallet ; } NetworkOPs& getOPs() { return mNetOps; } diff --git a/src/cpp/ripple/ConnectionPool.cpp b/src/cpp/ripple/ConnectionPool.cpp index 1f603418c0..641907babe 100644 --- a/src/cpp/ripple/ConnectionPool.cpp +++ b/src/cpp/ripple/ConnectionPool.cpp @@ -291,8 +291,8 @@ void ConnectionPool::connectTo(const std::string& strIp, int iPort) db->executeSQL(str(boost::format("REPLACE INTO PeerIps (IpPort,Score,Source,ScanNext) values (%s,%d,'%c',0);") % sqlEscape(str(boost::format("%s %d") % strIp % iPort)) - % theApp->getUNL().iSourceScore(UniqueNodeList::vsManual) - % char(UniqueNodeList::vsManual))); + % theApp->getUNL().iSourceScore(IUniqueNodeList::vsManual) + % char(IUniqueNodeList::vsManual))); } scanRefresh(); diff --git a/src/cpp/ripple/HttpsClient.cpp b/src/cpp/ripple/HttpsClient.cpp index f473f94933..9720be7948 100644 --- a/src/cpp/ripple/HttpsClient.cpp +++ b/src/cpp/ripple/HttpsClient.cpp @@ -139,7 +139,7 @@ void HttpsClient::handleDeadline(const boost::system::error_code& ecResult) // Mark us as shutting down. // XXX Use our own error code. - mShutdown = boost::system::error_code(errc::bad_address, system_category()); + mShutdown = boost::system::error_code(boost::system::errc::bad_address, boost::system::system_category()); // Cancel any resolving. mResolver.cancel(); @@ -301,7 +301,7 @@ void HttpsClient::handleHeader(const boost::system::error_code& ecResult, std::s { // XXX Use our own error code. WriteLog (lsTRACE, HttpsClient) << "No status code"; - invokeComplete(boost::system::error_code(errc::bad_address, system_category())); + invokeComplete(boost::system::error_code(boost::system::errc::bad_address, boost::system::system_category())); return; } mStatus = lexical_cast_st(smMatch[1]); diff --git a/src/cpp/ripple/Offer.h b/src/cpp/ripple/Offer.h index 82bc586465..dee556228c 100644 --- a/src/cpp/ripple/Offer.h +++ b/src/cpp/ripple/Offer.h @@ -1,3 +1,6 @@ +#ifndef RIPPLE_OFFER_H +#define RIPPLE_OFFER_H + #include "AccountItems.h" class Offer : public AccountItem @@ -23,4 +26,6 @@ public: }; +#endif + // vim:ts=4 diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index e3dcda0985..9a49e1bf66 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -792,7 +792,7 @@ void Peer::recvHello(ripple::TMHello& packet) // Don't save IP address if the node wants privacy. // Note: We don't go so far as to delete it. If a node which has previously announced itself now wants // privacy, it should at least change its port. - theApp->getConnectionPool().savePeer(strIP, iPort, UniqueNodeList::vsInbound); + theApp->getConnectionPool().savePeer(strIP, iPort, IUniqueNodeList::vsInbound); } } @@ -1185,7 +1185,7 @@ void Peer::recvPeers(ripple::TMPeers& packet) { //WriteLog (lsINFO, Peer) << "Peer: Learning: " << ADDRESS(this) << ": " << i << ": " << strIP << " " << iPort; - theApp->getConnectionPool().savePeer(strIP, iPort, UniqueNodeList::vsTold); + theApp->getConnectionPool().savePeer(strIP, iPort, IUniqueNodeList::vsTold); } } } diff --git a/src/cpp/ripple/RPCDoor.h b/src/cpp/ripple/RPCDoor.h index b1e01e2e33..ddb6a97684 100644 --- a/src/cpp/ripple/RPCDoor.h +++ b/src/cpp/ripple/RPCDoor.h @@ -1,5 +1,7 @@ +#ifndef RIPPLE_RPCDOOR_H +#define RIPPLE_RPCDOOR_H + #include "RPCServer.h" -#include /* Handles incoming connections from people making RPC Requests @@ -7,6 +9,11 @@ Handles incoming connections from people making RPC Requests class RPCDoor { +public: + explicit RPCDoor (boost::asio::io_service& io_service); + ~RPCDoor (); + +private: boost::asio::ip::tcp::acceptor mAcceptor; boost::asio::deadline_timer mDelayTimer; @@ -15,7 +22,6 @@ class RPCDoor const boost::system::error_code& error); bool isClientAllowed(const std::string& ip); -public: - RPCDoor(boost::asio::io_service& io_service); - ~RPCDoor(); }; + +#endif diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 0f9d0c6e0b..d56272bcfd 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -2391,13 +2391,13 @@ Json::Value RPCHandler::doUnlAdd(Json::Value jvRequest, int& cost, ScopedLock& M if (raNodePublic.setNodePublic(strNode)) { - theApp->getUNL().nodeAddPublic(raNodePublic, UniqueNodeList::vsManual, strComment); + theApp->getUNL().nodeAddPublic(raNodePublic, IUniqueNodeList::vsManual, strComment); return "adding node by public key"; } else { - theApp->getUNL().nodeAddDomain(strNode, UniqueNodeList::vsManual, strComment); + theApp->getUNL().nodeAddDomain(strNode, IUniqueNodeList::vsManual, strComment); return "adding node by domain"; } diff --git a/src/cpp/ripple/UniqueNodeList.h b/src/cpp/ripple/UniqueNodeList.h deleted file mode 100644 index 6cfb45bd44..0000000000 --- a/src/cpp/ripple/UniqueNodeList.h +++ /dev/null @@ -1,167 +0,0 @@ -#ifndef __UNIQUE_NODE_LIST__ -#define __UNIQUE_NODE_LIST__ - -#include -#include - -#include -#include -#include - -#include "Config.h" -#include "HttpsClient.h" -#include "ParseSection.h" - -// Guarantees minimum throughput of 1 node per second. -#define NODE_FETCH_JOBS 10 -#define NODE_FETCH_SECONDS 10 -#define NODE_FILE_BYTES_MAX (50<<10) // 50k -#define NODE_FILE_NAME SYSTEM_NAME ".txt" -#define NODE_FILE_PATH "/" NODE_FILE_NAME - -// Wait for validation information to be stable before scoring. -// #define SCORE_DELAY_SECONDS 20 -#define SCORE_DELAY_SECONDS 5 - -// Don't bother propagating past this number of rounds. -#define SCORE_ROUNDS 10 - -class UniqueNodeList -{ -public: - typedef enum { - vsConfig = 'C', // rippled.cfg - vsInbound = 'I', - vsManual = 'M', - vsReferral = 'R', - vsTold = 'T', - vsValidator = 'V', // validators.txt - vsWeb = 'W', - } validatorSource; - - typedef long score; - -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 mUNL; - - bool miscLoad(); - bool miscSave(); - - typedef struct { - std::string strDomain; - RippleAddress naPublicKey; - validatorSource vsSource; - boost::posix_time::ptime tpNext; - boost::posix_time::ptime tpScan; - boost::posix_time::ptime tpFetch; - uint256 iSha256; - std::string strComment; - } seedDomain; - - typedef struct { - RippleAddress naPublicKey; - validatorSource vsSource; - boost::posix_time::ptime tpNext; - boost::posix_time::ptime tpScan; - boost::posix_time::ptime tpFetch; - uint256 iSha256; - std::string strComment; - } seedNode; - - // Used to distribute scores. - typedef struct { - int iScore; - int iRoundScore; - int iRoundSeed; - int iSeen; - std::string strValidator; // The public key. - std::vector viReferrals; - } scoreNode; - - std::map sClusterNodes; - - typedef boost::unordered_map strIndex; - typedef std::pair ipPort; - typedef boost::unordered_map, score> epScore; - - void trustedLoad(); - - bool scoreRound(std::vector& vsnNodes); - - 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(); - void fetchProcess(std::string strDomain); - void fetchTimerHandler(const boost::system::error_code& err); - - void getValidatorsUrl(const RippleAddress& naNodePublic, section secSite); - void getIpsUrl(const RippleAddress& naNodePublic, section secSite); - bool responseIps(const std::string& strSite, const RippleAddress& naNodePublic, const boost::system::error_code& err, int iStatus, const std::string& strIpsFile); - 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); - - void processFile(const std::string& strDomain, const RippleAddress& naNodePublic, section secSite); - - bool getSeedDomains(const std::string& strDomain, seedDomain& dstSeedDomain); - void setSeedDomains(const seedDomain& dstSeedDomain, bool bNext); - - bool getSeedNodes(const RippleAddress& naNodePublic, seedNode& dstSeedNode); - void setSeedNodes(const seedNode& snSource, bool bNext); - - 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); - - // 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); -}; - -#endif -// vim:ts=4 diff --git a/src/cpp/ripple/ripple_IUniqueNodeList.h b/src/cpp/ripple/ripple_IUniqueNodeList.h new file mode 100644 index 0000000000..0a8cccccc7 --- /dev/null +++ b/src/cpp/ripple/ripple_IUniqueNodeList.h @@ -0,0 +1,53 @@ +#ifndef RIPPLE_IUNIQUENODELIST_H +#define RIPPLE_IUNIQUENODELIST_H + +class IUniqueNodeList +{ +public: + typedef enum { + vsConfig = 'C', // rippled.cfg + vsInbound = 'I', + vsManual = 'M', + vsReferral = 'R', + vsTold = 'T', + vsValidator = 'V', // validators.txt + vsWeb = 'W', + } validatorSource; + + // VFALCO: TODO, rename this to use the right coding style + typedef long score; + +public: + // VFALCO: TODO, make this not use boost::asio... + static IUniqueNodeList* New (boost::asio::io_service& io_service); + + virtual ~IUniqueNodeList () { } + + // VFALCO: TODO, Roll this into the constructor so there is one less state. + 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 nodeRemovePublic(const RippleAddress& naNodePublic) = 0; + virtual void nodeRemoveDomain(std::string strDomain) = 0; + virtual void nodeReset() = 0; + + virtual void nodeScore() = 0; + + virtual bool nodeInUNL(const RippleAddress& naNodePublic) = 0; + virtual bool nodeInCluster(const RippleAddress& naNodePublic) = 0; + virtual bool nodeInCluster(const RippleAddress& naNodePublic, std::string& name) = 0; + + virtual void nodeBootstrap () = 0; + virtual bool nodeLoad (boost::filesystem::path pConfig) = 0; + virtual void nodeNetwork () = 0; + + virtual Json::Value getUnlJson () = 0; + + virtual int iSourceScore (validatorSource vsWhy) = 0; +}; + +#endif + +// vim:ts=4 diff --git a/src/cpp/ripple/UniqueNodeList.cpp b/src/cpp/ripple/ripple_UniqueNodeList.cpp similarity index 89% rename from src/cpp/ripple/UniqueNodeList.cpp rename to src/cpp/ripple/ripple_UniqueNodeList.cpp index 59f1f4c771..2494fe35b0 100644 --- a/src/cpp/ripple/UniqueNodeList.cpp +++ b/src/cpp/ripple/ripple_UniqueNodeList.cpp @@ -1,24 +1,146 @@ // XXX Dynamically limit fetching by distance. // XXX Want a limit of 2000 validators. -#include "UniqueNodeList.h" +// Guarantees minimum throughput of 1 node per second. +#define NODE_FETCH_JOBS 10 +#define NODE_FETCH_SECONDS 10 +#define NODE_FILE_BYTES_MAX (50<<10) // 50k +#define NODE_FILE_NAME SYSTEM_NAME ".txt" +#define NODE_FILE_PATH "/" NODE_FILE_NAME -#include -#include -#include +// Wait for validation information to be stable before scoring. +// #define SCORE_DELAY_SECONDS 20 +#define SCORE_DELAY_SECONDS 5 -#include -#include -#include -#include -#include -#include -#include +// Don't bother propagating past this number of rounds. +#define SCORE_ROUNDS 10 -#include "Application.h" -#include "HttpsClient.h" -#include "ParseSection.h" +// VFALCO: TODO, move all function definitions inlined into the class. +class UniqueNodeList : public IUniqueNodeList +{ +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 mUNL; + + bool miscLoad(); + bool miscSave(); + + typedef struct { + std::string strDomain; + RippleAddress naPublicKey; + validatorSource vsSource; + boost::posix_time::ptime tpNext; + boost::posix_time::ptime tpScan; + boost::posix_time::ptime tpFetch; + uint256 iSha256; + std::string strComment; + } seedDomain; + + typedef struct { + RippleAddress naPublicKey; + validatorSource vsSource; + boost::posix_time::ptime tpNext; + boost::posix_time::ptime tpScan; + boost::posix_time::ptime tpFetch; + uint256 iSha256; + std::string strComment; + } seedNode; + + // Used to distribute scores. + typedef struct { + int iScore; + int iRoundScore; + int iRoundSeed; + int iSeen; + std::string strValidator; // The public key. + std::vector viReferrals; + } scoreNode; + + std::map sClusterNodes; + + typedef boost::unordered_map strIndex; + typedef std::pair ipPort; + typedef boost::unordered_map, score> epScore; + + void trustedLoad(); + + bool scoreRound(std::vector& vsnNodes); + + 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(); + void fetchProcess(std::string strDomain); + void fetchTimerHandler(const boost::system::error_code& err); + + void getValidatorsUrl(const RippleAddress& naNodePublic, section secSite); + void getIpsUrl(const RippleAddress& naNodePublic, section secSite); + bool responseIps(const std::string& strSite, const RippleAddress& naNodePublic, const boost::system::error_code& err, int iStatus, const std::string& strIpsFile); + 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); + + void processFile(const std::string& strDomain, const RippleAddress& naNodePublic, section secSite); + + bool getSeedDomains(const std::string& strDomain, seedDomain& dstSeedDomain); + void setSeedDomains(const seedDomain& dstSeedDomain, bool bNext); + + bool getSeedNodes(const RippleAddress& naNodePublic, seedNode& dstSeedNode); + void setSeedNodes(const seedNode& snSource, bool bNext); + + 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); + + // 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); +}; + +// VFALCO: TODO Replace macros with language constructs #define VALIDATORS_FETCH_SECONDS 30 #define VALIDATORS_FILE_BYTES_MAX (50 << 10) @@ -38,7 +160,7 @@ SETUP_LOG (UniqueNodeList) -UniqueNodeList::UniqueNodeList(boost::asio::io_service& io_service) : +UniqueNodeList::UniqueNodeList (boost::asio::io_service& io_service) : mdtScoreTimer(io_service), mFetchActive(0), mdtFetchTimer(io_service) @@ -1743,4 +1865,9 @@ bool UniqueNodeList::nodeInCluster(const RippleAddress& naNodePublic, std::strin return true; } +IUniqueNodeList* IUniqueNodeList::New (boost::asio::io_service& io_service) +{ + return new UniqueNodeList (io_service); +} + // vim:ts=4