Fix NetworkOPs to set timers on processing

This commit is contained in:
Vinnie Falco
2013-08-24 10:09:35 -07:00
parent 21485ec003
commit 8b59a7b07b
2 changed files with 72 additions and 50 deletions

View File

@@ -24,7 +24,7 @@ NetworkOPs::NetworkOPs (LedgerMaster* pLedgerMaster)
, mProposing (false)
, mValidating (false)
, mFeatureBlocked (false)
, m_netTimer (this)
, m_heartbeatTimer (this)
, m_clusterTimer (this)
, mLedgerMaster (pLedgerMaster)
, mCloseTimeOffset (0)
@@ -39,7 +39,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__);
@@ -87,24 +119,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<RippleAddress, ClusterNodeStatus> nodes = getApp().getUNL().getClusterStatus();
protocol::TMCluster cluster;
for (std::map<RippleAddress, ClusterNodeStatus>::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<PackedMessage>(cluster, protocol::mtCLUSTER);
getApp().getPeers().relayMessageCluster (NULL, message);
setClusterTimer ();
}
//------------------------------------------------------------------------------
std::string NetworkOPs::strOperatingMode ()
{
static const char* paStatusToken [] =
@@ -649,13 +700,6 @@ void NetworkOPs::setFeatureBlocked ()
setMode (omTRACKING);
}
void NetworkOPs::setStateTimer ()
{
m_netTimer.setRecurringExpiration (LEDGER_GRANULARITY / 1000.0);
m_clusterTimer.setRecurringExpiration (10.0);
}
class ValidationCount
{
public:
@@ -2391,31 +2435,3 @@ void NetworkOPs::missingNodeInLedger (uint32 seq)
if (hash.isNonZero ())
getApp().getInboundLedgers ().findCreate (hash, seq, false);
}
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<RippleAddress, ClusterNodeStatus> nodes = getApp().getUNL().getClusterStatus();
protocol::TMCluster cluster;
for (std::map<RippleAddress, ClusterNodeStatus>::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<PackedMessage>(cluster, protocol::mtCLUSTER);
getApp().getPeers().relayMessageCluster (NULL, message);
}

View File

@@ -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);
@@ -404,7 +410,7 @@ private:
bool mProposing, mValidating;
bool mFeatureBlocked;
boost::posix_time::ptime mConnectTime;
DeadlineTimer m_netTimer;
DeadlineTimer m_heartbeatTimer;
DeadlineTimer m_clusterTimer;
boost::shared_ptr<LedgerConsensus> mConsensus;
boost::unordered_map < uint160,