Yet more cleanup to TCP logic, this time adding a master switch and adding UDP preference in send().

This commit is contained in:
Adam Ierymenko 2014-04-09 17:08:35 -07:00
parent 73153b89b4
commit 8fb442d81a
6 changed files with 110 additions and 76 deletions

View file

@ -591,13 +591,29 @@ Node::ReasonForTermination Node::run()
LOG("resynchronize forced by user, syncing with network");
}
if (resynchronize)
if (resynchronize) {
_r->tcpTunnelingEnabled = false; // turn off TCP tunneling master switch at first
_r->timeOfLastResynchronize = now;
}
/* Ping supernodes separately, and do so more aggressively if we haven't
* heard anything from anyone since our last resynchronize / startup. */
/* Supernodes are pinged separately and more aggressively. The
* ZT_STARTUP_AGGRO parameter sets a limit on how rapidly they are
* tried, while PingSupernodesThatNeedPing contains the logic for
* determining if they need PING. */
if ((now - lastSupernodePingCheck) >= ZT_STARTUP_AGGRO) {
lastSupernodePingCheck = now;
uint64_t lastReceiveFromAnySupernode = 0; // function object result paramter
_r->topology->eachSupernodePeer(Topology::FindMostRecentDirectReceiveTimestamp(lastReceiveFromAnySupernode));
// Turn on TCP tunneling master switch if we haven't heard anything since before
// the last resynchronize and we've been trying long enough.
uint64_t tlr = _r->timeOfLastResynchronize;
if ((lastReceiveFromAnySupernode < tlr)&&((now - tlr) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT)) {
TRACE("network still unreachable after %u ms, TCP TUNNELING ENABLED",(unsigned int)ZT_TCP_TUNNEL_FAILOVER_TIMEOUT);
_r->tcpTunnelingEnabled = true;
}
_r->topology->eachSupernodePeer(Topology::PingSupernodesThatNeedPing(_r,now));
}