summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-04-02 17:32:47 -0400
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-04-02 17:32:47 -0400
commit81e56904104c45beb17e574eb1691a864cd91bb2 (patch)
tree5951d4046b170e15e3e0dda410797d828154902b /node
parent700a450806263f035f7b1266d5f63c5934461e97 (diff)
downloadinfinitytier-81e56904104c45beb17e574eb1691a864cd91bb2.tar.gz
infinitytier-81e56904104c45beb17e574eb1691a864cd91bb2.zip
More tweaks to TCP failover logic. Such edge case.
Diffstat (limited to 'node')
-rw-r--r--node/Node.cpp2
-rw-r--r--node/Peer.cpp28
-rw-r--r--node/Peer.hpp23
3 files changed, 31 insertions, 22 deletions
diff --git a/node/Node.cpp b/node/Node.cpp
index a0dd14c1..051cb317 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -543,6 +543,8 @@ Node::ReasonForTermination Node::run()
_r->timeOfLastResynchronize = Utils::now();
while (impl->reasonForTermination == NODE_RUNNING) {
+ //TRACE("--- BEGIN main I/O loop");
+
if (Utils::fileExists(shutdownIfUnreadablePath.c_str(),false)) {
FILE *tmpf = fopen(shutdownIfUnreadablePath.c_str(),"r");
if (!tmpf)
diff --git a/node/Peer.cpp b/node/Peer.cpp
index 3fad7c05..f8ff4082 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -176,9 +176,9 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
Mutex::Lock _l(_lock);
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
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)) {
p->sent(now);
- p->pinged(now);
sent = true;
}
}
@@ -187,6 +187,32 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now)
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)
{
Mutex::Lock _l(_lock);
diff --git a/node/Peer.hpp b/node/Peer.hpp
index 8b8bf578..6a57e14a 100644
--- a/node/Peer.hpp
+++ b/node/Peer.hpp
@@ -267,27 +267,8 @@ public:
* @param now Current time
* @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
- 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;
- }
+ bool isTcpFailoverTime(const RuntimeEnvironment *_r,uint64_t now) const
+ throw();
/**
* @return Current latency or 0 if unknown (max: 65535)