mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Get rid of hash_SMN and instead extend boost::hash.
This makes the TaggedCache code cleaner.
This commit is contained in:
@@ -47,7 +47,7 @@ protected:
|
||||
int mYays, mNays;
|
||||
bool mOurPosition;
|
||||
std::vector<unsigned char> transaction;
|
||||
boost::unordered_map<uint256, bool, hash_SMN> mVotes;
|
||||
boost::unordered_map<uint256, bool> mVotes;
|
||||
|
||||
public:
|
||||
typedef boost::shared_ptr<LCTransaction> pointer;
|
||||
@@ -85,17 +85,17 @@ protected:
|
||||
LedgerProposal::pointer mOurPosition;
|
||||
|
||||
// Convergence tracking, trusted peers indexed by hash of public key
|
||||
boost::unordered_map<uint256, LedgerProposal::pointer, hash_SMN> mPeerPositions;
|
||||
boost::unordered_map<uint256, LedgerProposal::pointer> mPeerPositions;
|
||||
|
||||
// Transaction Sets, indexed by hash of transaction tree
|
||||
boost::unordered_map<uint256, SHAMap::pointer, hash_SMN> mComplete;
|
||||
boost::unordered_map<uint256, TransactionAcquire::pointer, hash_SMN> mAcquiring;
|
||||
boost::unordered_map<uint256, SHAMap::pointer> mComplete;
|
||||
boost::unordered_map<uint256, TransactionAcquire::pointer> mAcquiring;
|
||||
|
||||
// Peer sets
|
||||
boost::unordered_map<uint256, std::vector< boost::weak_ptr<Peer> >, hash_SMN> mPeerData;
|
||||
boost::unordered_map<uint256, std::vector< boost::weak_ptr<Peer> > > mPeerData;
|
||||
|
||||
// Disputed transactions
|
||||
boost::unordered_map<uint256, LCTransaction::pointer, hash_SMN> mDisputes;
|
||||
boost::unordered_map<uint256, LCTransaction::pointer> mDisputes;
|
||||
|
||||
// final accept logic
|
||||
static void Saccept(boost::shared_ptr<LedgerConsensus> This, SHAMap::pointer txSet);
|
||||
|
||||
@@ -285,7 +285,7 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
// Do we have sufficient validations for our last closed ledger? Or do sufficient nodes
|
||||
// agree? And do we have no better ledger available?
|
||||
// If so, we are either tracking or full.
|
||||
boost::unordered_map<uint256, ValidationCount, hash_SMN> ledgers;
|
||||
boost::unordered_map<uint256, ValidationCount> ledgers;
|
||||
|
||||
for (std::vector<Peer::pointer>::iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
|
||||
{
|
||||
|
||||
@@ -726,6 +726,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
|
||||
{
|
||||
SHAMap::pointer map;
|
||||
newcoin::TMLedgerData reply;
|
||||
bool fatLeaves = true;
|
||||
|
||||
if (packet.itype() == newcoin::liTS_CANDIDATE)
|
||||
{ // Request is for a transaction candidate set
|
||||
@@ -748,6 +749,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
|
||||
reply.set_ledgerseq(0);
|
||||
reply.set_ledgerhash(txHash.begin(), txHash.size());
|
||||
reply.set_type(newcoin::liTS_CANDIDATE);
|
||||
fatLeaves = false; // We'll already have most transactions
|
||||
}
|
||||
else
|
||||
{ // Figure out what ledger they want
|
||||
@@ -828,7 +830,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
|
||||
}
|
||||
std::vector<SHAMapNode> nodeIDs;
|
||||
std::list< std::vector<unsigned char> > rawNodes;
|
||||
if(map->getNodeFat(mn, nodeIDs, rawNodes))
|
||||
if(map->getNodeFat(mn, nodeIDs, rawNodes, fatLeaves))
|
||||
{
|
||||
std::vector<SHAMapNode>::iterator nodeIDIterator;
|
||||
std::list< std::vector<unsigned char> >::iterator rawNodeIterator;
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
#include "SHAMap.h"
|
||||
#include "Application.h"
|
||||
|
||||
std::size_t hash_SMN::operator() (const SHAMapNode& mn) const
|
||||
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 hash_SMN::operator() (const uint256& u) const
|
||||
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());
|
||||
@@ -671,7 +671,7 @@ void SHAMap::dump(bool hash)
|
||||
|
||||
std::cerr << " MAP Contains" << std::endl;
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
for(boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer, hash_SMN>::iterator it = mTNByID.begin();
|
||||
for(boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer>::iterator it = mTNByID.begin();
|
||||
it != mTNByID.end(); ++it)
|
||||
{
|
||||
std::cerr << it->second->getString() << std::endl;
|
||||
|
||||
14
src/SHAMap.h
14
src/SHAMap.h
@@ -76,14 +76,8 @@ public:
|
||||
SHAMapNode(const void *ptr, int len);
|
||||
};
|
||||
|
||||
class hash_SMN
|
||||
{
|
||||
|
||||
public:
|
||||
std::size_t operator() (const SHAMapNode& mn) const;
|
||||
|
||||
std::size_t operator() (const uint256& u) const;
|
||||
};
|
||||
extern std::size_t hash_value(const SHAMapNode& mn);
|
||||
extern std::size_t hash_value(const uint256& u);
|
||||
|
||||
class SHAMapItem
|
||||
{ // an item stored in a SHAMap
|
||||
@@ -234,7 +228,7 @@ public:
|
||||
private:
|
||||
uint32 mSeq;
|
||||
mutable boost::recursive_mutex mLock;
|
||||
boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer, hash_SMN> mTNByID;
|
||||
boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer> mTNByID;
|
||||
|
||||
boost::shared_ptr<std::map<SHAMapNode, SHAMapTreeNode::pointer> > mDirtyNodes;
|
||||
|
||||
@@ -301,7 +295,7 @@ public:
|
||||
// comparison/sync functions
|
||||
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max);
|
||||
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
|
||||
std::list<std::vector<unsigned char> >& rawNode);
|
||||
std::list<std::vector<unsigned char> >& rawNode, bool fatLeaves);
|
||||
bool addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode);
|
||||
bool addRootNode(const std::vector<unsigned char>& rootNode);
|
||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <map>
|
||||
|
||||
#include <boost/thread/recursive_mutex.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
// This class implemented a cache and a map. The cache keeps objects alive
|
||||
@@ -25,10 +26,10 @@ protected:
|
||||
mutable boost::recursive_mutex mLock;
|
||||
|
||||
int mTargetSize, mTargetAge;
|
||||
std::map<key_type, cache_entry> mCache; // Hold strong reference to recent objects
|
||||
boost::unordered_map<key_type, cache_entry> mCache; // Hold strong reference to recent objects
|
||||
time_t mLastSweep;
|
||||
|
||||
std::map<key_type, weak_data_ptr> mMap; // Track stored objects
|
||||
boost::unordered_map<key_type, weak_data_ptr> mMap; // Track stored objects
|
||||
|
||||
public:
|
||||
TaggedCache(int size, int age) : mTargetSize(size), mTargetAge(age), mLastSweep(time(NULL)) { ; }
|
||||
@@ -81,7 +82,7 @@ template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep
|
||||
time_t target = now - mTargetAge;
|
||||
|
||||
// Pass 1, remove old objects from cache
|
||||
typename std::map<key_type, cache_entry>::iterator cit = mCache.begin();
|
||||
typename boost::unordered_map<key_type, cache_entry>::iterator cit = mCache.begin();
|
||||
while (cit != mCache.end())
|
||||
{
|
||||
if (cit->second->second.first < target)
|
||||
@@ -90,7 +91,7 @@ template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep
|
||||
}
|
||||
|
||||
// Pass 2, remove dead objects from map
|
||||
typename std::map<key_type, weak_data_ptr>::iterator mit = mMap.begin();
|
||||
typename boost::unordered_map<key_type, weak_data_ptr>::iterator mit = mMap.begin();
|
||||
while (mit != mMap.end())
|
||||
{
|
||||
if (mit->second->expired())
|
||||
@@ -104,7 +105,7 @@ template<typename c_Key, typename c_Data> bool TaggedCache<c_Key, c_Data>::touch
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
// Is the object in the map?
|
||||
typename std::map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
typename boost::unordered_map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
if (mit == mMap.end()) return false;
|
||||
if (mit->second->expired())
|
||||
{ // in map, but expired
|
||||
@@ -113,7 +114,7 @@ template<typename c_Key, typename c_Data> bool TaggedCache<c_Key, c_Data>::touch
|
||||
}
|
||||
|
||||
// Is the object in the cache?
|
||||
typename std::map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
typename boost::unordered_map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
if (cit != mCache.end())
|
||||
{ // in both map and cache
|
||||
cit->second->first = time(NULL);
|
||||
@@ -129,7 +130,7 @@ template<typename c_Key, typename c_Data> bool TaggedCache<c_Key, c_Data>::del(c
|
||||
{ // Remove from cache, map unaffected
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
typename std::map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
typename boost::unordered_map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
if (cit == mCache.end()) return false;
|
||||
mCache.erase(cit);
|
||||
return true;
|
||||
@@ -141,7 +142,7 @@ bool TaggedCache<c_Key, c_Data>::canonicalize(const key_type& key, boost::shared
|
||||
// Return values: true=we had the data already
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
typename std::map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
typename boost::unordered_map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
if (mit == mMap.end())
|
||||
{ // not in map
|
||||
mCache.insert(std::make_pair(key, std::make_pair(time(NULL), data)));
|
||||
@@ -159,7 +160,7 @@ bool TaggedCache<c_Key, c_Data>::canonicalize(const key_type& key, boost::shared
|
||||
assert(!!data);
|
||||
|
||||
// Valid in map, is it in cache?
|
||||
typename std::map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
typename boost::unordered_map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
if (cit != mCache.end())
|
||||
cit->second.first = time(NULL); // Yes, refesh
|
||||
else // no, add to cache
|
||||
@@ -174,7 +175,7 @@ boost::shared_ptr<c_Data> TaggedCache<c_Key, c_Data>::fetch(const key_type& key)
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
// Is it in the map?
|
||||
typename std::map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
typename boost::unordered_map<key_type, weak_data_ptr>::iterator mit = mMap.find(key);
|
||||
if (mit == mMap.end()) return data_ptr(); // No, we're done
|
||||
if (mit->second.expired())
|
||||
{ // in map, but expired
|
||||
@@ -185,7 +186,7 @@ boost::shared_ptr<c_Data> TaggedCache<c_Key, c_Data>::fetch(const key_type& key)
|
||||
boost::shared_ptr<c_Data> data = mit->second.lock();
|
||||
|
||||
// Valid in map, is it in the cache?
|
||||
typename std::map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
typename boost::unordered_map<key_type, cache_entry>::iterator cit = mCache.find(key);
|
||||
if (cit != mCache.end())
|
||||
cit->second.first = time(NULL); // Yes, refresh
|
||||
else // No, add to cache
|
||||
|
||||
Reference in New Issue
Block a user