diff --git a/RippleD.props b/RippleD.props index 4d5516806b..79a7139809 100644 --- a/RippleD.props +++ b/RippleD.props @@ -17,6 +17,7 @@ Level3 $(RepoDir);$(RepoDir)\src\cpp\leveldb;$(RepoDir)\src\cpp\leveldb\include;$(RepoDir)\src\cpp\protobuf\src;$(RepoDir)\src\cpp\protobuf\vsprojects;$(RepoDir)\build\proto;$(RepoDir)\Subtrees\beast;%(AdditionalIncludeDirectories) /bigobj %(AdditionalOptions) + Async Shlwapi.lib;%(AdditionalDependencies) diff --git a/modules/ripple_basics/containers/ripple_RangeSet.cpp b/modules/ripple_basics/containers/ripple_RangeSet.cpp index 5db2feda9f..5801510d87 100644 --- a/modules/ripple_basics/containers/ripple_RangeSet.cpp +++ b/modules/ripple_basics/containers/ripple_RangeSet.cpp @@ -6,100 +6,152 @@ inline uint32 max(uint32 x, uint32 y) { return (x > y) ? x : y; } bool RangeSet::hasValue(uint32 v) const { - return mRanges.find(v) != mRanges.end(); + BOOST_FOREACH(const value_type& it, mRanges) + { + if (contains(it, v)) + return true; + } + return false; } uint32 RangeSet::getFirst() const { - const_iterator it = begin(); - if (it == end()) + const_iterator it = mRanges.begin(); + if (it == mRanges.end()) return RangeSetAbsent; - return lower(it); + return it->first; } uint32 RangeSet::getNext(uint32 v) const { - for (const_iterator it = begin(); it != end(); ++it) + BOOST_FOREACH(const value_type& it, mRanges) { - if (upper(it) > v) - return max(v + 1, lower(it)); + if (it.first > v) + return it.first; + if (contains(it, v + 1)) + return v + 1; } return RangeSetAbsent; } uint32 RangeSet::getLast() const { - const_reverse_iterator it = rbegin(); - if (it == rend()) + const_reverse_iterator it = mRanges.rbegin(); + if (it == mRanges.rend()) return RangeSetAbsent; - return upper(it); + return it->second; } uint32 RangeSet::getPrev(uint32 v) const { - for (const_reverse_iterator it = rbegin(); it != rend(); ++it) + BOOST_REVERSE_FOREACH(const value_type& it, mRanges) { - if (lower(it) < v) - return min(v - 1, upper(it)); + if (it.second < v) + return it.second; + if (contains(it, v + 1)) + return v - 1; } return RangeSetAbsent; } uint32 RangeSet::prevMissing(uint32 v) const { // largest number not in the set that is less than the given number - WriteLog (lsTRACE, RangeSet) << "prevMissing(" << v << ") " << toString(); - for (const_reverse_iterator it = rbegin(); it != rend(); ++it) + BOOST_FOREACH(const value_type& it, mRanges) { - if ((upper(it) + 1) < v) - return upper(it) + 1; - if (lower(it) == 0) - return RangeSetAbsent; - if ((lower(it) - 1) < v) - return lower(it) - 1; + if (contains(it, v)) + return it.first - 1; + if (it.first > v) + return v + 1; } - if (v > 0) - return v - 1; return RangeSetAbsent; } void RangeSet::setValue(uint32 v) { - setRange(v, v); + if (!hasValue(v)) + { + mRanges[v] = v; + simplify(); + } } void RangeSet::setRange(uint32 minV, uint32 maxV) { - mRanges.add(boost::icl::discrete_interval(minV, maxV + 1)); + while (hasValue(minV)) + { + ++minV; + if (minV >= maxV) + return; + } + mRanges[minV] = maxV; + simplify(); } void RangeSet::clearValue(uint32 v) { - clearRange(v, v); -} - -void RangeSet::clearRange(uint32 minV, uint32 maxV) -{ - mRanges.erase(boost::icl::discrete_interval(minV, maxV + 1)); + for (iterator it = mRanges.begin(); it != mRanges.end(); ++it) + { + if (contains(*it, v)) + { + if (it->first == v) + { + if (it->second == v) + mRanges.erase(it); + else + { + mRanges[v + 1] = it->second; + it->second = v - 1; + } + } + else if (it->second == v) + --(it->second); + else + { + uint32 oldEnd = it->second; + it->second = v - 1; + mRanges[v + 1] = oldEnd; + } + return; + } + } } std::string RangeSet::toString() const { std::string ret; - for (const_iterator it = begin(); it != end(); ++it) + BOOST_FOREACH(value_type const& it, mRanges) { if (!ret.empty()) ret += ","; - if (lower(it) == upper(it)) - ret += boost::lexical_cast(lower(it)); + if (it.first == it.second) + ret += boost::lexical_cast((it.first)); else - ret += boost::lexical_cast(lower(it)) + "-" - + boost::lexical_cast(upper(it)); + ret += boost::lexical_cast(it.first) + "-" + + boost::lexical_cast(it.second); } if (ret.empty()) return "empty"; return ret; } +void RangeSet::simplify() +{ + iterator it = mRanges.begin(); + while (1) + { + iterator nit = it; + if (++nit == mRanges.end()) + return; + if (it->second >= (nit->first - 1)) + { // ranges overlap + it->second = nit->second; + mRanges.erase(nit); + } + else + it = nit; + } +} + BOOST_AUTO_TEST_SUITE(RangeSet_suite) BOOST_AUTO_TEST_CASE(RangeSet_test) diff --git a/modules/ripple_basics/containers/ripple_RangeSet.h b/modules/ripple_basics/containers/ripple_RangeSet.h index 9a311853cc..44dfa4045e 100644 --- a/modules/ripple_basics/containers/ripple_RangeSet.h +++ b/modules/ripple_basics/containers/ripple_RangeSet.h @@ -4,15 +4,22 @@ class RangeSet { public: - typedef boost::icl::interval_set iRangeSet; - typedef iRangeSet::iterator iterator; - typedef iRangeSet::const_iterator const_iterator; - typedef iRangeSet::reverse_iterator reverse_iterator; - typedef iRangeSet::const_reverse_iterator const_reverse_iterator; static const uint32 RangeSetAbsent = static_cast(-1); protected: - iRangeSet mRanges; + std::map mRanges; // First is lowest value in range, last is highest value in range + + typedef std::map::const_iterator const_iterator; + typedef std::map::const_reverse_iterator const_reverse_iterator; + typedef std::map::value_type value_type; + typedef std::map::iterator iterator; + + static bool contains(value_type const& it, uint32 v) + { + return (it.first <= v) && (it.second >= v); + } + + void simplify(); public: @@ -29,71 +36,10 @@ public: void setValue(uint32); void setRange(uint32, uint32); void clearValue(uint32); - void clearRange(uint32, uint32); - - - // iterator stuff - iterator begin() { return mRanges.begin(); } - iterator end() { return mRanges.end(); } - const_iterator begin() const { return mRanges.begin(); } - const_iterator end() const { return mRanges.end(); } - reverse_iterator rbegin() { return mRanges.rbegin(); } - reverse_iterator rend() { return mRanges.rend(); } - const_reverse_iterator rbegin() const { return mRanges.rbegin(); } - const_reverse_iterator rend() const { return mRanges.rend(); } - - static uint32 lower(const_iterator& it) { return it->lower(); } - static uint32 upper(const_iterator& it) { return it->upper() - 1; } - static uint32 lower(const_reverse_iterator& it) { return it->lower(); } - static uint32 upper(const_reverse_iterator& it) { return it->upper() - 1; } - std::string toString() const; }; -inline RangeSet::const_iterator range_begin(const RangeSet& r) { return r.begin(); } -inline RangeSet::iterator range_begin(RangeSet& r) { return r.begin(); } -inline RangeSet::const_iterator range_end(const RangeSet& r) { return r.end(); } -inline RangeSet::iterator range_end(RangeSet& r) { return r.end(); } - -namespace boost -{ - template<> struct range_mutable_iterator - { - typedef RangeSet::iterator type; - }; - template<> struct range_const_iterator - { - typedef RangeSet::const_iterator type; - }; -} - -// VFALCO Maybe not the best place for this but it sort of makes sense here - -// VFALCO NOTE these three are unused. -/* -template T range_check(const T& value, const T& minimum, const T& maximum) -{ - if ((value < minimum) || (value > maximum)) - throw std::runtime_error("Value out of range"); - return value; -} - -template T range_check_min(const T& value, const T& minimum) -{ - if (value < minimum) - throw std::runtime_error("Value out of range"); - return value; -} - -template T range_check_max(const T& value, const T& maximum) -{ - if (value > maximum) - throw std::runtime_error("Value out of range"); - return value; -} -*/ - // VFALCO TODO these parameters should not be const references. template T range_check_cast(const U& value, const T& minimum, const T& maximum) { @@ -102,6 +48,7 @@ template T range_check_cast(const U& value, const T& min return static_cast(value); } + #endif // vim:ts=4 diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index eb092665e8..b7552056c0 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -72,7 +72,7 @@ namespace boost { // RangeSet #include -#include // oof this one is ugly +//#include // oof this one is ugly // InstanceCounter //#include diff --git a/modules/ripple_basics/utility/ripple_InstanceCounter.h b/modules/ripple_basics/utility/ripple_InstanceCounter.h index bcdcebddec..f1275320bc 100644 --- a/modules/ripple_basics/utility/ripple_InstanceCounter.h +++ b/modules/ripple_basics/utility/ripple_InstanceCounter.h @@ -1,7 +1,7 @@ #ifndef RIPPLE_INSTANCECOUNTER_H #define RIPPLE_INSTANCECOUNTER_H -// VFALCO TODO Clean up this junk, remove the macros, replace +// VFALCO TODO Clean this up, remove the macros, replace // with a robust leak checker when we have atomics. // @@ -38,7 +38,7 @@ protected: public: typedef std::pair InstanceCount; - InstanceType(const char *n) : mInstances(0), mName(n) + explicit InstanceType (const char *n) : mInstances(0), mName(n) { mNextInstance = sHeadInstance; sHeadInstance = this; @@ -65,7 +65,7 @@ public: { if (sMultiThreaded) { - // VFALCO NOTE Junk that will go away with atomics + // VFALCO NOTE This will go away with atomics mLock.lock(); ++mInstances; mLock.unlock(); diff --git a/modules/ripple_basics/utility/ripple_RandomNumbers.cpp b/modules/ripple_basics/utility/ripple_RandomNumbers.cpp index 1336434ac8..b2673617e8 100644 --- a/modules/ripple_basics/utility/ripple_RandomNumbers.cpp +++ b/modules/ripple_basics/utility/ripple_RandomNumbers.cpp @@ -160,7 +160,7 @@ bool RandomNumbers::platformAddEntropy () void RandomNumbers::platformAddPerformanceMonitorEntropy () { - // VFALCO This is how we simulate local functions + // VFALCO TODO Remove all this fancy stuff struct { int64 operator() () const diff --git a/modules/ripple_basics/utility/ripple_Sustain.h b/modules/ripple_basics/utility/ripple_Sustain.h index bbd612a851..be254a73ec 100644 --- a/modules/ripple_basics/utility/ripple_Sustain.h +++ b/modules/ripple_basics/utility/ripple_Sustain.h @@ -19,7 +19,10 @@ #ifndef RIPPLE_SUSTAIN_H #define RIPPLE_SUSTAIN_H -// VFALCO TODO figure out what the heck this is?? +// "Sustain" is a system for a buddy process that monitors the main process +// and relaunches it on a fault. +// +// VFALCO TODO Rename this and put it in a class. extern bool HaveSustain(); extern std::string StopSustain(); extern std::string DoSustain(); diff --git a/modules/ripple_client/ripple_client.cpp b/modules/ripple_client/ripple_client.cpp index ad6ceb49c4..b565aedea4 100644 --- a/modules/ripple_client/ripple_client.cpp +++ b/modules/ripple_client/ripple_client.cpp @@ -22,4 +22,51 @@ @ingroup ripple_client */ +#include + +#include +#include +#include + #include "ripple_client.h" + +#include "../ripple_basics/ripple_basics.h" + +#include "../ripple_data/ripple_data.h" + +#include "src/cpp/ripple/ripple_InfoSub.h" + +// Order and indentation reflect the hierarchy of dependencies + #include "src/cpp/ripple/ripple_HashedObject.h" + #include "src/cpp/ripple/ripple_SHAMapItem.h" + #include "src/cpp/ripple/ripple_SHAMapNode.h" + #include "src/cpp/ripple/ripple_SHAMapAddNode.h" + #include "src/cpp/ripple/ripple_SHAMapMissingNode.h" + #include "src/cpp/ripple/ripple_SHAMapTreeNode.h" + #include "src/cpp/ripple/ripple_SHAMapSyncFilter.h" + #include "src/cpp/ripple/ripple_SHAMap.h" + #include "src/cpp/ripple/ripple_SerializedTransaction.h" + #include "src/cpp/ripple/ripple_SerializedLedger.h" + #include "src/cpp/ripple/TransactionMeta.h" + #include "src/cpp/ripple/Transaction.h" + #include "src/cpp/ripple/AccountState.h" + #include "src/cpp/ripple/NicknameState.h" + #include "src/cpp/ripple/Ledger.h" + #include "src/cpp/ripple/LedgerEntrySet.h" + #include "src/cpp/ripple/TransactionEngine.h" + #include "src/cpp/ripple/LoadManager.h" + #include "src/cpp/ripple/ripple_Peer.h" + #include "src/cpp/ripple/ripple_PeerSet.h" + #include "src/cpp/ripple/ripple_LedgerAcquire.h" + #include "src/cpp/ripple/ripple_LedgerHistory.h" + #include "src/cpp/ripple/ripple_CanonicalTXSet.h" + #include "src/cpp/ripple/LedgerMaster.h" + #include "src/cpp/ripple/ripple_InfoSub.h" + #include "src/cpp/ripple/SerializedValidation.h" + #include "src/cpp/ripple/LedgerProposal.h" + #include "src/cpp/ripple/ripple_AcceptedLedgerTx.h" + #include "src/cpp/ripple/NetworkOPs.h" + #include "src/cpp/ripple/ripple_IApplication.h" + +#include "src/cpp/ripple/ripple_InfoSub.cpp" +//#include "src/cpp/ripple/NetworkOPs.cpp" diff --git a/modules/ripple_client/ripple_client.h b/modules/ripple_client/ripple_client.h index 4c069d433e..dcc19bfd7d 100644 --- a/modules/ripple_client/ripple_client.h +++ b/modules/ripple_client/ripple_client.h @@ -32,6 +32,4 @@ #ifndef RIPPLE_CLIENT_H #define RIPPLE_CLIENT_H -#include "modules/ripple_basics/ripple_basics.h" - #endif diff --git a/modules/ripple_data/protocol/ripple_LedgerFormat.cpp b/modules/ripple_data/protocol/ripple_LedgerFormat.cpp index e46a08242c..cc799e6ecc 100644 --- a/modules/ripple_data/protocol/ripple_LedgerFormat.cpp +++ b/modules/ripple_data/protocol/ripple_LedgerFormat.cpp @@ -3,8 +3,6 @@ std::map LedgerEntryFormat::byType; std::map LedgerEntryFormat::byName; -// VFALCO TODO surely we can think of a better way than macros? - #define LEF_BASE \ << SOElement(sfLedgerIndex, SOE_OPTIONAL) \ << SOElement(sfLedgerEntryType, SOE_REQUIRED) \ diff --git a/modules/ripple_data/protocol/ripple_RippleAddress.cpp b/modules/ripple_data/protocol/ripple_RippleAddress.cpp index 924be45a4c..a935734c11 100644 --- a/modules/ripple_data/protocol/ripple_RippleAddress.cpp +++ b/modules/ripple_data/protocol/ripple_RippleAddress.cpp @@ -1,13 +1,8 @@ - -// VFALCO TODO remove this when it's safe to do so. -#ifdef __APPLICATION__ -#error Including Application.h is disallowed! -#endif - SETUP_LOG (RippleAddress) -RippleAddress::RippleAddress() : mIsValid(false) +RippleAddress::RippleAddress () + : mIsValid (false) { nVersion = VER_NONE; } diff --git a/modules/ripple_data/protocol/ripple_SerializedObject.cpp b/modules/ripple_data/protocol/ripple_SerializedObject.cpp index f4b7c362c4..b440510e75 100644 --- a/modules/ripple_data/protocol/ripple_SerializedObject.cpp +++ b/modules/ripple_data/protocol/ripple_SerializedObject.cpp @@ -1021,13 +1021,13 @@ UPTR_T STObject::parseJson(const Json::Value& object, SField::ref inNa else if (value.isInt()) { if (value.asInt() < 0 || value.asInt() > 255) - throw std::runtime_error("value out of rand"); + throw std::runtime_error("value out of range"); data.push_back(new STUInt8(field, range_check_cast(value.asInt(), 0, 255))); } else if (value.isUInt()) { if (value.asUInt() > 255) - throw std::runtime_error("value out of rand"); + throw std::runtime_error("value out of range"); data.push_back(new STUInt8(field, range_check_cast(value.asUInt(), 0, 255))); } else diff --git a/modules/ripple_data/protocol/ripple_SerializedTypes.h b/modules/ripple_data/protocol/ripple_SerializedTypes.h index ae5aafec84..a55ecc074d 100644 --- a/modules/ripple_data/protocol/ripple_SerializedTypes.h +++ b/modules/ripple_data/protocol/ripple_SerializedTypes.h @@ -30,7 +30,7 @@ static const uint160 u160_zero(0), u160_one(1); static inline const uint160& get_u160_zero() { return u160_zero; } static inline const uint160& get_u160_one() { return u160_one; } -// VFALCO TODO replace these with language constructs, gah! +// VFALCO TODO replace these with language constructs #define CURRENCY_XRP get_u160_zero() #define CURRENCY_ONE get_u160_one() // Used as a place holder. #define CURRENCY_BAD uint160(0x5852500000000000) // Do not allow XRP as an IOU currency. diff --git a/modules/ripple_data/ripple_data.h b/modules/ripple_data/ripple_data.h index 14b687c4c0..cb899428ee 100644 --- a/modules/ripple_data/ripple_data.h +++ b/modules/ripple_data/ripple_data.h @@ -57,6 +57,15 @@ // VFALCO TODO try to reduce these dependencies #include "../ripple_basics/ripple_basics.h" +//------------------------------------------------------------------------------ + +// VFALCO TODO prepare a unity header for LevelDB +// VFALCO TODO don't expose leveldb throughout the headers +#include "leveldb/cache.h" +#include "leveldb/filter_policy.h" +#include "leveldb/db.h" +#include "leveldb/write_batch.h" + // VFALCO TODO figure out a good place for this file, perhaps give it some // additional hierarchy via directories. #include "ripple.pb.h" diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index 249c84830f..0f72e445a1 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -34,11 +34,14 @@ #include #include #include +#include #include #include #include #include +// VFALCO NOTE Holy smokes...that's a lot of boost!!! + #include #include #include @@ -55,11 +58,14 @@ #include #include #include +#include #include +#include #include #include #include #include +#include #include #include #include @@ -77,14 +83,6 @@ //------------------------------------------------------------------------------ -// VFALCO TODO prepare a unity header for LevelDB -#include "leveldb/cache.h" -#include "leveldb/filter_policy.h" -#include "leveldb/db.h" -#include "leveldb/write_batch.h" - -//------------------------------------------------------------------------------ - // VFALCO TODO fix these warnings! #ifdef _MSC_VER //#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length" @@ -197,7 +195,16 @@ // // ----------- -#include "src/cpp/ripple/Application.h" +#include "src/cpp/ripple/TransactionMaster.h" +#include "src/cpp/ripple/Wallet.h" +#include "src/cpp/ripple/WSDoor.h" +#include "src/cpp/ripple/SNTPClient.h" +#include "src/cpp/ripple/RPCHandler.h" +#include "src/cpp/ripple/TransactionQueue.h" +#include "src/cpp/ripple/OrderBookDB.h" +#include "src/cpp/ripple/ripple_DatabaseCon.h" + +#include "src/cpp/ripple/ripple_IApplication.h" #include "src/cpp/ripple/AutoSocket.h" #include "src/cpp/ripple/CallRPC.h" #include "src/cpp/ripple/ChangeTransactor.h" @@ -210,8 +217,7 @@ #include "src/cpp/ripple/OfferCancelTransactor.h" #include "src/cpp/ripple/OfferCreateTransactor.h" #include "src/cpp/ripple/OrderBook.h" -#include "src/cpp/ripple/OrderBookDB.h" -#include "src/cpp/ripple/PFRequest.h" +#include "src/cpp/ripple/ripple_PathRequest.h" #include "src/cpp/ripple/ParameterTable.h" #include "src/cpp/ripple/ParseSection.h" #include "src/cpp/ripple/Pathfinder.h" @@ -220,24 +226,18 @@ #include "src/cpp/ripple/RPC.h" #include "src/cpp/ripple/RPCDoor.h" #include "src/cpp/ripple/RPCErr.h" -#include "src/cpp/ripple/RPCHandler.h" #include "src/cpp/ripple/RPCServer.h" #include "src/cpp/ripple/RPCSub.h" #include "src/cpp/ripple/RegularKeySetTransactor.h" #include "src/cpp/ripple/RippleCalc.h" #include "src/cpp/ripple/RippleState.h" -#include "src/cpp/ripple/SNTPClient.h" #include "src/cpp/ripple/SerializedValidation.h" -#include "src/cpp/ripple/TransactionMaster.h" -#include "src/cpp/ripple/TransactionQueue.h" #include "src/cpp/ripple/Transactor.h" #include "src/cpp/ripple/AccountSetTransactor.h" #include "src/cpp/ripple/TrustSetTransactor.h" #include "src/cpp/ripple/Version.h" #include "src/cpp/ripple/WSConnection.h" -#include "src/cpp/ripple/WSDoor.h" #include "src/cpp/ripple/WSHandler.h" -#include "src/cpp/ripple/Wallet.h" #include "src/cpp/ripple/WalletAddTransactor.h" #include "../websocketpp/src/logger/logger.hpp" // for ripple_LogWebSockets.cpp @@ -270,7 +270,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/AccountItems.cpp" // no log #include "src/cpp/ripple/AccountSetTransactor.cpp" #include "src/cpp/ripple/AccountState.cpp" // no log -#include "src/cpp/ripple/Application.cpp" #include "src/cpp/ripple/CallRPC.cpp" #include "src/cpp/ripple/ripple_CanonicalTXSet.cpp" #include "src/cpp/ripple/ChangeTransactor.cpp" // no log @@ -300,7 +299,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/Pathfinder.cpp" #include "src/cpp/ripple/PaymentTransactor.cpp" #include "src/cpp/ripple/PeerDoor.cpp" -#include "src/cpp/ripple/PFRequest.cpp" #include "src/cpp/ripple/RegularKeySetTransactor.cpp" #include "src/cpp/ripple/RippleCalc.cpp" #include "src/cpp/ripple/RippleState.cpp" // no log @@ -322,7 +320,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/TransactionQueue.cpp" // no log #include "src/cpp/ripple/Transactor.cpp" #include "src/cpp/ripple/TrustSetTransactor.cpp" -#include "src/cpp/ripple/UpdateTables.cpp" #include "src/cpp/ripple/Wallet.cpp" #include "src/cpp/ripple/WalletAddTransactor.cpp" #include "src/cpp/ripple/WSDoor.cpp" // uses logging in WSConnection.h @@ -339,13 +336,14 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/ripple_AcceptedLedgerTx.cpp" #include "src/cpp/ripple/ripple_AcceptedLedger.cpp" +#include "src/cpp/ripple/ripple_Application.cpp" #include "src/cpp/ripple/ripple_Config.cpp" #include "src/cpp/ripple/ripple_DatabaseCon.cpp" #include "src/cpp/ripple/ripple_Features.cpp" #include "src/cpp/ripple/ripple_FeeVote.cpp" #include "src/cpp/ripple/ripple_HashedObjectStore.cpp" #include "src/cpp/ripple/ripple_HashRouter.cpp" -#include "src/cpp/ripple/ripple_InfoSub.cpp" +//#include "src/cpp/ripple/ripple_InfoSub.cpp" #include "src/cpp/ripple/ripple_Job.cpp" #include "src/cpp/ripple/ripple_JobQueue.cpp" #include "src/cpp/ripple/ripple_LedgerAcquire.cpp" @@ -355,6 +353,7 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/ripple_LoadMonitor.cpp" #include "src/cpp/ripple/ripple_LogWebsockets.cpp" #include "src/cpp/ripple/ripple_LoadFeeTrack.cpp" +#include "src/cpp/ripple/ripple_PathRequest.cpp" #include "src/cpp/ripple/ripple_Peer.cpp" #include "src/cpp/ripple/ripple_Peers.cpp" #include "src/cpp/ripple/ripple_PeerSet.cpp" diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 67d836442c..bd058cc8bd 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -734,7 +734,7 @@ true true - + true true true @@ -990,7 +990,7 @@ true true - + true true @@ -1264,12 +1264,6 @@ true true - - true - true - true - true - true true @@ -1702,7 +1696,7 @@ - + @@ -1745,7 +1739,7 @@ - + diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 9a48bf5bdd..a3f77cb535 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -91,9 +91,6 @@ {7f76ce57-c428-487e-97a0-979c0990a81d} - - {97c96b68-70fd-4679-89fc-c1c8c87c265e} - {a5190241-c5bc-4e23-8ef1-6adf757c75e3} @@ -130,9 +127,12 @@ {2f3572a9-2882-4656-ab93-82b7761c9e3d} - + {b6175f9a-7d46-4b57-877f-f58b0b3bba89} + + {97c96b68-70fd-4679-89fc-c1c8c87c265e} + @@ -469,10 +469,10 @@ 1. Modules\ripple_basics - 1. Modules\ripple_ledger + 2. Empty\ripple_ledger - 2. Empty\ripple_client + 1. Modules\ripple_client 1. Modules\ripple_main\_unfactored\transactions @@ -579,18 +579,12 @@ 1. Modules\ripple_data\protobuf - - 1. Modules\ripple_main\_unfactored\main - 1. Modules\ripple_main\_unfactored\main 1. Modules\ripple_main\_unfactored\main - - 1. Modules\ripple_main\_unfactored\main - 1. Modules\ripple_main\_unfactored\network @@ -678,9 +672,6 @@ 1. Modules\ripple_main\_unfactored\ledger - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -840,6 +831,12 @@ 1. Modules\ripple_main\refactored + + 1. Modules\ripple_main\_unfactored\ledger + + + 1. Modules\ripple_main\_unfactored\main + @@ -1170,10 +1167,10 @@ 1. Modules\ripple_basics - 1. Modules\ripple_ledger + 2. Empty\ripple_ledger - 2. Empty\ripple_client + 1. Modules\ripple_client 1. Modules\ripple_main\_unfactored\transactions @@ -1316,9 +1313,6 @@ 1. Modules\ripple_data\protobuf - - 1. Modules\ripple_main\_unfactored\main - 1. Modules\ripple_main\_unfactored\main @@ -1412,9 +1406,6 @@ 1. Modules\ripple_main\_unfactored\ledger - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -1583,6 +1574,12 @@ 1. Modules\ripple_main\refactored + + 1. Modules\ripple_main\_unfactored\ledger + + + 1. Modules\ripple_main\_unfactored\main + diff --git a/src/cpp/database/SqliteDatabase.cpp b/src/cpp/database/SqliteDatabase.cpp index e8e7f8e973..6bfc28b985 100644 --- a/src/cpp/database/SqliteDatabase.cpp +++ b/src/cpp/database/SqliteDatabase.cpp @@ -117,20 +117,6 @@ bool SqliteDatabase::executeSQL(const char* sql, bool fail_ok) return true; } -// tells you how many rows were changed by an update or insert -int SqliteDatabase::getNumRowsAffected() -{ - // TODO: SqliteDatabase::getNumRowsAffected() - return(0); -} - -// VFALCO TODO This must be fixed!!! return value needs to be int64 -// -int SqliteDatabase::getLastInsertID() -{ - return(sqlite3_last_insert_rowid(mConnection)); -} - // returns false if there are no results bool SqliteDatabase::startIterRows(bool finalize) { diff --git a/src/cpp/database/SqliteDatabase.h b/src/cpp/database/SqliteDatabase.h index f219f17b36..55b9d679d4 100644 --- a/src/cpp/database/SqliteDatabase.h +++ b/src/cpp/database/SqliteDatabase.h @@ -27,7 +27,6 @@ public: // tells you how many rows were changed by an update or insert int getNumRowsAffected(); - int getLastInsertID(); // returns false if there are no results bool startIterRows(bool finalize); diff --git a/src/cpp/database/database.h b/src/cpp/database/database.h index 4bfb1c6684..f8cdbece71 100644 --- a/src/cpp/database/database.h +++ b/src/cpp/database/database.h @@ -43,10 +43,6 @@ public: return executeSQL(strSql.c_str(), fail_okay); } - // tells you how many rows were changed by an update or insert - virtual int getNumRowsAffected()=0; - virtual int getLastInsertID()=0; - // returns false if there are no results virtual bool startIterRows(bool finalize = true)=0; virtual void endIterRows()=0; diff --git a/src/cpp/ripple/AccountState.cpp b/src/cpp/ripple/AccountState.cpp index 3eff3b7652..ed4cc9a776 100644 --- a/src/cpp/ripple/AccountState.cpp +++ b/src/cpp/ripple/AccountState.cpp @@ -26,7 +26,7 @@ std::string AccountState::createGravatarUrl(uint128 uEmailHash) std::string strMD5Lower = strHex(vucMD5); boost::to_lower(strMD5Lower); - return str(boost::format("http://www.gravatar.com/avatar/%s") % strMD5Lower); + return str(boost::format("https://www.gravatar.com/avatar/%s") % strMD5Lower); } void AccountState::addJson(Json::Value& val) diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h deleted file mode 100644 index ba621dafc4..0000000000 --- a/src/cpp/ripple/Application.h +++ /dev/null @@ -1,151 +0,0 @@ -#ifndef __APPLICATION__ -#define __APPLICATION__ - -#include "leveldb/db.h" - -#include - -#include "../database/database.h" - -#include "LedgerMaster.h" -#include "TransactionMaster.h" -#include "Wallet.h" -#include "WSDoor.h" -#include "SNTPClient.h" -#include "RPCHandler.h" -#include "LoadManager.h" -#include "TransactionQueue.h" -#include "OrderBookDB.h" - -#include "ripple_DatabaseCon.h" - -// VFALCO TODO Fix forward declares required for header dependency loops -class IFeatures; -class IFeeVote; -class IHashRouter; -class ILoadFeeTrack; -class IValidations; -class IUniqueNodeList; -class IProofOfWorkFactory; -class IPeers; - -class RPCDoor; -class PeerDoor; - -typedef TaggedCache NodeCache; -typedef TaggedCache SLECache; - -class Application -{ -public: - Application(); - ~Application(); - - Wallet& getWallet() { return mWallet ; } - NetworkOPs& getOPs() { return mNetOps; } - - boost::asio::io_service& getIOService() { return mIOService; } - boost::asio::io_service& getAuxService() { return mAuxService; } - - LedgerMaster& getLedgerMaster() { return mLedgerMaster; } - LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; } - TransactionMaster& getMasterTransaction() { return mMasterTransaction; } - NodeCache& getTempNodeCache() { return mTempNodeCache; } - HashedObjectStore& getHashedObjectStore() { return mHashedObjectStore; } - JobQueue& getJobQueue() { return mJobQueue; } - boost::recursive_mutex& getMasterLock() { return mMasterLock; } - LoadManager& getLoadManager() { return mLoadMgr; } - TXQueue& getTxnQueue() { return mTxnQueue; } - PeerDoor& getPeerDoor() { return *mPeerDoor; } - OrderBookDB& getOrderBookDB() { return mOrderBookDB; } - SLECache& getSLECache() { return mSLECache; } - - IFeatures& getFeatureTable() { return *mFeatures; } - ILoadFeeTrack& getFeeTrack() { return *mFeeTrack; } - IFeeVote& getFeeVote() { return *mFeeVote; } - IHashRouter& getHashRouter() { return *mHashRouter; } - IValidations& getValidations() { return *mValidations; } - IUniqueNodeList& getUNL() { return *mUNL; } - IProofOfWorkFactory& getProofOfWorkFactory() { return *mProofOfWorkFactory; } - IPeers& getPeers () { return *mPeers; } - - // VFALCO TODO Move these to the .cpp - bool running() { return mTxnDB != NULL; } // VFALCO TODO replace with nullptr when beast is available - bool getSystemTimeOffset(int& offset) { return mSNTPClient.getOffset(offset); } - - DatabaseCon* getRpcDB() { return mRpcDB; } - DatabaseCon* getTxnDB() { return mTxnDB; } - DatabaseCon* getLedgerDB() { return mLedgerDB; } - DatabaseCon* getWalletDB() { return mWalletDB; } - DatabaseCon* getNetNodeDB() { return mNetNodeDB; } - DatabaseCon* getPathFindDB() { return mPathFindDB; } - DatabaseCon* getHashNodeDB() { return mHashNodeDB; } - - leveldb::DB* getHashNodeLDB() { return mHashNodeLDB; } - leveldb::DB* getEphemeralLDB() { return mEphemeralLDB; } - - bool isShutdown() { return mShutdown; } - void setup(); - void run(); - void stop(); - void sweep(); - -private: - void updateTables (bool); - void startNewLedger (); - bool loadOldLedger (const std::string&); - - boost::asio::io_service mIOService; - boost::asio::io_service mAuxService; - boost::asio::io_service::work mIOWork; - boost::asio::io_service::work mAuxWork; - - boost::recursive_mutex mMasterLock; - - Wallet mWallet; - LedgerMaster mLedgerMaster; - LedgerAcquireMaster mMasterLedgerAcquire; - TransactionMaster mMasterTransaction; - NetworkOPs mNetOps; - NodeCache mTempNodeCache; - HashedObjectStore mHashedObjectStore; - SLECache mSLECache; - SNTPClient mSNTPClient; - JobQueue mJobQueue; - LoadManager mLoadMgr; - TXQueue mTxnQueue; - OrderBookDB mOrderBookDB; - - // VFALCO Clean stuff - beast::ScopedPointer mFeatures; - beast::ScopedPointer mFeeVote; - beast::ScopedPointer mFeeTrack; - beast::ScopedPointer mHashRouter; - beast::ScopedPointer mValidations; - beast::ScopedPointer mUNL; - beast::ScopedPointer mProofOfWorkFactory; - beast::ScopedPointer mPeers; - // VFALCO End Clean stuff - - DatabaseCon *mRpcDB, *mTxnDB, *mLedgerDB, *mWalletDB, *mNetNodeDB, *mPathFindDB, *mHashNodeDB; - - leveldb::DB *mHashNodeLDB; - leveldb::DB *mEphemeralLDB; - - PeerDoor* mPeerDoor; - RPCDoor* mRPCDoor; - WSDoor* mWSPublicDoor; - WSDoor* mWSPrivateDoor; - - boost::asio::deadline_timer mSweepTimer; - - std::map mPeerMap; - boost::recursive_mutex mPeerMapLock; - - volatile bool mShutdown; -}; - -extern Application* theApp; - -#endif -// vim:ts=4 diff --git a/src/cpp/ripple/CallRPC.cpp b/src/cpp/ripple/CallRPC.cpp index 13c29361e6..958933fbda 100644 --- a/src/cpp/ripple/CallRPC.cpp +++ b/src/cpp/ripple/CallRPC.cpp @@ -20,7 +20,6 @@ #include #include -#include "Application.h" #include "RPC.h" #include "RPCErr.h" diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/LedgerEntrySet.h index a784b34e80..a47f9b7656 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/LedgerEntrySet.h @@ -39,7 +39,14 @@ public: LedgerEntrySetEntry(SLE::ref e, LedgerEntryAction a, int s) : mEntry(e), mAction(a), mSeq(s) { ; } }; +/** An LES is a LedgerEntrySet. + It's a view into a ledger used while a transaction is processing. + The transaction manipulates the LES rather than the ledger + (because it's cheaper, can be checkpointed, and so on). When the + transaction finishes, the LES is committed into the ledger to make + the modifications. The transaction metadata is built from the LES too. +*/ class LedgerEntrySet : private IS_INSTANCE(LedgerEntrySet) { public: diff --git a/src/cpp/ripple/LedgerMaster.cpp b/src/cpp/ripple/LedgerMaster.cpp index 27f6b9299e..a40cbe1ca9 100644 --- a/src/cpp/ripple/LedgerMaster.cpp +++ b/src/cpp/ripple/LedgerMaster.cpp @@ -726,12 +726,13 @@ void LedgerMaster::updatePaths() mPathFindNewRequest = false; } - PFRequest::updateAll(lastLedger, newOnly); + // VFALCO TODO Fix this global variable + PathRequest::updateAll (lastLedger, newOnly); } while(1); } -void LedgerMaster::newPFRequest() +void LedgerMaster::newPathRequest() { boost::recursive_mutex::scoped_lock ml(mLock); mPathFindNewRequest = true; diff --git a/src/cpp/ripple/LedgerMaster.h b/src/cpp/ripple/LedgerMaster.h index b03b360fbd..701a551162 100644 --- a/src/cpp/ripple/LedgerMaster.h +++ b/src/cpp/ripple/LedgerMaster.h @@ -11,7 +11,7 @@ class LedgerMaster { public: - typedef FUNCTION_TYPE callback; + typedef FUNCTION_TYPE callback; public: LedgerMaster () @@ -125,7 +125,7 @@ public: void checkAccept(uint256 const& hash); void checkAccept(uint256 const& hash, uint32 seq); void tryPublish(); - void newPFRequest(); + void newPathRequest(); static bool shouldAcquire(uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger); diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index bdf5cc3cf5..8b415af21a 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1,10 +1,4 @@ -#include "Application.h" -#include "Transaction.h" -#include "HashPrefixes.h" -#include "LedgerConsensus.h" -#include "LedgerTiming.h" - SETUP_LOG (NetworkOPs) // This is the primary interface into the "client" portion of the program. @@ -977,16 +971,21 @@ void NetworkOPs::mapComplete(uint256 const& hash, SHAMap::ref map) mConsensus->mapComplete(hash, map, true); } -void NetworkOPs::endConsensus(bool correctLCL) +void NetworkOPs::endConsensus (bool correctLCL) { uint256 deadLedger = mLedgerMaster->getClosedLedger()->getParentHash(); - std::vector peerList = theApp->getPeers().getPeerVector(); - BOOST_FOREACH(Peer::ref it, peerList) + + std::vector peerList = theApp->getPeers().getPeerVector (); + + BOOST_FOREACH(Peer::ref it, peerList) + { if (it && (it->getClosedLedgerHash() == deadLedger)) { WriteLog (lsTRACE, NetworkOPs) << "Killing obsolete peer status"; it->cycleStatus(); } + } + mConsensus = boost::shared_ptr(); } @@ -996,33 +995,43 @@ void NetworkOPs::consensusViewChange() setMode(omCONNECTED); } -void NetworkOPs::pubServer() +void NetworkOPs::pubServer () { - boost::recursive_mutex::scoped_lock sl(mMonitorLock); + // VFALCO TODO Don't hold the lock across calls to send...make a copy of the + // list into a local array while holding the lock then release the + // lock and call send on everyone. + // + boost::recursive_mutex::scoped_lock sl (mMonitorLock); - if (!mSubServer.empty()) - { - Json::Value jvObj(Json::objectValue); + if (!mSubServer.empty ()) + { + Json::Value jvObj (Json::objectValue); - jvObj["type"] = "serverStatus"; - jvObj["server_status"] = strOperatingMode(); - jvObj["load_base"] = (mLastLoadBase = theApp->getFeeTrack().getLoadBase()); - jvObj["load_factor"] = (mLastLoadFactor = theApp->getFeeTrack().getLoadFactor()); + jvObj ["type"] = "serverStatus"; + jvObj ["server_status"] = strOperatingMode(); + jvObj ["load_base"] = (mLastLoadBase = theApp->getFeeTrack().getLoadBase()); + jvObj ["load_factor"] = (mLastLoadFactor = theApp->getFeeTrack().getLoadFactor()); - NetworkOPs::subMapType::const_iterator it = mSubServer.begin(); - while (it != mSubServer.end()) - { - InfoSub::pointer p = it->second.lock(); - if (p) - { - p->send(jvObj, true); - ++it; - } - else - it = mSubServer.erase(it); - } + NetworkOPs::subMapType::const_iterator it = mSubServer.begin(); - } + while (it != mSubServer.end()) + { + InfoSub::pointer p = it->second.lock(); + + // VFALCO TODO research the possibility of using thread queues and linearizing + // the deletion of subscribers with the sending of JSON data. + if (p) + { + p->send(jvObj, true); + + ++it; + } + else + { + it = mSubServer.erase(it); + } + } + } } void NetworkOPs::setMode(OperatingMode om) @@ -1668,9 +1677,11 @@ bool NetworkOPs::subBook(InfoSub::ref isrListener, const uint160& currencyPays, { BookListeners::pointer listeners = theApp->getOrderBookDB().makeBookListeners(currencyPays, currencyGets, issuerPays, issuerGets); - if (listeners) + + if (listeners) listeners->addSubscriber(isrListener); - return true; + + return true; } bool NetworkOPs::unsubBook(uint64 uSeq, diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index ef8090b72c..5336642590 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -25,7 +25,22 @@ public: omFULL = 4 // we have the ledger and can even validate }; - typedef boost::unordered_map subMapType; +#if 0 + /** Subscription data interface. + */ + class Subscriber + { + public: + typedef boost::weak_ptr WeakPtr; + + /** Called every time new JSON data is available. + */ + virtual void onSubscriberReceiveJSON (Json::Value const& json) { } + }; + typedef boost::unordered_map subMapType; +#endif + + typedef boost::unordered_map subMapType; public: NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster); diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 8db36b2289..a6d7a539b4 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -1,12 +1,4 @@ -#include "Pathfinder.h" - -#include - -#include - -#include "Application.h" - SETUP_LOG (Pathfinder) /* diff --git a/src/cpp/ripple/PeerDoor.cpp b/src/cpp/ripple/PeerDoor.cpp index 352a5c828c..5472c06fc4 100644 --- a/src/cpp/ripple/PeerDoor.cpp +++ b/src/cpp/ripple/PeerDoor.cpp @@ -1,13 +1,4 @@ -#include "PeerDoor.h" - -#include - -#include -#include - -#include "Application.h" - SETUP_LOG (PeerDoor) using namespace std; diff --git a/src/cpp/ripple/RPCDoor.cpp b/src/cpp/ripple/RPCDoor.cpp index b2df802f65..9033681e51 100644 --- a/src/cpp/ripple/RPCDoor.cpp +++ b/src/cpp/ripple/RPCDoor.cpp @@ -1,5 +1,4 @@ #include "RPCDoor.h" -#include "Application.h" #include #include diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index cc4824565e..8307a3d690 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -11,7 +11,6 @@ #include "Pathfinder.h" #include "RPCHandler.h" #include "RPCSub.h" -#include "Application.h" #include "AccountItems.h" #include "Wallet.h" #include "RippleCalc.h" @@ -19,7 +18,6 @@ #include "AccountState.h" #include "NicknameState.h" #include "Offer.h" -#include "PFRequest.h" SETUP_LOG (RPCHandler) @@ -1326,29 +1324,29 @@ Json::Value RPCHandler::doPathFind(Json::Value jvRequest, int& cost, ScopedLock& if (sSubCommand == "create") { - mInfoSub->clearPFRequest(); - PFRequest::pointer request = boost::make_shared(mInfoSub); + mInfoSub->clearPathRequest(); + PathRequest::pointer request = boost::make_shared(mInfoSub); Json::Value result = request->doCreate(mNetOps->getClosedLedger(), jvRequest); if (request->isValid()) { - mInfoSub->setPFRequest(request); - theApp->getLedgerMaster().newPFRequest(); + mInfoSub->setPathRequest(request); + theApp->getLedgerMaster().newPathRequest(); } return result; } if (sSubCommand == "close") { - PFRequest::pointer request = mInfoSub->getPFRequest(); + PathRequest::pointer request = mInfoSub->getPathRequest(); if (!request) return rpcError(rpcNO_PF_REQUEST); - mInfoSub->clearPFRequest(); + mInfoSub->clearPathRequest(); return request->doClose(jvRequest); } if (sSubCommand == "status") { - PFRequest::pointer request = mInfoSub->getPFRequest(); + PathRequest::pointer request = mInfoSub->getPathRequest(); if (!request) return rpcNO_PF_REQUEST; return request->doStatus(jvRequest); diff --git a/src/cpp/ripple/RPCSub.cpp b/src/cpp/ripple/RPCSub.cpp index 6028eda30b..a6c9e20074 100644 --- a/src/cpp/ripple/RPCSub.cpp +++ b/src/cpp/ripple/RPCSub.cpp @@ -1,6 +1,5 @@ #include -#include "Application.h" #include "RPCSub.h" #include "CallRPC.h" diff --git a/src/cpp/ripple/UpdateTables.cpp b/src/cpp/ripple/UpdateTables.cpp deleted file mode 100644 index d9ce1c989b..0000000000 --- a/src/cpp/ripple/UpdateTables.cpp +++ /dev/null @@ -1,136 +0,0 @@ - -//VFALCO TODO clean this up since it is just a file holding a single member function definition - -static std::vector getSchema(DatabaseCon* dbc, const std::string& dbName) -{ - std::vector schema; - - std::string sql = "SELECT sql FROM sqlite_master WHERE tbl_name='"; - sql += dbName; - sql += "';"; - - SQL_FOREACH(dbc->getDB(), sql) - { - dbc->getDB()->getStr("sql", sql); - schema.push_back(sql); - } - - return schema; -} - -static bool schemaHas(DatabaseCon* dbc, const std::string& dbName, int line, const std::string& content) -{ - std::vector schema = getSchema(dbc, dbName); - if (static_cast(schema.size()) <= line) - { - Log(lsFATAL) << "Schema for " << dbName << " has too few lines"; - throw std::runtime_error("bad schema"); - } - return schema[line].find(content) != std::string::npos; -} - -static void addTxnSeqField() -{ - if (schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "TxnSeq")) - return; - Log(lsWARNING) << "Transaction sequence field is missing"; - - Database* db = theApp->getTxnDB()->getDB(); - - std::vector< std::pair > txIDs; - txIDs.reserve(300000); - - Log(lsINFO) << "Parsing transactions"; - int i = 0; - uint256 transID; - SQL_FOREACH(db, "SELECT TransID,TxnMeta FROM Transactions;") - { - Blob rawMeta; - int metaSize = 2048; - rawMeta.resize(metaSize); - metaSize = db->getBinary("TxnMeta", &*rawMeta.begin(), rawMeta.size()); - if (metaSize > static_cast(rawMeta.size())) - { - rawMeta.resize(metaSize); - db->getBinary("TxnMeta", &*rawMeta.begin(), rawMeta.size()); - } - else rawMeta.resize(metaSize); - - std::string tid; - db->getStr("TransID", tid); - transID.SetHex(tid, true); - - if (rawMeta.size() == 0) - { - txIDs.push_back(std::make_pair(transID, -1)); - Log(lsINFO) << "No metadata for " << transID; - } - else - { - TransactionMetaSet m(transID, 0, rawMeta); - txIDs.push_back(std::make_pair(transID, m.getIndex())); - } - - if ((++i % 1000) == 0) - Log(lsINFO) << i << " transactions read"; - } - - Log(lsINFO) << "All " << i << " transactions read"; - - db->executeSQL("BEGIN TRANSACTION;"); - - Log(lsINFO) << "Dropping old index"; - db->executeSQL("DROP INDEX AcctTxIndex;"); - - Log(lsINFO) << "Altering table"; - db->executeSQL("ALTER TABLE AccountTransactions ADD COLUMN TxnSeq INTEGER;"); - - typedef std::pair u256_int_pair_t; - boost::format fmt("UPDATE AccountTransactions SET TxnSeq = %d WHERE TransID = '%s';"); - i = 0; - BOOST_FOREACH(u256_int_pair_t& t, txIDs) - { - db->executeSQL(boost::str(fmt % t.second % t.first.GetHex())); - if ((++i % 1000) == 0) - Log(lsINFO) << i << " transactions updated"; - } - - Log(lsINFO) << "Building new index"; - db->executeSQL("CREATE INDEX AcctTxIndex ON AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);"); - db->executeSQL("END TRANSACTION;"); -} - -void Application::updateTables(bool ldbImport) -{ // perform any needed table updates - assert(schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "TransID")); - assert(!schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "foobar")); - addTxnSeqField(); - - if (schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "PRIMARY")) - { - Log(lsFATAL) << "AccountTransactions database should not have a primary key"; - StopSustain(); - exit(1); - } - - if (theApp->getHashedObjectStore().isLevelDB()) - { - boost::filesystem::path hashPath = theConfig.DATA_DIR / "hashnode.db"; - if (boost::filesystem::exists(hashPath)) - { - if (theConfig.LDB_IMPORT) - { - Log(lsWARNING) << "Importing SQLite -> LevelDB"; - theApp->getHashedObjectStore().import(hashPath.string()); - Log(lsWARNING) << "Remove or remname the hashnode.db file"; - } - else - { - Log(lsWARNING) << "SQLite hashnode database exists. Please either remove or import"; - Log(lsWARNING) << "To import, start with the '--import' option. Otherwise, remove hashnode.db"; - StopSustain(); - exit(1); - } - } - } -} diff --git a/src/cpp/ripple/WSConnection.h b/src/cpp/ripple/WSConnection.h index d19cc95bfd..45251bfc8b 100644 --- a/src/cpp/ripple/WSConnection.h +++ b/src/cpp/ripple/WSConnection.h @@ -11,7 +11,6 @@ #include #include "WSDoor.h" -#include "Application.h" #include "CallRPC.h" #include "LoadManager.h" #include "RPCErr.h" diff --git a/src/cpp/ripple/WSDoor.cpp b/src/cpp/ripple/WSDoor.cpp index fac356c159..85a3f3fde7 100644 --- a/src/cpp/ripple/WSDoor.cpp +++ b/src/cpp/ripple/WSDoor.cpp @@ -4,7 +4,6 @@ //#include "../websocketpp/src/sockets/autotls.hpp" //#include "../websocketpp/src/websocketpp.hpp" -#include "Application.h" #include "WSConnection.h" #include "WSHandler.h" diff --git a/src/cpp/ripple/WSHandler.h b/src/cpp/ripple/WSHandler.h index 4e0de4cfb9..17fdad72bd 100644 --- a/src/cpp/ripple/WSHandler.h +++ b/src/cpp/ripple/WSHandler.h @@ -1,8 +1,6 @@ #ifndef __WSHANDLER__ #define __WSHANDLER__ -#include "Application.h" - extern void initSSLContext(boost::asio::ssl::context& context, std::string key_file, std::string cert_file, std::string chain_file); diff --git a/src/cpp/ripple/main.cpp b/src/cpp/ripple/main.cpp index db76538db8..de7c50bc37 100644 --- a/src/cpp/ripple/main.cpp +++ b/src/cpp/ripple/main.cpp @@ -1,15 +1,4 @@ -#include - -#include -#include -#include -#include - -#include "Application.h" -#include "CallRPC.h" -#include "RPCHandler.h" - namespace po = boost::program_options; // VFALCO TODO make these singletons that initialize statically @@ -21,7 +10,7 @@ using namespace boost::unit_test; void setupServer() { - theApp = new Application(); + theApp = IApplication::New (); theApp->setup(); } @@ -54,7 +43,7 @@ void startServer() bool init_unit_test() { - theApp = new Application(); + theApp = IApplication::New (); return true; } diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/ripple_Application.cpp similarity index 65% rename from src/cpp/ripple/Application.cpp rename to src/cpp/ripple/ripple_Application.cpp index f6cec546cf..86c0af9f9a 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/ripple_Application.cpp @@ -1,27 +1,125 @@ -// VFALCO TODO Replace these with beast "unsigned long long" generators -#define SYSTEM_CURRENCY_GIFT 1000ull -#define SYSTEM_CURRENCY_USERS 100000000ull -#define SYSTEM_CURRENCY_PARTS 1000000ull // 10^SYSTEM_CURRENCY_PRECISION -#define SYSTEM_CURRENCY_START (SYSTEM_CURRENCY_GIFT*SYSTEM_CURRENCY_USERS*SYSTEM_CURRENCY_PARTS) -/* VFALCO NOTE +IApplication* theApp = NULL; - The master lock protects: - - The open ledger - - Server global state - * What the last closed ledger is - * State of the consensus engine - - other things -*/ +class Application; SETUP_LOG (Application) // VFALCO TODO fix/clean this, it might have broken with the Log changes LogPartition AutoSocketPartition("AutoSocket"); -Application* theApp = NULL; + +// VFALCO TODO Move the function definitions into the class declaration +class Application : public IApplication +{ +public: + Application(); + ~Application(); + + Wallet& getWallet() { return mWallet ; } + NetworkOPs& getOPs() { return mNetOps; } + + boost::asio::io_service& getIOService() { return mIOService; } + boost::asio::io_service& getAuxService() { return mAuxService; } + + LedgerMaster& getLedgerMaster() { return mLedgerMaster; } + LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; } + TransactionMaster& getMasterTransaction() { return mMasterTransaction; } + NodeCache& getTempNodeCache() { return mTempNodeCache; } + HashedObjectStore& getHashedObjectStore() { return mHashedObjectStore; } + JobQueue& getJobQueue() { return mJobQueue; } + boost::recursive_mutex& getMasterLock() { return mMasterLock; } + LoadManager& getLoadManager() { return mLoadMgr; } + TXQueue& getTxnQueue() { return mTxnQueue; } + PeerDoor& getPeerDoor() { return *mPeerDoor; } + OrderBookDB& getOrderBookDB() { return mOrderBookDB; } + SLECache& getSLECache() { return mSLECache; } + + IFeatures& getFeatureTable() { return *mFeatures; } + ILoadFeeTrack& getFeeTrack() { return *mFeeTrack; } + IFeeVote& getFeeVote() { return *mFeeVote; } + IHashRouter& getHashRouter() { return *mHashRouter; } + IValidations& getValidations() { return *mValidations; } + IUniqueNodeList& getUNL() { return *mUNL; } + IProofOfWorkFactory& getProofOfWorkFactory() { return *mProofOfWorkFactory; } + IPeers& getPeers () { return *mPeers; } + + // VFALCO TODO Move these to the .cpp + bool running() { return mTxnDB != NULL; } // VFALCO TODO replace with nullptr when beast is available + bool getSystemTimeOffset(int& offset) { return mSNTPClient.getOffset(offset); } + + DatabaseCon* getRpcDB() { return mRpcDB; } + DatabaseCon* getTxnDB() { return mTxnDB; } + DatabaseCon* getLedgerDB() { return mLedgerDB; } + DatabaseCon* getWalletDB() { return mWalletDB; } + DatabaseCon* getNetNodeDB() { return mNetNodeDB; } + DatabaseCon* getPathFindDB() { return mPathFindDB; } + DatabaseCon* getHashNodeDB() { return mHashNodeDB; } + + leveldb::DB* getHashNodeLDB() { return mHashNodeLDB; } + leveldb::DB* getEphemeralLDB() { return mEphemeralLDB; } + + bool isShutdown() { return mShutdown; } + void setup(); + void run(); + void stop(); + void sweep(); + +private: + void updateTables (bool); + void startNewLedger (); + bool loadOldLedger (const std::string&); + + boost::asio::io_service mIOService; + boost::asio::io_service mAuxService; + boost::asio::io_service::work mIOWork; + boost::asio::io_service::work mAuxWork; + + boost::recursive_mutex mMasterLock; + + Wallet mWallet; + LedgerMaster mLedgerMaster; + LedgerAcquireMaster mMasterLedgerAcquire; + TransactionMaster mMasterTransaction; + NetworkOPs mNetOps; + NodeCache mTempNodeCache; + HashedObjectStore mHashedObjectStore; + SLECache mSLECache; + SNTPClient mSNTPClient; + JobQueue mJobQueue; + LoadManager mLoadMgr; + TXQueue mTxnQueue; + OrderBookDB mOrderBookDB; + + // VFALCO Clean stuff + beast::ScopedPointer mFeatures; + beast::ScopedPointer mFeeVote; + beast::ScopedPointer mFeeTrack; + beast::ScopedPointer mHashRouter; + beast::ScopedPointer mValidations; + beast::ScopedPointer mUNL; + beast::ScopedPointer mProofOfWorkFactory; + beast::ScopedPointer mPeers; + // VFALCO End Clean stuff + + DatabaseCon *mRpcDB, *mTxnDB, *mLedgerDB, *mWalletDB, *mNetNodeDB, *mPathFindDB, *mHashNodeDB; + + leveldb::DB *mHashNodeLDB; + leveldb::DB *mEphemeralLDB; + + PeerDoor* mPeerDoor; + RPCDoor* mRPCDoor; + WSDoor* mWSPublicDoor; + WSDoor* mWSPrivateDoor; + + boost::asio::deadline_timer mSweepTimer; + + std::map mPeerMap; + boost::recursive_mutex mPeerMapLock; + + volatile bool mShutdown; +}; Application::Application () : mIOService ((theConfig.NODE_SIZE >= 2) ? 2 : 1) @@ -568,4 +666,143 @@ bool serverOkay(std::string& reason) return true; } -// vim:ts=4 +//VFALCO TODO clean this up since it is just a file holding a single member function definition + +static std::vector getSchema(DatabaseCon* dbc, const std::string& dbName) +{ + std::vector schema; + + std::string sql = "SELECT sql FROM sqlite_master WHERE tbl_name='"; + sql += dbName; + sql += "';"; + + SQL_FOREACH(dbc->getDB(), sql) + { + dbc->getDB()->getStr("sql", sql); + schema.push_back(sql); + } + + return schema; +} + +static bool schemaHas(DatabaseCon* dbc, const std::string& dbName, int line, const std::string& content) +{ + std::vector schema = getSchema(dbc, dbName); + if (static_cast(schema.size()) <= line) + { + Log(lsFATAL) << "Schema for " << dbName << " has too few lines"; + throw std::runtime_error("bad schema"); + } + return schema[line].find(content) != std::string::npos; +} + +static void addTxnSeqField() +{ + if (schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "TxnSeq")) + return; + Log(lsWARNING) << "Transaction sequence field is missing"; + + Database* db = theApp->getTxnDB()->getDB(); + + std::vector< std::pair > txIDs; + txIDs.reserve(300000); + + Log(lsINFO) << "Parsing transactions"; + int i = 0; + uint256 transID; + SQL_FOREACH(db, "SELECT TransID,TxnMeta FROM Transactions;") + { + Blob rawMeta; + int metaSize = 2048; + rawMeta.resize(metaSize); + metaSize = db->getBinary("TxnMeta", &*rawMeta.begin(), rawMeta.size()); + if (metaSize > static_cast(rawMeta.size())) + { + rawMeta.resize(metaSize); + db->getBinary("TxnMeta", &*rawMeta.begin(), rawMeta.size()); + } + else rawMeta.resize(metaSize); + + std::string tid; + db->getStr("TransID", tid); + transID.SetHex(tid, true); + + if (rawMeta.size() == 0) + { + txIDs.push_back(std::make_pair(transID, -1)); + Log(lsINFO) << "No metadata for " << transID; + } + else + { + TransactionMetaSet m(transID, 0, rawMeta); + txIDs.push_back(std::make_pair(transID, m.getIndex())); + } + + if ((++i % 1000) == 0) + Log(lsINFO) << i << " transactions read"; + } + + Log(lsINFO) << "All " << i << " transactions read"; + + db->executeSQL("BEGIN TRANSACTION;"); + + Log(lsINFO) << "Dropping old index"; + db->executeSQL("DROP INDEX AcctTxIndex;"); + + Log(lsINFO) << "Altering table"; + db->executeSQL("ALTER TABLE AccountTransactions ADD COLUMN TxnSeq INTEGER;"); + + typedef std::pair u256_int_pair_t; + boost::format fmt("UPDATE AccountTransactions SET TxnSeq = %d WHERE TransID = '%s';"); + i = 0; + BOOST_FOREACH(u256_int_pair_t& t, txIDs) + { + db->executeSQL(boost::str(fmt % t.second % t.first.GetHex())); + if ((++i % 1000) == 0) + Log(lsINFO) << i << " transactions updated"; + } + + Log(lsINFO) << "Building new index"; + db->executeSQL("CREATE INDEX AcctTxIndex ON AccountTransactions(Account, LedgerSeq, TxnSeq, TransID);"); + db->executeSQL("END TRANSACTION;"); +} + +void Application::updateTables(bool ldbImport) +{ // perform any needed table updates + assert(schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "TransID")); + assert(!schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "foobar")); + addTxnSeqField(); + + if (schemaHas(theApp->getTxnDB(), "AccountTransactions", 0, "PRIMARY")) + { + Log(lsFATAL) << "AccountTransactions database should not have a primary key"; + StopSustain(); + exit(1); + } + + if (theApp->getHashedObjectStore().isLevelDB()) + { + boost::filesystem::path hashPath = theConfig.DATA_DIR / "hashnode.db"; + if (boost::filesystem::exists(hashPath)) + { + if (theConfig.LDB_IMPORT) + { + Log(lsWARNING) << "Importing SQLite -> LevelDB"; + theApp->getHashedObjectStore().import(hashPath.string()); + Log(lsWARNING) << "Remove or remname the hashnode.db file"; + } + else + { + Log(lsWARNING) << "SQLite hashnode database exists. Please either remove or import"; + Log(lsWARNING) << "To import, start with the '--import' option. Otherwise, remove hashnode.db"; + StopSustain(); + exit(1); + } + } + } +} + +IApplication* IApplication::New () +{ + return new Application; +} diff --git a/src/cpp/ripple/ripple_HashedObjectStore.h b/src/cpp/ripple/ripple_HashedObjectStore.h index 06244f2220..279e121547 100644 --- a/src/cpp/ripple/ripple_HashedObjectStore.h +++ b/src/cpp/ripple/ripple_HashedObjectStore.h @@ -3,6 +3,7 @@ /** Persistency layer for hashed objects. */ +// VFALCO TODO Move all definitions to the .cpp class HashedObjectStore { public: diff --git a/src/cpp/ripple/ripple_IApplication.h b/src/cpp/ripple/ripple_IApplication.h new file mode 100644 index 0000000000..f745244cbd --- /dev/null +++ b/src/cpp/ripple/ripple_IApplication.h @@ -0,0 +1,111 @@ +#ifndef RIPPLE_IAPPLICATION_H +#define RIPPLE_IAPPLICATION_H + +// VFALCO TODO Replace these with beast "unsigned long long" generators +// VFALCO NOTE Apparently these are used elsewhere. Make them constants in the config +// or in the IApplication +// +#define SYSTEM_CURRENCY_GIFT 1000ull +#define SYSTEM_CURRENCY_USERS 100000000ull +#define SYSTEM_CURRENCY_PARTS 1000000ull // 10^SYSTEM_CURRENCY_PRECISION +#define SYSTEM_CURRENCY_START (SYSTEM_CURRENCY_GIFT*SYSTEM_CURRENCY_USERS*SYSTEM_CURRENCY_PARTS) + +// VFALCO TODO Fix forward declares required for header dependency loops +class IFeatures; +class IFeeVote; +class IHashRouter; +class ILoadFeeTrack; +class IPeers; +class IProofOfWorkFactory; +class IUniqueNodeList; +class IValidations; + +class HashedObjectStore; +class JobQueue; +class LedgerAcquireMaster; +class LedgerMaster; +class LoadManager; +class NetworkOPs; +class OrderBookDB; +class PeerDoor; +class SerializedLedgerEntry; +class TransactionMaster; +class TXQueue; +class Wallet; + +class DatabaseCon; + +typedef TaggedCache NodeCache; +typedef TaggedCache SLECache; + +class IApplication +{ +public: + static IApplication* New (); + + virtual ~IApplication () { } + + /* VFALCO NOTE + + The master lock protects: + + - The open ledger + - Server global state + * What the last closed ledger is + * State of the consensus engine + + other things + */ + virtual boost::recursive_mutex& getMasterLock () = 0; + + virtual boost::asio::io_service& getIOService () = 0; + virtual boost::asio::io_service& getAuxService () = 0; + + virtual NodeCache& getTempNodeCache () = 0; + virtual SLECache& getSLECache () = 0; + + virtual IFeatures& getFeatureTable () = 0; + virtual IFeeVote& getFeeVote () = 0; + virtual IHashRouter& getHashRouter () = 0; + virtual ILoadFeeTrack& getFeeTrack () = 0; + virtual IPeers& getPeers () = 0; + virtual IProofOfWorkFactory& getProofOfWorkFactory () = 0; + virtual IUniqueNodeList& getUNL () = 0; + virtual IValidations& getValidations () = 0; + + virtual HashedObjectStore& getHashedObjectStore () = 0; + virtual JobQueue& getJobQueue () = 0; + virtual LedgerAcquireMaster& getMasterLedgerAcquire () = 0; + virtual LedgerMaster& getLedgerMaster () = 0; + virtual LoadManager& getLoadManager () = 0; + virtual NetworkOPs& getOPs () = 0; + virtual OrderBookDB& getOrderBookDB () = 0; + virtual PeerDoor& getPeerDoor () = 0; + virtual TransactionMaster& getMasterTransaction () = 0; + virtual TXQueue& getTxnQueue () = 0; + virtual Wallet& getWallet () = 0; + + virtual DatabaseCon* getRpcDB () = 0; + virtual DatabaseCon* getTxnDB () = 0; + virtual DatabaseCon* getLedgerDB () = 0; + virtual DatabaseCon* getWalletDB () = 0; + virtual DatabaseCon* getNetNodeDB () = 0; + virtual DatabaseCon* getPathFindDB () = 0; + virtual DatabaseCon* getHashNodeDB () = 0; + + virtual leveldb::DB* getHashNodeLDB () = 0; + virtual leveldb::DB* getEphemeralLDB () = 0; + + virtual bool getSystemTimeOffset (int& offset) = 0; + virtual bool isShutdown () = 0; + virtual bool running () = 0; + virtual void setup () = 0; + virtual void run () = 0; + virtual void stop () = 0; + virtual void sweep () = 0; +}; + +extern IApplication* theApp; + +#endif +// vim:ts=4 diff --git a/src/cpp/ripple/ripple_InfoSub.cpp b/src/cpp/ripple/ripple_InfoSub.cpp index b108c4f6a1..99034579b3 100644 --- a/src/cpp/ripple/ripple_InfoSub.cpp +++ b/src/cpp/ripple/ripple_InfoSub.cpp @@ -10,7 +10,7 @@ // code assumes this node is synched (and will continue to do so until // there's a functional network. -DECLARE_INSTANCE(InfoSub); +DECLARE_INSTANCE (InfoSub); // VFALCO TODO Figure out how to clean up these globals uint64 InfoSub::sSeq = 0; @@ -54,17 +54,17 @@ void InfoSub::insertSubAccountInfo (RippleAddress addr, uint32 uLedgerIndex) mSubAccountInfo.insert(addr); } -void InfoSub::clearPFRequest() +void InfoSub::clearPathRequest() { - mPFRequest.reset(); + mPathRequest.reset(); } -void InfoSub::setPFRequest(const boost::shared_ptr& req) +void InfoSub::setPathRequest(const boost::shared_ptr& req) { - mPFRequest = req; + mPathRequest = req; } -const boost::shared_ptr& InfoSub::getPFRequest() +const boost::shared_ptr& InfoSub::getPathRequest() { - return mPFRequest; + return mPathRequest; } diff --git a/src/cpp/ripple/ripple_InfoSub.h b/src/cpp/ripple/ripple_InfoSub.h index c2914fbd1d..9748337242 100644 --- a/src/cpp/ripple/ripple_InfoSub.h +++ b/src/cpp/ripple/ripple_InfoSub.h @@ -4,11 +4,10 @@ // Operations that clients may wish to perform against the network // Master operational handler, server sequencer, network tracker -class PFRequest; +class PathRequest; DEFINE_INSTANCE(InfoSub); -// VFALCO TODO Move InfoSub to a separate file class InfoSub : public IS_INSTANCE(InfoSub) { public: @@ -35,23 +34,24 @@ public: void insertSubAccountInfo (RippleAddress addr, uint32 uLedgerIndex); - void clearPFRequest(); + void clearPathRequest(); - void setPFRequest (const boost::shared_ptr& req); + void setPathRequest (const boost::shared_ptr& req); - boost::shared_ptr const& getPFRequest (); + boost::shared_ptr const& getPathRequest (); protected: // VFALCO TODO make accessor for this member boost::mutex mLockInfo; private: + // VFALCO TODO Move these globals to class instance static uint64 sSeq; static boost::mutex sSeqLock; - boost::unordered_set mSubAccountInfo; - boost::unordered_set mSubAccountTransaction; - boost::shared_ptr mPFRequest; + boost::unordered_set mSubAccountInfo; + boost::unordered_set mSubAccountTransaction; + boost::shared_ptr mPathRequest; uint64 mSeq; }; diff --git a/src/cpp/ripple/ripple_JobQueue.cpp b/src/cpp/ripple/ripple_JobQueue.cpp index 30073d61ae..9eb52ab3fa 100644 --- a/src/cpp/ripple/ripple_JobQueue.cpp +++ b/src/cpp/ripple/ripple_JobQueue.cpp @@ -215,10 +215,8 @@ void JobQueue::IOThread(boost::mutex::scoped_lock& sl) // do jobs until asked to stop void JobQueue::threadEntry() { - - // VFALCO TODO Replace this mutex nonsense - // boost::mutex::scoped_lock sl(mJobLock); + while (1) { setCallingThreadName("waiting"); diff --git a/src/cpp/ripple/ripple_LoadFeeTrack.cpp b/src/cpp/ripple/ripple_LoadFeeTrack.cpp index 374ce5214e..fecf9f409b 100644 --- a/src/cpp/ripple/ripple_LoadFeeTrack.cpp +++ b/src/cpp/ripple/ripple_LoadFeeTrack.cpp @@ -1,7 +1,3 @@ -//#include -//#include -//#include -//#include "Application.h" class LoadFeeTrack : public ILoadFeeTrack { diff --git a/src/cpp/ripple/PFRequest.cpp b/src/cpp/ripple/ripple_PathRequest.cpp similarity index 83% rename from src/cpp/ripple/PFRequest.cpp rename to src/cpp/ripple/ripple_PathRequest.cpp index daf5df0683..6332d727df 100644 --- a/src/cpp/ripple/PFRequest.cpp +++ b/src/cpp/ripple/ripple_PathRequest.cpp @@ -1,35 +1,30 @@ -#include "PFRequest.h" +SETUP_LOG (PathRequest) -#include "RPCErr.h" -#include "Ledger.h" -#include "Application.h" -#include "Pathfinder.h" -#include "RippleCalc.h" +// VFALCO TODO Move these globals into a PathRequests collection inteface +boost::recursive_mutex PathRequest::sLock; +std::set PathRequest::sRequests; -SETUP_LOG (PFRequest) - -boost::recursive_mutex PFRequest::sLock; -std::set PFRequest::sRequests; - -PFRequest::PFRequest(const boost::shared_ptr& subscriber) : - wpSubscriber(subscriber), jvStatus(Json::objectValue), bValid(false), bNew(true) +PathRequest::PathRequest (const boost::shared_ptr& subscriber) + : wpSubscriber (subscriber) + , jvStatus (Json::objectValue) + , bValid (false) + , bNew (true) { - ; } -bool PFRequest::isValid() +bool PathRequest::isValid() { boost::recursive_mutex::scoped_lock sl(mLock); return bValid; } -bool PFRequest::isNew() +bool PathRequest::isNew() { boost::recursive_mutex::scoped_lock sl(mLock); return bNew; } -bool PFRequest::isValid(Ledger::ref lrLedger) +bool PathRequest::isValid(Ledger::ref lrLedger) { boost::recursive_mutex::scoped_lock sl(mLock); bValid = raSrcAccount.isSet() && raDstAccount.isSet() && saDstAmount.isPositive(); @@ -74,7 +69,7 @@ bool PFRequest::isValid(Ledger::ref lrLedger) return bValid; } -Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value) +Json::Value PathRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value) { assert(lrLedger->isClosed()); @@ -98,9 +93,9 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value) if (mValid) { - WriteLog (lsINFO, PFRequest) << "Request created: " << raSrcAccount.humanAccountID() << + WriteLog (lsINFO, PathRequest) << "Request created: " << raSrcAccount.humanAccountID() << " -> " << raDstAccount.humanAccountID(); - WriteLog (lsINFO, PFRequest) << "Deliver: " << saDstAmount.getFullText(); + WriteLog (lsINFO, PathRequest) << "Deliver: " << saDstAmount.getFullText(); boost::recursive_mutex::scoped_lock sl(sLock); sRequests.insert(shared_from_this()); @@ -109,7 +104,7 @@ Json::Value PFRequest::doCreate(Ledger::ref lrLedger, const Json::Value& value) return jvStatus; } -int PFRequest::parseJson(const Json::Value& jvParams, bool complete) +int PathRequest::parseJson(const Json::Value& jvParams, bool complete) { int ret = PFR_PJ_NOCHANGE; @@ -194,19 +189,19 @@ int PFRequest::parseJson(const Json::Value& jvParams, bool complete) return ret; } -Json::Value PFRequest::doClose(const Json::Value&) +Json::Value PathRequest::doClose(const Json::Value&) { boost::recursive_mutex::scoped_lock sl(mLock); return jvStatus; } -Json::Value PFRequest::doStatus(const Json::Value&) +Json::Value PathRequest::doStatus(const Json::Value&) { boost::recursive_mutex::scoped_lock sl(mLock); return jvStatus; } -bool PFRequest::doUpdate(RLCache::ref cache, bool fast) +bool PathRequest::doUpdate(RLCache::ref cache, bool fast) { boost::recursive_mutex::scoped_lock sl(mLock); jvStatus = Json::objectValue; @@ -246,13 +241,13 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) { { STAmount test(currIssuer.first, currIssuer.second, 1); - WriteLog (lsDEBUG, PFRequest) << "Trying to find paths: " << test.getFullText(); + WriteLog (lsDEBUG, PathRequest) << "Trying to find paths: " << test.getFullText(); } bool valid; STPathSet spsPaths; Pathfinder pf(cache, raSrcAccount, raDstAccount, currIssuer.first, currIssuer.second, saDstAmount, valid); - CondLog (!valid, lsINFO, PFRequest) << "PF request not valid"; + CondLog (!valid, lsINFO, PathRequest) << "PF request not valid"; if (valid && pf.findPaths(theConfig.PATH_SEARCH_SIZE - (fast ? 0 : 1), 3, spsPaths)) { LedgerEntrySet lesSandbox(cache->getLedger(), tapNONE); @@ -263,7 +258,7 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) currIssuer.second.isNonZero() ? currIssuer.second : (currIssuer.first.isZero() ? ACCOUNT_XRP : raSrcAccount.getAccountID()), 1); saMaxAmount.negate(); - WriteLog (lsDEBUG, PFRequest) << "Paths found, calling rippleCalc"; + WriteLog (lsDEBUG, PathRequest) << "Paths found, calling rippleCalc"; TER terResult = RippleCalc::rippleCalc(lesSandbox, saMaxAmountAct, saDstAmountAct, vpsExpanded, saMaxAmount, saDstAmount, raDstAccount.getAccountID(), raSrcAccount.getAccountID(), spsPaths, false, false, false, true); @@ -276,19 +271,19 @@ bool PFRequest::doUpdate(RLCache::ref cache, bool fast) } else { - WriteLog (lsINFO, PFRequest) << "rippleCalc returns " << transHuman(terResult); + WriteLog (lsINFO, PathRequest) << "rippleCalc returns " << transHuman(terResult); } } else { - WriteLog (lsINFO, PFRequest) << "No paths found"; + WriteLog (lsINFO, PathRequest) << "No paths found"; } } jvStatus["alternatives"] = jvArray; return true; } -void PFRequest::updateAll(Ledger::ref ledger, bool newOnly) +void PathRequest::updateAll(Ledger::ref ledger, bool newOnly) { std::set requests; @@ -305,7 +300,7 @@ void PFRequest::updateAll(Ledger::ref ledger, bool newOnly) BOOST_FOREACH(wref wRequest, requests) { bool remove = true; - PFRequest::pointer pRequest = wRequest.lock(); + PathRequest::pointer pRequest = wRequest.lock(); if (pRequest && (!newOnly || pRequest->isNew())) { InfoSub::pointer ipSub = pRequest->wpSubscriber.lock(); diff --git a/src/cpp/ripple/PFRequest.h b/src/cpp/ripple/ripple_PathRequest.h similarity index 85% rename from src/cpp/ripple/PFRequest.h rename to src/cpp/ripple/ripple_PathRequest.h index c736a4b616..e0d07c1f2a 100644 --- a/src/cpp/ripple/PFRequest.h +++ b/src/cpp/ripple/ripple_PathRequest.h @@ -14,7 +14,6 @@ // A pathfinding request submitted by a client // The request issuer must maintain a strong pointer -class Ledger; class InfoSub; class STAmount; class RLCache; @@ -24,17 +23,18 @@ class RLCache; #define PFR_PJ_NOCHANGE 0 #define PFR_PJ_CHANGE 1 -class PFRequest : public boost::enable_shared_from_this +class PathRequest : public boost::enable_shared_from_this { public: - typedef boost::weak_ptr wptr; - typedef boost::shared_ptr pointer; + typedef boost::weak_ptr wptr; + typedef boost::shared_ptr pointer; typedef const pointer& ref; typedef const wptr& wref; typedef std::pair currIssuer_t; public: - PFRequest(const boost::shared_ptr& subscriber); + // VFALCO TODO Break the cyclic dependency on InfoSub + explicit PathRequest (boost::shared_ptr const& subscriber); bool isValid(const boost::shared_ptr&); bool isValid(); diff --git a/src/cpp/ripple/ripple_Validations.cpp b/src/cpp/ripple/ripple_Validations.cpp index 1784847e3e..4b2924d788 100644 --- a/src/cpp/ripple/ripple_Validations.cpp +++ b/src/cpp/ripple/ripple_Validations.cpp @@ -1,9 +1,4 @@ -#include - -#include "Application.h" -#include "LedgerTiming.h" - class Validations; SETUP_LOG (Validations) diff --git a/src/cpp/websocket_core.cpp b/src/cpp/websocket_core.cpp index 25f76e584e..3691495424 100644 --- a/src/cpp/websocket_core.cpp +++ b/src/cpp/websocket_core.cpp @@ -3,8 +3,8 @@ // // VFALCO TODO Fix this right. It's not really needed -// to include this file, its a hack to keep -// __STDC_LIMIT_MACROS from generating redefinition warnings +// to include this file, its a hack to keep +// __STDC_LIMIT_MACROS from generating redefinition warnings #include "websocketpp/src/rng/boost_rng.hpp" // Must come first to prevent compile errors