More tweaks to TCP failover logic. Such edge case.
This commit is contained in:
parent
700a450806
commit
81e5690410
3 changed files with 31 additions and 22 deletions
|
@ -543,6 +543,8 @@ Node::ReasonForTermination Node::run()
|
||||||
_r->timeOfLastResynchronize = Utils::now();
|
_r->timeOfLastResynchronize = Utils::now();
|
||||||
|
|
||||||
while (impl->reasonForTermination == NODE_RUNNING) {
|
while (impl->reasonForTermination == NODE_RUNNING) {
|
||||||
|
//TRACE("--- BEGIN main I/O loop");
|
||||||
|
|
||||||
if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) {
|
if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) {
|
||||||
FILE *tmpf = fopen(shutdownIfUnreadablePath.c_str(),"r");
|
FILE *tmpf = fopen(shutdownIfUnreadablePath.c_str(),"r");
|
||||||
if (!tmpf)
|
if (!tmpf)
|
||||||
|
|
|
@ -176,9 +176,9 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
|
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
|
||||||
if ((useTcp)||(!p->tcp())) {
|
if ((useTcp)||(!p->tcp())) {
|
||||||
|
p->pinged(now); // we log pings sent even if the send "fails", since what we want to track is when we last tried to ping
|
||||||
if (_r->sw->sendHELLO(self,*p)) {
|
if (_r->sw->sendHELLO(self,*p)) {
|
||||||
p->sent(now);
|
p->sent(now);
|
||||||
p->pinged(now);
|
|
||||||
sent = true;
|
sent = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,32 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
|
||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Peer::isTcpFailoverTime(const RuntimeEnvironment *_r,uint64_t now) const
|
||||||
|
throw()
|
||||||
|
{
|
||||||
|
uint64_t lastResync = _r->timeOfLastResynchronize;
|
||||||
|
if ((now - lastResync) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT) {
|
||||||
|
if ((now - _r->timeOfLastPacketReceived) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
uint64_t lastUdpPingSent = 0;
|
||||||
|
uint64_t lastUdpReceive = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
Mutex::Lock _l(_lock);
|
||||||
|
for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) {
|
||||||
|
if (p->type() == Path::PATH_TYPE_UDP) {
|
||||||
|
lastUdpPingSent = std::max(lastUdpPingSent,p->lastPing());
|
||||||
|
lastUdpReceive = std::max(lastUdpReceive,p->lastReceived());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ( (lastUdpPingSent > lastResync) && (lastUdpPingSent > lastUdpReceive) && ((now - lastUdpPingSent) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT) );
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void Peer::clean(uint64_t now)
|
void Peer::clean(uint64_t now)
|
||||||
{
|
{
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
|
|
|
@ -267,27 +267,8 @@ public:
|
||||||
* @param now Current time
|
* @param now Current time
|
||||||
* @return True if it's time to attempt TCP failover (if we have TCP_OUT paths)
|
* @return True if it's time to attempt TCP failover (if we have TCP_OUT paths)
|
||||||
*/
|
*/
|
||||||
inline bool isTcpFailoverTime(const RuntimeEnvironment *_r,uint64_t now) const
|
bool isTcpFailoverTime(const RuntimeEnvironment *_r,uint64_t now) const
|
||||||
throw()
|
throw();
|
||||||
{
|
|
||||||
if ((now - _r->timeOfLastResynchronize) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT) {
|
|
||||||
uint64_t lastUdpPingSent = 0;
|
|
||||||
uint64_t lastUdpReceive = 0;
|
|
||||||
|
|
||||||
{
|
|
||||||
Mutex::Lock _l(_lock);
|
|
||||||
for(std::vector<Path>::const_iterator p(_paths.begin());p!=_paths.end();++p) {
|
|
||||||
if (p->type() == Path::PATH_TYPE_UDP) {
|
|
||||||
lastUdpPingSent = std::max(lastUdpPingSent,p->lastPing());
|
|
||||||
lastUdpReceive = std::max(lastUdpReceive,p->lastReceived());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ( (lastUdpPingSent > lastUdpReceive) && ((now - lastUdpPingSent) >= ZT_TCP_TUNNEL_FAILOVER_TIMEOUT) );
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Current latency or 0 if unknown (max: 65535)
|
* @return Current latency or 0 if unknown (max: 65535)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue