Replace all Application nonces with nonce singleton and refactor hash_value functions

This commit is contained in:
Vinnie Falco
2013-06-04 13:35:54 -07:00
parent 0523d6a054
commit b523b6c8d4
17 changed files with 69 additions and 76 deletions

View File

@@ -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,

View File

@@ -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();

View File

@@ -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

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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