summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-26 16:44:58 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-03-26 16:44:58 -0700
commite6b23059aca4947c8c4638c5d5e0abdba3b2b7b7 (patch)
treeadaf54ea49f8086bb79dcd825ca35369aafa9c1b
parent04169b51505bc41f70ad7b8797e8e4d5376bb9c7 (diff)
downloadinfinitytier-e6b23059aca4947c8c4638c5d5e0abdba3b2b7b7.tar.gz
infinitytier-e6b23059aca4947c8c4638c5d5e0abdba3b2b7b7.zip
Change the way TCP failover is invoked.
-rw-r--r--node/Path.hpp13
-rw-r--r--node/Peer.cpp16
2 files changed, 11 insertions, 18 deletions
diff --git a/node/Path.hpp b/node/Path.hpp
index 960b08b3..09ed1f9e 100644
--- a/node/Path.hpp
+++ b/node/Path.hpp
@@ -88,19 +88,6 @@ public:
}
/**
- * @return True if it appears that a ping has gone unanswered
- */
- inline bool pingUnanswered(uint64_t now) const
- throw()
- {
- uint64_t lp = _lastPing;
- uint64_t lr = _lastReceived;
- if (lp)
- return ((lr < lp)&&((lp - lr) > ZT_PING_UNANSWERED_AFTER));
- return false;
- }
-
- /**
* @return Human-readable address and other information about this path, some computed as of current time
*/
inline std::string toString() const
diff --git a/node/Peer.cpp b/node/Peer.cpp
index f8ff9ba6..0cd82909 100644
--- a/node/Peer.cpp
+++ b/node/Peer.cpp
@@ -150,18 +150,24 @@ bool Peer::sendPing(const RuntimeEnvironment *_r,uint64_t now,bool firstSinceRes
{
bool sent = false;
SharedPtr<Peer> self(this);
+
Mutex::Lock _l(_lock);
+ // NOTE: this will never ping a peer that has *only* TCP paths. Right
+ // now there's never such a thing as TCP is only for failover.
+
bool pingTcp;
if (!firstSinceReset) {
// Do not use TCP if one of our UDP endpoints has answered recently.
- pingTcp = true;
+ uint64_t lastPing = 0;
+ uint64_t lastDirectReceive = 0;
+
for(std::vector<Path>::iterator p(_paths.begin());p!=_paths.end();++p) {
- if (!p->pingUnanswered(now)) {
- pingTcp = false;
- break;
- }
+ lastPing = std::max(lastPing,p->lastPing());
+ lastDirectReceive = std::max(lastDirectReceive,p->lastReceived());
}
+
+ pingTcp = ( (lastDirectReceive < lastPing) && ((lastPing - lastDirectReceive) >= ZT_PING_UNANSWERED_AFTER) );
} else pingTcp = false;
TRACE("PING %s (pingTcp==%d)",_id.address().toString().c_str(),(int)pingTcp);