diff --git a/src/ripple_app/shamap/SHAMap.cpp b/src/ripple_app/shamap/SHAMap.cpp index f5bed8230..d913de3d8 100644 --- a/src/ripple_app/shamap/SHAMap.cpp +++ b/src/ripple_app/shamap/SHAMap.cpp @@ -17,12 +17,51 @@ */ //============================================================================== -#ifndef STATE_MAP_BUCKETS -#define STATE_MAP_BUCKETS 1024 -#endif - SETUP_LOG (SHAMap) +void SHAMap::DefaultMissingNodeHandler::operator() (uint32 refNUm) +{ + getApp().getOPs ().missingNodeInLedger (refNUm); +}; + +//------------------------------------------------------------------------------ + +SHAMap::SHAMap (SHAMapType t, uint32 seq, + MissingNodeHandler missing_node_handler) + : mLock (this, "SHAMap", __FILE__, __LINE__) + , mSeq (seq) + , mLedgerSeq (0) + , mState (smsModifying) + , mType (t) + , m_missing_node_handler (missing_node_handler) +{ + assert (mSeq != 0); + if (t == smtSTATE) + mTNByID.rehash (STATE_MAP_BUCKETS); + + root = boost::make_shared (mSeq, SHAMapNode (0, uint256 ())); + root->makeInner (); + mTNByID[*root] = root; +} + +SHAMap::SHAMap (SHAMapType t, uint256 const& hash, + MissingNodeHandler missing_node_handler) + : mLock (this, "SHAMap", __FILE__, __LINE__) + , mSeq (1) + , mLedgerSeq (0) + , mState (smsSynching) + , mType (t) + , m_missing_node_handler (missing_node_handler) +{ + // FIXME: Need to acquire root node + if (t == smtSTATE) + mTNByID.rehash (STATE_MAP_BUCKETS); + + root = boost::make_shared (mSeq, SHAMapNode (0, uint256 ())); + root->makeInner (); + mTNByID[*root] = root; +} + TaggedCacheType< SHAMap::TNIndex, SHAMapTreeNode, UptimeTimerAdapter> SHAMap::treeNodeCache ("TreeNodeCache", 65536, 60); @@ -68,39 +107,6 @@ std::size_t hash_value (const SHAMapNode& mn) return mn.getMHash (); } - -SHAMap::SHAMap (SHAMapType t, uint32 seq) - : mLock (this, "SHAMap", __FILE__, __LINE__) - , mSeq (seq) - , mLedgerSeq (0) - , mState (smsModifying) - , mType (t) -{ - assert (mSeq != 0); - if (t == smtSTATE) - mTNByID.rehash (STATE_MAP_BUCKETS); - - root = boost::make_shared (mSeq, SHAMapNode (0, uint256 ())); - root->makeInner (); - mTNByID[*root] = root; -} - -SHAMap::SHAMap (SHAMapType t, uint256 const& hash) - : mLock (this, "SHAMap", __FILE__, __LINE__) - , mSeq (1) - , mLedgerSeq (0) - , mState (smsSynching) - , mType (t) -{ - // FIXME: Need to acquire root node - if (t == smtSTATE) - mTNByID.rehash (STATE_MAP_BUCKETS); - - root = boost::make_shared (mSeq, SHAMapNode (0, uint256 ())); - root->makeInner (); - mTNByID[*root] = root; -} - SHAMap::pointer SHAMap::snapShot (bool isMutable) { SHAMap::pointer ret = boost::make_shared (mType); @@ -906,7 +912,7 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternalNT (const SHAMapNode& id, uint2 { if (mLedgerSeq != 0) { - getApp().getOPs ().missingNodeInLedger (mLedgerSeq); + m_missing_node_handler (mLedgerSeq); mLedgerSeq = 0; } diff --git a/src/ripple_app/shamap/SHAMap.h b/src/ripple_app/shamap/SHAMap.h index 7cad145eb..fb857732b 100644 --- a/src/ripple_app/shamap/SHAMap.h +++ b/src/ripple_app/shamap/SHAMap.h @@ -32,7 +32,22 @@ enum SHAMapState class SHAMap : public CountedObject { +private: + /** Function object which handles missing nodes. */ + typedef beast::function MissingNodeHandler; + + /** Default handler which calls NetworkOPs. */ + struct DefaultMissingNodeHandler + { + void operator() (uint32 refNUm); + }; + public: + enum + { + STATE_MAP_BUCKETS = 1024 + }; + static char const* getCountedObjectName () { return "SHAMap"; } typedef boost::shared_ptr pointer; @@ -47,8 +62,11 @@ public: public: // build new map - explicit SHAMap (SHAMapType t, uint32 seq = 1); - SHAMap (SHAMapType t, uint256 const & hash); + explicit SHAMap (SHAMapType t, uint32 seq = 1, + MissingNodeHandler missing_node_handler = DefaultMissingNodeHandler()); + + SHAMap (SHAMapType t, uint256 const& hash, + MissingNodeHandler missing_node_handler = DefaultMissingNodeHandler()); ~SHAMap (); @@ -268,15 +286,11 @@ private: uint32 mSeq; uint32 mLedgerSeq; // sequence number of ledger this is part of NodeMap mTNByID; - boost::shared_ptr mDirtyNodes; - SHAMapTreeNode::pointer root; - SHAMapState mState; - SHAMapType mType; + MissingNodeHandler m_missing_node_handler; }; #endif -// vim:ts=4