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);
}