summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorGrant Limberg <glimberg@gmail.com>2015-05-23 13:34:21 -0700
committerGrant Limberg <glimberg@gmail.com>2015-05-23 13:34:21 -0700
commit5c2aaad365b5f4d575d4cc40d7808db990a7f680 (patch)
tree84d50bface4ae245994dc78cb57738711f2baebc /node
parent1e043a3f66c5ae7d9c1043be3244d605cbaa64fa (diff)
parentd8783b14eb465cd97950afd726e940bbe3708c8a (diff)
downloadinfinitytier-5c2aaad365b5f4d575d4cc40d7808db990a7f680.tar.gz
infinitytier-5c2aaad365b5f4d575d4cc40d7808db990a7f680.zip
Merge branch 'adamierymenko-dev' into android-jni
Diffstat (limited to 'node')
-rw-r--r--node/Constants.hpp2
-rw-r--r--node/Node.cpp8
-rw-r--r--node/Node.hpp1
-rw-r--r--node/Switch.cpp59
-rw-r--r--node/Switch.hpp2
5 files changed, 27 insertions, 45 deletions
diff --git a/node/Constants.hpp b/node/Constants.hpp
index 1da10d11..ed227f9f 100644
--- a/node/Constants.hpp
+++ b/node/Constants.hpp
@@ -297,7 +297,7 @@
/**
* Delay between initial direct NAT-t packet and more aggressive techniques
*/
-#define ZT_NAT_T_TACTICAL_ESCALATION_DELAY 2000
+#define ZT_NAT_T_TACTICAL_ESCALATION_DELAY 1000
/**
* Size of anti-recursion history (see AntiRecursion.hpp)
diff --git a/node/Node.cpp b/node/Node.cpp
index 6b3f1f2c..c5c9873c 100644
--- a/node/Node.cpp
+++ b/node/Node.cpp
@@ -77,7 +77,6 @@ Node::Node(
_networks(),
_networks_m(),
_now(now),
- _startTimeAfterInactivity(0),
_lastPingCheck(0),
_lastHousekeepingRun(0),
_lastBeacon(0)
@@ -217,17 +216,12 @@ ZT1_ResultCode Node::processBackgroundTasks(uint64_t now,volatile uint64_t *next
if ((now - _lastPingCheck) >= ZT_PING_CHECK_INVERVAL) {
_lastPingCheck = now;
- // This is used to compute whether we appear to be "online" or not
- if ((now - _startTimeAfterInactivity) > (ZT_PING_CHECK_INVERVAL * 3))
- _startTimeAfterInactivity = now;
-
try {
_PingPeersThatNeedPing pfunc(RR,now);
RR->topology->eachPeer<_PingPeersThatNeedPing &>(pfunc);
- const uint64_t lastActivityAgo = now - std::max(_startTimeAfterInactivity,pfunc.lastReceiveFromUpstream);
bool oldOnline = _online;
- _online = (lastActivityAgo < ZT_PEER_ACTIVITY_TIMEOUT);
+ _online = ((now - pfunc.lastReceiveFromUpstream) < ZT_PEER_ACTIVITY_TIMEOUT);
if (oldOnline != _online)
postEvent(_online ? ZT1_EVENT_ONLINE : ZT1_EVENT_OFFLINE);
} catch ( ... ) {
diff --git a/node/Node.hpp b/node/Node.hpp
index f8678115..1d9372e4 100644
--- a/node/Node.hpp
+++ b/node/Node.hpp
@@ -229,7 +229,6 @@ private:
Mutex _backgroundTasksLock;
uint64_t _now;
- uint64_t _startTimeAfterInactivity;
uint64_t _lastPingCheck;
uint64_t _lastHousekeepingRun;
uint64_t _lastBeacon;
diff --git a/node/Switch.cpp b/node/Switch.cpp
index 19a77db7..4bdf2d84 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -444,42 +444,31 @@ unsigned long Switch::doTimerTasks(uint64_t now)
continue;
} else {
// Nope, nothing yet. Time to kill some kittens.
-
- switch(qi->strategyIteration++) {
-
- case 0: {
- // First strategy: rifle method: direct packet to known port
- qi->peer->attemptToContactAt(RR,qi->inaddr,now);
- } break;
-
- case 1: {
- // Second strategy: shotgun method up: try a few ports above
- InetAddress tmpaddr(qi->inaddr);
- int p = (int)qi->inaddr.port();
- for(int i=0;i<9;++i) {
- if (++p > 0xffff) break;
- tmpaddr.setPort((unsigned int)p);
- qi->peer->attemptToContactAt(RR,tmpaddr,now);
- }
- } break;
-
- case 2: {
- // Third strategy: shotgun method down: try a few ports below
- InetAddress tmpaddr(qi->inaddr);
- int p = (int)qi->inaddr.port();
- for(int i=0;i<3;++i) {
- if (--p < 1024) break;
- tmpaddr.setPort((unsigned int)p);
- qi->peer->attemptToContactAt(RR,tmpaddr,now);
- }
-
- // We've tried all strategies
- _contactQueue.erase(qi++);
- continue;
- } break;
-
+ if (qi->strategyIteration == 0) {
+ // First strategy: send packet directly (we already tried this but try again)
+ qi->peer->attemptToContactAt(RR,qi->inaddr,now);
+ } else if (qi->strategyIteration <= 9) {
+ // Strategies 1-9: try escalating ports
+ InetAddress tmpaddr(qi->inaddr);
+ int p = (int)qi->inaddr.port() + qi->strategyIteration;
+ if (p < 0xffff) {
+ tmpaddr.setPort((unsigned int)p);
+ qi->peer->attemptToContactAt(RR,tmpaddr,now);
+ } else qi->strategyIteration = 9;
+ } else if (qi->strategyIteration <= 18) {
+ // Strategies 10-18: try ports below
+ InetAddress tmpaddr(qi->inaddr);
+ int p = (int)qi->inaddr.port() - (qi->strategyIteration - 9);
+ if (p >= 1024) {
+ tmpaddr.setPort((unsigned int)p);
+ qi->peer->attemptToContactAt(RR,tmpaddr,now);
+ } else qi->strategyIteration = 18;
+ } else {
+ // All strategies tried, expire entry
+ _contactQueue.erase(qi++);
+ continue;
}
-
+ ++qi->strategyIteration;
qi->fireAtTime = now + ZT_NAT_T_TACTICAL_ESCALATION_DELAY;
nextDelay = std::min(nextDelay,(unsigned long)ZT_NAT_T_TACTICAL_ESCALATION_DELAY);
}
diff --git a/node/Switch.hpp b/node/Switch.hpp
index 0b748247..e944c843 100644
--- a/node/Switch.hpp
+++ b/node/Switch.hpp
@@ -250,7 +250,7 @@ private:
peer(p),
fireAtTime(ft),
inaddr(a),
- strategyIteration(1) {} // start with 2nd strategy, since first was tried at inception
+ strategyIteration(0) {}
SharedPtr<Peer> peer;
uint64_t fireAtTime;