mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Nicer nonce/hash code.
This commit is contained in:
@@ -37,6 +37,7 @@ Application::Application() :
|
||||
mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL)
|
||||
{
|
||||
RAND_bytes(mNonce256.begin(), mNonce256.size());
|
||||
RAND_bytes(reinterpret_cast<unsigned char *>(&mNonceST), sizeof(mNonceST));
|
||||
}
|
||||
|
||||
extern const char *TxnDBInit[], *LedgerDBInit[], *WalletDBInit[], *HashNodeDBInit[], *NetNodeDBInit[];
|
||||
|
||||
@@ -48,6 +48,7 @@ class Application
|
||||
RPCDoor* mRPCDoor;
|
||||
|
||||
uint256 mNonce256;
|
||||
std::size_t mNonceST;
|
||||
|
||||
std::map<std::string, Peer::pointer> mPeerMap;
|
||||
boost::recursive_mutex mPeerMapLock;
|
||||
@@ -69,13 +70,14 @@ public:
|
||||
LedgerAcquireMaster& getMasterLedgerAcquire() { return mMasterLedgerAcquire; }
|
||||
TransactionMaster& getMasterTransaction() { return mMasterTransaction; }
|
||||
|
||||
DatabaseCon* getTxnDB() { return mTxnDB; }
|
||||
DatabaseCon* getLedgerDB() { return mLedgerDB; }
|
||||
DatabaseCon* getWalletDB() { return mWalletDB; }
|
||||
DatabaseCon* getHashNodeDB() { return mHashNodeDB; }
|
||||
DatabaseCon* getNetNodeDB() { return mNetNodeDB; }
|
||||
DatabaseCon* getTxnDB() { return mTxnDB; }
|
||||
DatabaseCon* getLedgerDB() { return mLedgerDB; }
|
||||
DatabaseCon* getWalletDB() { return mWalletDB; }
|
||||
DatabaseCon* getHashNodeDB() { return mHashNodeDB; }
|
||||
DatabaseCon* getNetNodeDB() { return mNetNodeDB; }
|
||||
|
||||
uint256 getNonce256() { return mNonce256; }
|
||||
uint256 getNonce256() { return mNonce256; }
|
||||
std::size_t getNonceST() { return mNonceST; }
|
||||
|
||||
void run();
|
||||
void stop();
|
||||
|
||||
@@ -17,15 +17,15 @@
|
||||
|
||||
std::size_t hash_value(const SHAMapNode& mn)
|
||||
{
|
||||
return mn.getDepth()
|
||||
^ *reinterpret_cast<const std::size_t *>(mn.getNodeID().begin())
|
||||
^ *reinterpret_cast<const std::size_t *>(theApp->getNonce256().begin());
|
||||
std::size_t seed = theApp->getNonceST();
|
||||
boost::hash_combine(seed, mn.getDepth());
|
||||
return mn.getNodeID().hash_combine(seed);
|
||||
}
|
||||
|
||||
std::size_t hash_value(const uint256& u)
|
||||
{
|
||||
return *reinterpret_cast<const std::size_t *>(u.begin())
|
||||
^ *reinterpret_cast<const std::size_t *>(theApp->getNonce256().begin());
|
||||
std::size_t seed = theApp->getNonceST();
|
||||
return u.hash_combine(seed);
|
||||
}
|
||||
|
||||
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying)
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
|
||||
@@ -136,6 +138,13 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::size_t hash_combine(std::size_t& seed) const
|
||||
{
|
||||
for (int i = 0; i < WIDTH; ++i)
|
||||
boost::hash_combine(seed, pn[i]);
|
||||
return seed;
|
||||
}
|
||||
|
||||
friend inline int compare(const base_uint& a, const base_uint& b)
|
||||
{
|
||||
const unsigned char* pA = a.begin();
|
||||
|
||||
Reference in New Issue
Block a user