From 700a450806263f035f7b1266d5f63c5934461e97 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 1 Apr 2014 18:39:10 -0700 Subject: More tweaks to algorithm for determining when to fail over to TCP, and stop supernodes from resynchronizing unless explicitly ordered. --- node/Node.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'node/Node.cpp') diff --git a/node/Node.cpp b/node/Node.cpp index a5978936..a0dd14c1 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -540,7 +540,7 @@ Node::ReasonForTermination Node::run() long lastDelayDelta = 0; uint64_t networkConfigurationFingerprint = 0; - _r->timeOfLastResynchronize = 0; + _r->timeOfLastResynchronize = Utils::now(); while (impl->reasonForTermination == NODE_RUNNING) { if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) { @@ -551,13 +551,7 @@ Node::ReasonForTermination Node::run() } uint64_t now = Utils::now(); - - // Did the user send SIGHUP or otherwise order network resync? (mostly for debugging) - bool resynchronize = impl->resynchronize; - impl->resynchronize = false; - if (resynchronize) { - LOG("manual resynchronize ordered, resyncing with network"); - } + bool resynchronize = false; // If it looks like the computer slept and woke, resynchronize. if (lastDelayDelta >= ZT_SLEEP_WAKE_DETECTION_THRESHOLD) { @@ -577,18 +571,29 @@ Node::ReasonForTermination Node::run() } } + // Supernodes do not resynchronize unless explicitly ordered via SIGHUP. + if ((resynchronize)&&(_r->topology->amSupernode())) + resynchronize = false; + + // Check for SIGHUP / force resync. + if (impl->resynchronize) { + impl->resynchronize = false; + resynchronize = true; + LOG("resynchronize forced by user, syncing with network"); + } + if (resynchronize) _r->timeOfLastResynchronize = now; /* Ping supernodes separately, and do so more aggressively if we haven't * heard anything from anyone since our last resynchronize / startup. */ if ( ((now - lastSupernodePing) >= ZT_PEER_DIRECT_PING_DELAY) || - ((_r->timeOfLastResynchronize > _r->timeOfLastPacketReceived) && ((now - lastSupernodePing) >= ZT_PING_UNANSWERED_AFTER)) ) { + ((_r->timeOfLastResynchronize > _r->timeOfLastPacketReceived) && ((now - lastSupernodePing) >= ZT_STARTUP_AGGRO)) ) { lastSupernodePing = now; std::vector< SharedPtr > sns(_r->topology->supernodePeers()); TRACE("pinging %d supernodes",(int)sns.size()); for(std::vector< SharedPtr >::const_iterator p(sns.begin());p!=sns.end();++p) - (*p)->sendPing(_r,now,resynchronize); + (*p)->sendPing(_r,now); } if (resynchronize) { @@ -625,7 +630,7 @@ Node::ReasonForTermination Node::run() if ((now - lastPingCheck) >= ZT_PING_CHECK_DELAY) { lastPingCheck = now; try { - _r->topology->eachPeer(Topology::PingPeersThatNeedPing(_r,now,resynchronize)); + _r->topology->eachPeer(Topology::PingPeersThatNeedPing(_r,now)); _r->topology->eachPeer(Topology::OpenPeersThatNeedFirewallOpener(_r,now)); } catch (std::exception &exc) { LOG("unexpected exception running ping check cycle: %s",exc.what()); -- cgit v1.2.3