Inject SHAMap missing node handler dependency

This commit is contained in:
Vinnie Falco
2013-12-22 11:54:03 -08:00
parent 2f521a6a91
commit 074325a7ea
2 changed files with 65 additions and 45 deletions

View File

@@ -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<SHAMapTreeNode> (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<SHAMapTreeNode> (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<SHAMapTreeNode> (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<SHAMapTreeNode> (mSeq, SHAMapNode (0, uint256 ()));
root->makeInner ();
mTNByID[*root] = root;
}
SHAMap::pointer SHAMap::snapShot (bool isMutable)
{
SHAMap::pointer ret = boost::make_shared<SHAMap> (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;
}

View File

@@ -32,7 +32,22 @@ enum SHAMapState
class SHAMap
: public CountedObject <SHAMap>
{
private:
/** Function object which handles missing nodes. */
typedef beast::function <void (uint32 refNum)> 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<SHAMap> 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<NodeMap> mDirtyNodes;
SHAMapTreeNode::pointer root;
SHAMapState mState;
SHAMapType mType;
MissingNodeHandler m_missing_node_handler;
};
#endif
// vim:ts=4