summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-06 15:08:45 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-04-06 15:08:45 -0700
commit197d272287d0e4160f945ce8896560c473a08c0d (patch)
treee51b1b8eb3cb2946ebdf154b83c9a9ec9f2dcfd1
parentbe4683a96d2dfdf8d1b1596281b82b0a43d1f779 (diff)
downloadinfinitytier-197d272287d0e4160f945ce8896560c473a08c0d.tar.gz
infinitytier-197d272287d0e4160f945ce8896560c473a08c0d.zip
More NAT strategy cleanup.
-rw-r--r--node/Switch.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/node/Switch.cpp b/node/Switch.cpp
index 61062c48..f15dd1f6 100644
--- a/node/Switch.cpp
+++ b/node/Switch.cpp
@@ -457,30 +457,27 @@ unsigned long Switch::doTimerTasks()
Packet outp(qi->peer->address(),RR->identity.address(),Packet::VERB_NOP);
outp.armor(qi->peer->key(),false);
- switch(qi->strategyIteration) {
- case 0:
+ switch(qi->strategyIteration++) {
+ case 0: {
// First strategy: rifle method: direct packet to known port
- ++qi->strategyIteration;
RR->node->putPacket(qi->inaddr,outp.data(),outp.size(),qi->currentDesperation);
- break;
+ } break;
case 1: {
// Second strategy: shotgun method up: try a few ports above
- ++qi->strategyIteration;
+ InetAddress tmpaddr(qi->inaddr);
int p = (int)qi->inaddr.port();
for(int i=0;i<9;++i) {
if (++p > 0xffff) break;
- InetAddress tmpaddr(qi->inaddr);
tmpaddr.setPort((unsigned int)p);
RR->node->putPacket(tmpaddr,outp.data(),outp.size(),qi->currentDesperation);
}
} break;
case 2: {
// Third strategy: shotgun method down: try a few ports below
- ++qi->strategyIteration;
+ InetAddress tmpaddr(qi->inaddr);
int p = (int)qi->inaddr.port();
for(int i=0;i<3;++i) {
if (--p < 1024) break;
- InetAddress tmpaddr(qi->inaddr);
tmpaddr.setPort((unsigned int)p);
RR->node->putPacket(tmpaddr,outp.data(),outp.size(),qi->currentDesperation);
}