mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Replace all Application nonces with nonce singleton and refactor hash_value functions
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -84,7 +84,7 @@ private:
|
||||
@note This routine will be called concurrently.
|
||||
*/
|
||||
template <class T>
|
||||
NonceHolder <T> const& getNonceHolder ()
|
||||
NonceHolder <T> const& getNonceHolder () const
|
||||
{
|
||||
static NonceHolder <T> nonceHolder;
|
||||
|
||||
15
modules/ripple_basics/types/ripple_UInt256.cpp
Normal file
15
modules/ripple_basics/types/ripple_UInt256.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
std::size_t hash_value(const uint256& u)
|
||||
{
|
||||
std::size_t seed = HashMaps::getInstance ().getNonce <size_t> ();
|
||||
|
||||
return u.hash_combine (seed);
|
||||
}
|
||||
|
||||
std::size_t hash_value(const uint160& u)
|
||||
{
|
||||
std::size_t seed = HashMaps::getInstance ().getNonce <size_t> ();
|
||||
|
||||
return u.hash_combine(seed);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 <class T>
|
||||
void fill (T* object)
|
||||
|
||||
@@ -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 <size_t> ()
|
||||
+ (b58.nVersion * 0x9e3779b9);
|
||||
|
||||
boost::hash_combine (seed, b58.vchData);
|
||||
|
||||
return seed;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -180,6 +180,12 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="modules\ripple_basics\ripple_basics.cpp" />
|
||||
<ClCompile Include="modules\ripple_basics\types\ripple_Uint256.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="modules\ripple_basics\utility\ripple_ByteOrder.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -846,12 +852,6 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\ripple_HashValue.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\ripple_Job.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
@@ -1270,7 +1270,7 @@
|
||||
<ClInclude Include="modules\ripple_basics\containers\ripple_SecureAllocator.h" />
|
||||
<ClInclude Include="modules\ripple_basics\containers\ripple_TaggedCache.h" />
|
||||
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_HashTables.h" />
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_HashMaps.h" />
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_UInt256.h" />
|
||||
<ClInclude Include="modules\ripple_basics\utility\ripple_ByteOrder.h" />
|
||||
<ClInclude Include="modules\ripple_basics\utility\ripple_DiffieHellmanUtil.h" />
|
||||
@@ -1655,7 +1655,6 @@
|
||||
<ClInclude Include="src\cpp\ripple\LedgerProposal.h" />
|
||||
<ClInclude Include="src\cpp\ripple\LedgerTiming.h" />
|
||||
<ClInclude Include="src\cpp\ripple\LoadManager.h" />
|
||||
<ClInclude Include="src\cpp\ripple\ripple_HashValue.h" />
|
||||
<ClInclude Include="src\cpp\ripple\ripple_Job.h" />
|
||||
<ClInclude Include="src\cpp\ripple\ripple_JobQueue.h" />
|
||||
<ClInclude Include="src\cpp\ripple\ripple_LoadMonitor.h" />
|
||||
|
||||
@@ -729,9 +729,6 @@
|
||||
<ClCompile Include="src\cpp\ripple\SHAMapSync.cpp">
|
||||
<Filter>1. Modules\ripple_main\_unfactored\containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\ripple_HashValue.cpp">
|
||||
<Filter>1. Modules\ripple_main\refactored</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="modules\ripple_data\crypto\ripple_CKeyDeterministic.cpp">
|
||||
<Filter>1. Modules\ripple_data\crypto</Filter>
|
||||
</ClCompile>
|
||||
@@ -810,6 +807,9 @@
|
||||
<ClCompile Include="modules\ripple_data\protocol\ripple_STAmountRound.cpp">
|
||||
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="modules\ripple_basics\types\ripple_Uint256.cpp">
|
||||
<Filter>1. Modules\ripple_basics\types</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="database\sqlite3ext.h">
|
||||
@@ -1424,9 +1424,6 @@
|
||||
<ClInclude Include="src\cpp\ripple\SHAMapSync.h">
|
||||
<Filter>1. Modules\ripple_main\_unfactored\containers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\ripple_HashValue.h">
|
||||
<Filter>1. Modules\ripple_main\refactored</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\cpp\ripple\SerializedValidation.h">
|
||||
<Filter>1. Modules\ripple_main\_unfactored\ledger</Filter>
|
||||
</ClInclude>
|
||||
@@ -1505,7 +1502,7 @@
|
||||
<ClInclude Include="modules\ripple_data\protocol\ripple_RippleSystem.h">
|
||||
<Filter>1. Modules\ripple_data\protocol</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_HashTables.h">
|
||||
<ClInclude Include="modules\ripple_basics\types\ripple_HashMaps.h">
|
||||
<Filter>1. Modules\ripple_basics\types</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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 <size_t> ();
|
||||
}
|
||||
|
||||
|
||||
extern const char *RpcDBInit[], *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[],
|
||||
*NetNodeDBInit[], *PathFindDBInit[];
|
||||
extern int RpcDBCount, TxnDBCount, LedgerDBCount, WalletDBCount, HashNodeDBCount,
|
||||
|
||||
@@ -79,9 +79,6 @@ class Application
|
||||
WSDoor* mWSPublicDoor;
|
||||
WSDoor* mWSPrivateDoor;
|
||||
|
||||
uint256 mNonce256;
|
||||
std::size_t mNonceST;
|
||||
|
||||
boost::asio::deadline_timer mSweepTimer;
|
||||
|
||||
std::map<std::string, Peer::pointer> 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();
|
||||
|
||||
@@ -6,9 +6,6 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
#include "ripple_HashValue.h"
|
||||
|
||||
|
||||
// VFALCO: TODO, Move this to someplace sensible!!
|
||||
// Adapter to furnish uptime information to KeyCache via UptimeTimer singleton
|
||||
struct UptimeTimerAdapter
|
||||
|
||||
@@ -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<const unsigned int *>(mNodeID.begin());
|
||||
for (int i = (mDepth + 7) / 8; i != 0; --i)
|
||||
std::size_t h = HashMaps::getInstance ().getNonce <std::size_t> ()
|
||||
+ (mDepth * 0x9e3779b9);
|
||||
|
||||
const unsigned int *ptr = reinterpret_cast <const unsigned int *>(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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user