diff --git a/modules/ripple_app/misc/NetworkOPs.cpp b/modules/ripple_app/misc/NetworkOPs.cpp index 45c86d5a00..ddef0f0f7d 100644 --- a/modules/ripple_app/misc/NetworkOPs.cpp +++ b/modules/ripple_app/misc/NetworkOPs.cpp @@ -23,7 +23,7 @@ NetworkOPs::NetworkOPs (LedgerMaster* pLedgerMaster) , mProposing (false) , mValidating (false) , mFeatureBlocked (false) - , m_netTimer (this) + , m_heartbeatTimer (this) , m_clusterTimer (this) , mLedgerMaster (pLedgerMaster) , mCloseTimeOffset (0) @@ -38,7 +38,39 @@ NetworkOPs::NetworkOPs (LedgerMaster* pLedgerMaster) { } -void NetworkOPs::processNetTimer () +//------------------------------------------------------------------------------ + +void NetworkOPs::setStateTimer () +{ + setHeartbeatTimer (); + setClusterTimer (); +} + +void NetworkOPs::setHeartbeatTimer () +{ + m_heartbeatTimer.setExpiration (LEDGER_GRANULARITY / 1000.0); +} + +void NetworkOPs::setClusterTimer () +{ + m_clusterTimer.setExpiration (10.0); +} + +void NetworkOPs::onDeadlineTimer (DeadlineTimer& timer) +{ + if (timer == m_heartbeatTimer) + { + getApp().getJobQueue ().addJob (jtNETOP_TIMER, "NetOPs.heartbeat", + BIND_TYPE (&NetworkOPs::processHeartbeatTimer, this)); + } + else if (timer == m_clusterTimer) + { + getApp().getJobQueue ().addJob (jtNETOP_CLUSTER, "NetOPs.cluster", + BIND_TYPE (&NetworkOPs::processClusterTimer, this)); + } +} + +void NetworkOPs::processHeartbeatTimer () { { Application::ScopedLockType lock (getApp().getMasterLock (), __FILE__, __LINE__); @@ -86,24 +118,43 @@ void NetworkOPs::processNetTimer () if (mConsensus) mConsensus->timerEntry (); } + + setHeartbeatTimer (); } -void NetworkOPs::onDeadlineTimer (DeadlineTimer& timer) +void NetworkOPs::processClusterTimer () { - if (timer == m_netTimer) + bool synced = (getApp().getLedgerMaster().getValidatedLedgerAge() <= 240); + ClusterNodeStatus us("", synced ? getApp().getFeeTrack().getLocalFee() : 0, getNetworkTimeNC()); + if (!getApp().getUNL().nodeUpdate(getApp().getLocalCredentials().getNodePublic(), us)) { - getApp().getJobQueue ().addJob (jtNETOP_TIMER, "NetworkOPs::processNetTimer", - BIND_TYPE (&NetworkOPs::processNetTimer, this)); - //processNetTimer (); + WriteLog (lsDEBUG, NetworkOPs) << "To soon to send cluster update"; + return; } - else if (timer == m_clusterTimer) + + std::map nodes = getApp().getUNL().getClusterStatus(); + + protocol::TMCluster cluster; + for (std::map::iterator it = nodes.begin(), + end = nodes.end(); it != end; ++it) { - getApp().getJobQueue ().addJob (jtNETOP_CLUSTER, "NetworkOPs::doClusterReport", - BIND_TYPE (&NetworkOPs::doClusterReport, this)); - //doClusterReport(); + protocol::TMClusterNode& node = *cluster.add_clusternodes(); + node.set_publickey(it->first.humanNodePublic()); + node.set_reporttime(it->second.getReportTime()); + node.set_nodeload(it->second.getLoadFee()); + if (!it->second.getName().empty()) + node.set_nodename(it->second.getName()); } + + PackedMessage::pointer message = boost::make_shared(cluster, protocol::mtCLUSTER); + getApp().getPeers().relayMessageCluster (NULL, message); + + setClusterTimer (); } +//------------------------------------------------------------------------------ + + std::string NetworkOPs::strOperatingMode () { static const char* paStatusToken [] = @@ -648,13 +699,6 @@ void NetworkOPs::setFeatureBlocked () setMode (omTRACKING); } -void NetworkOPs::setStateTimer () -{ - m_netTimer.setRecurringExpiration (LEDGER_GRANULARITY / 1000.0); - - m_clusterTimer.setRecurringExpiration (10.0); -} - class ValidationCount { public: @@ -2390,31 +2434,3 @@ void NetworkOPs::missingNodeInLedger (uint32 seq) if (hash.isNonZero ()) getApp().getInboundLedgers ().findCreate (hash, seq); } - -void NetworkOPs::doClusterReport () -{ - bool synced = (getApp().getLedgerMaster().getValidatedLedgerAge() <= 240); - ClusterNodeStatus us("", synced ? getApp().getFeeTrack().getLocalFee() : 0, getNetworkTimeNC()); - if (!getApp().getUNL().nodeUpdate(getApp().getLocalCredentials().getNodePublic(), us)) - { - WriteLog (lsDEBUG, NetworkOPs) << "Too soon to send cluster update"; - return; - } - - std::map nodes = getApp().getUNL().getClusterStatus(); - - protocol::TMCluster cluster; - for (std::map::iterator it = nodes.begin(), - end = nodes.end(); it != end; ++it) - { - protocol::TMClusterNode& node = *cluster.add_clusternodes(); - node.set_publickey(it->first.humanNodePublic()); - node.set_reporttime(it->second.getReportTime()); - node.set_nodeload(it->second.getLoadFee()); - if (!it->second.getName().empty()) - node.set_nodename(it->second.getName()); - } - - PackedMessage::pointer message = boost::make_shared(cluster, protocol::mtCLUSTER); - getApp().getPeers().relayMessageCluster (NULL, message); -} diff --git a/modules/ripple_app/misc/NetworkOPs.h b/modules/ripple_app/misc/NetworkOPs.h index 52e88404fd..f95591b13a 100644 --- a/modules/ripple_app/misc/NetworkOPs.h +++ b/modules/ripple_app/misc/NetworkOPs.h @@ -253,7 +253,12 @@ public: { setMode (omFULL); } + + /** Called to initially start our timers. + Not called for stand-alone mode. + */ void setStateTimer (); + void newLCL (int proposers, int convergeTime, uint256 const& ledgerHash); void needNetworkLedger () { @@ -320,8 +325,6 @@ public: uint256 getConsensusLCL (); void reportFeeChange (); - void doClusterReport (); - //Helper function to generate SQL query to get transactions std::string transactionsSQL (std::string selection, const RippleAddress& account, int32 minLedger, int32 maxLedger, bool descending, uint32 offset, int limit, @@ -373,8 +376,11 @@ public: InfoSub::pointer addRpcSub (const std::string& strUrl, InfoSub::ref rspEntry); private: - void processNetTimer (); + void setHeartbeatTimer (); + void setClusterTimer (); void onDeadlineTimer (DeadlineTimer& timer); + void processHeartbeatTimer (); + void processClusterTimer (); void setMode (OperatingMode); @@ -399,7 +405,7 @@ private: bool mProposing, mValidating; bool mFeatureBlocked; boost::posix_time::ptime mConnectTime; - DeadlineTimer m_netTimer; + DeadlineTimer m_heartbeatTimer; DeadlineTimer m_clusterTimer; boost::shared_ptr mConsensus; boost::unordered_map < uint160,