diff --git a/modules/ripple_basics/ripple_basics.cpp b/modules/ripple_basics/ripple_basics.cpp index c21162287a..538a33c853 100644 --- a/modules/ripple_basics/ripple_basics.cpp +++ b/modules/ripple_basics/ripple_basics.cpp @@ -84,6 +84,7 @@ #endif #include "utility/ripple_RandomNumbers.cpp" // has Win32/Posix dependencies +#include "types/ripple_UInt256.cpp" #ifdef _MSC_VER //#pragma warning (pop) diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index 68801f888d..5aac2185e2 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -148,6 +148,6 @@ namespace boost { #include "types/ripple_UInt256.h" #include "utility/ripple_HashUtilities.h" // requires UInt256 -#include "types/ripple_HashTables.h" +#include "types/ripple_HashMaps.h" #endif diff --git a/modules/ripple_basics/types/ripple_HashTables.h b/modules/ripple_basics/types/ripple_HashMaps.h similarity index 97% rename from modules/ripple_basics/types/ripple_HashTables.h rename to modules/ripple_basics/types/ripple_HashMaps.h index 10f524921d..1fad631367 100644 --- a/modules/ripple_basics/types/ripple_HashTables.h +++ b/modules/ripple_basics/types/ripple_HashMaps.h @@ -84,7 +84,7 @@ private: @note This routine will be called concurrently. */ template - NonceHolder const& getNonceHolder () + NonceHolder const& getNonceHolder () const { static NonceHolder nonceHolder; diff --git a/modules/ripple_basics/types/ripple_UInt256.cpp b/modules/ripple_basics/types/ripple_UInt256.cpp new file mode 100644 index 0000000000..32350681fc --- /dev/null +++ b/modules/ripple_basics/types/ripple_UInt256.cpp @@ -0,0 +1,15 @@ + +std::size_t hash_value(const uint256& u) +{ + std::size_t seed = HashMaps::getInstance ().getNonce (); + + return u.hash_combine (seed); +} + +std::size_t hash_value(const uint160& u) +{ + std::size_t seed = HashMaps::getInstance ().getNonce (); + + return u.hash_combine(seed); +} + diff --git a/modules/ripple_basics/types/ripple_UInt256.h b/modules/ripple_basics/types/ripple_UInt256.h index 16c837cf50..0e4b934510 100644 --- a/modules/ripple_basics/types/ripple_UInt256.h +++ b/modules/ripple_basics/types/ripple_UInt256.h @@ -735,6 +735,10 @@ inline const std::string strHex(const uint160& ui) return strHex(ui.begin(), ui.size()); } +extern std::size_t hash_value (const uint160&); + +extern std::size_t hash_value (const uint256&); + #endif // vim:ts=4 diff --git a/modules/ripple_basics/utility/ripple_RandomNumbers.h b/modules/ripple_basics/utility/ripple_RandomNumbers.h index 17afabd3ae..6f479a91b6 100644 --- a/modules/ripple_basics/utility/ripple_RandomNumbers.h +++ b/modules/ripple_basics/utility/ripple_RandomNumbers.h @@ -24,6 +24,8 @@ class RandomNumbers { public: + /** Retrieve the instance of the generator. + */ static RandomNumbers& getInstance (); /** Initialize the generator. @@ -40,8 +42,9 @@ public: The generated data is suitable for cryptography. - @invariant The destination buffer must be large enough or undefined behavior - results. + @invariant The destination buffer must be large enough or + undefined behavior results. + @param destinationBuffer The place to store the bytes. @param numberOfBytes The number of bytes to generate. */ @@ -51,8 +54,14 @@ public: The generated data is suitable for cryptography. - Fills the memory for the object with random numbers. This is a type-safe - alternative to the function above. + Fills the memory for the object with random numbers. + This is a type-safe alternative to the function above. + + @param object A pointer to the object to fill. + + @tparam T The type of `object` + + @note Undefined behavior results if `T` is not a POD type. */ template void fill (T* object) diff --git a/modules/ripple_data/crypto/ripple_Base58Data.cpp b/modules/ripple_data/crypto/ripple_Base58Data.cpp index 35ac093cf9..d8c0a9d854 100644 --- a/modules/ripple_data/crypto/ripple_Base58Data.cpp +++ b/modules/ripple_data/crypto/ripple_Base58Data.cpp @@ -107,4 +107,14 @@ bool CBase58Data::operator>=(const CBase58Data& b58) const { return CompareTo(b5 bool CBase58Data::operator< (const CBase58Data& b58) const { return CompareTo(b58) < 0; } bool CBase58Data::operator> (const CBase58Data& b58) const { return CompareTo(b58) > 0; } +std::size_t hash_value(const CBase58Data& b58) +{ + std::size_t seed = HashMaps::getInstance ().getNonce () + + (b58.nVersion * 0x9e3779b9); + + boost::hash_combine (seed, b58.vchData); + + return seed; +} + // vim:ts=4 diff --git a/modules/ripple_data/crypto/ripple_Base58Data.h b/modules/ripple_data/crypto/ripple_Base58Data.h index a5509e1ecb..58ed874e07 100644 --- a/modules/ripple_data/crypto/ripple_Base58Data.h +++ b/modules/ripple_data/crypto/ripple_Base58Data.h @@ -61,5 +61,7 @@ public: friend std::size_t hash_value(const CBase58Data& b58); }; +extern std::size_t hash_value (const CBase58Data& b58); + #endif // vim:ts=4 diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index d3ffa81b7a..16e715acab 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -95,7 +95,6 @@ #include "src/cpp/ripple/ripple_Config.h" #include "src/cpp/ripple/ripple_DatabaseCon.h" -#include "src/cpp/ripple/ripple_HashValue.h" #include "src/cpp/ripple/ripple_LoadEvent.h" #include "src/cpp/ripple/ripple_LoadMonitor.h" #include "src/cpp/ripple/ripple_Job.h" @@ -297,7 +296,6 @@ static DH* handleTmpDh(SSL* ssl, int is_export, int iKeyLength) #include "src/cpp/ripple/ripple_Features.cpp" #include "src/cpp/ripple/ripple_FeeVote.cpp" #include "src/cpp/ripple/ripple_HashRouter.cpp" -#include "src/cpp/ripple/ripple_HashValue.cpp" #include "src/cpp/ripple/ripple_Job.cpp" #include "src/cpp/ripple/ripple_JobQueue.cpp" #include "src/cpp/ripple/ripple_LoadEvent.cpp" diff --git a/newcoin.vcxproj b/newcoin.vcxproj index d00aec0f6c..47e57ecb4c 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -180,6 +180,12 @@ true + + true + true + true + true + true true @@ -846,12 +852,6 @@ true true - - true - true - true - true - true true @@ -1270,7 +1270,7 @@ - + @@ -1655,7 +1655,6 @@ - diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 08bc33521d..f5ee4ad7b7 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -729,9 +729,6 @@ 1. Modules\ripple_main\_unfactored\containers - - 1. Modules\ripple_main\refactored - 1. Modules\ripple_data\crypto @@ -810,6 +807,9 @@ 1. Modules\ripple_data\protocol + + 1. Modules\ripple_basics\types + @@ -1424,9 +1424,6 @@ 1. Modules\ripple_main\_unfactored\containers - - 1. Modules\ripple_main\refactored - 1. Modules\ripple_main\_unfactored\ledger @@ -1505,7 +1502,7 @@ 1. Modules\ripple_data\protocol - + 1. Modules\ripple_basics\types diff --git a/src/cpp/ripple/Application.cpp b/src/cpp/ripple/Application.cpp index 40f0a527e3..02ae10df9c 100644 --- a/src/cpp/ripple/Application.cpp +++ b/src/cpp/ripple/Application.cpp @@ -68,10 +68,11 @@ Application::Application () , mSweepTimer (mAuxService) , mShutdown (false) { - RandomNumbers::getInstance ().fillBytes (mNonce256.begin(), mNonce256.size()); - RandomNumbers::getInstance ().fill (&mNonceST); + // VFALCO: TODO, remove these once the call is thread safe. + HashMaps::getInstance ().initializeNonce (); } + extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[], *PathFindDBInit[]; extern int RpcDBCount, TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount, diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 3255799e01..28b5137fc9 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -79,9 +79,6 @@ class Application WSDoor* mWSPublicDoor; WSDoor* mWSPrivateDoor; - uint256 mNonce256; - std::size_t mNonceST; - boost::asio::deadline_timer mSweepTimer; std::map mPeerMap; @@ -148,9 +145,6 @@ public: leveldb::DB* getHashNodeLDB() { return mHashNodeLDB; } leveldb::DB* getEphemeralLDB() { return mEphemeralLDB; } - uint256 getNonce256() { return mNonce256; } - std::size_t getNonceST() { return mNonceST; } - bool isShutdown() { return mShutdown; } void setup(); void run(); diff --git a/src/cpp/ripple/HashedObject.h b/src/cpp/ripple/HashedObject.h index 52500bd6f9..31e31c3c16 100644 --- a/src/cpp/ripple/HashedObject.h +++ b/src/cpp/ripple/HashedObject.h @@ -6,9 +6,6 @@ #include #include -#include "ripple_HashValue.h" - - // VFALCO: TODO, Move this to someplace sensible!! // Adapter to furnish uptime information to KeyCache via UptimeTimer singleton struct UptimeTimerAdapter diff --git a/src/cpp/ripple/SHAMap.cpp b/src/cpp/ripple/SHAMap.cpp index bd30d1980d..ed2f81a4aa 100644 --- a/src/cpp/ripple/SHAMap.cpp +++ b/src/cpp/ripple/SHAMap.cpp @@ -24,11 +24,15 @@ DECLARE_INSTANCE(SHAMapTreeNode); void SHAMapNode::setMHash() const { - std::size_t h = theApp->getNonceST() + (mDepth * 0x9e3779b9); - const unsigned int *ptr = reinterpret_cast(mNodeID.begin()); - for (int i = (mDepth + 7) / 8; i != 0; --i) + std::size_t h = HashMaps::getInstance ().getNonce () + + (mDepth * 0x9e3779b9); + + const unsigned int *ptr = reinterpret_cast (mNodeID.begin()); + + for (int i = (mDepth + 7) / 8; i != 0; --i) h = (h * 0x9e3779b9) ^ *ptr++; - mHash = h; + + mHash = h; } std::size_t hash_value(const SHAMapNode& mn) diff --git a/src/cpp/ripple/ripple_HashValue.cpp b/src/cpp/ripple/ripple_HashValue.cpp deleted file mode 100644 index fa04fb34cd..0000000000 --- a/src/cpp/ripple/ripple_HashValue.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -std::size_t hash_value(const uint256& u) -{ - std::size_t seed = theApp->getNonceST(); - - return u.hash_combine(seed); -} - -std::size_t hash_value(const uint160& u) -{ - std::size_t seed = theApp->getNonceST(); - - return u.hash_combine(seed); -} - -std::size_t hash_value(const CBase58Data& b58) -{ - std::size_t seed = theApp->getNonceST() + (b58.nVersion * 0x9e3779b9); - boost::hash_combine(seed, b58.vchData); - return seed; -} diff --git a/src/cpp/ripple/ripple_HashValue.h b/src/cpp/ripple/ripple_HashValue.h deleted file mode 100644 index 0d4e594488..0000000000 --- a/src/cpp/ripple/ripple_HashValue.h +++ /dev/null @@ -1,17 +0,0 @@ - -#ifndef RIPPLE_HASH_VALUE_H -#define RIPPLE_HASH_VALUE_H - -// VFALCO: TODO, clean this up -// -// These are needed for boost::hash stuff. The implemnetations access -// the Application object for the nonce, introducing a nasty dependency -// so I have split them away from the relevant classes and put them here. - -extern std::size_t hash_value(const uint160&); - -extern std::size_t hash_value(const uint256&); - -extern std::size_t hash_value(const CBase58Data& b58); - -#endif