From 9aee72099e518636acb243237042049c50dcf483 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 6 Jan 2016 10:59:39 -0800 Subject: [PATCH] AntiRecursion cleanup and some other minor things. --- node/AntiRecursion.hpp | 6 ++++-- node/Path.cpp | 2 +- node/Peer.cpp | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/node/AntiRecursion.hpp b/node/AntiRecursion.hpp index 4d9df465c..78ee95c2b 100644 --- a/node/AntiRecursion.hpp +++ b/node/AntiRecursion.hpp @@ -105,8 +105,9 @@ public: const _ArItem *const end = i + ZT_ANTIRECURSION_HISTORY_SIZE; while (i != end) { #ifdef ZT_NO_TYPE_PUNNING - if (!memcmp(pp,i->tail,32)) + if (!memcmp(pp,i->tail,32)) { return false; + } #else const uint64_t *t = i->tail; const uint64_t *p = reinterpret_cast(pp); @@ -114,8 +115,9 @@ public: bits |= *(t++) ^ *(p++); bits |= *(t++) ^ *(p++); bits |= *t ^ *p; - if (!bits) + if (!bits) { return false; + } #endif ++i; } diff --git a/node/Path.cpp b/node/Path.cpp index e2475751c..c67352de8 100644 --- a/node/Path.cpp +++ b/node/Path.cpp @@ -34,9 +34,9 @@ namespace ZeroTier { bool Path::send(const RuntimeEnvironment *RR,const void *data,unsigned int len,uint64_t now) { + RR->antiRec->logOutgoingZT(data,len); if (RR->node->putPacket(_localAddress,address(),data,len)) { sent(now); - RR->antiRec->logOutgoingZT(data,len); return true; } return false; diff --git a/node/Peer.cpp b/node/Peer.cpp index aff610d52..1914da971 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -253,7 +253,7 @@ bool Peer::doPingAndKeepalive(uint64_t now,int inetAddressFamily) sendHELLO(p->localAddress(),p->address(),now); p->sent(now); p->pinged(now); - } else if (((now - std::max(p->lastSend(),p->lastKeepalive())) >= ZT_NAT_KEEPALIVE_DELAY)&&(!p->reliable())) { + } else if ( ((now - std::max(p->lastSend(),p->lastKeepalive())) >= ZT_NAT_KEEPALIVE_DELAY) && (!p->reliable()) ) { //TRACE("NAT keepalive %s(%s) after %llums/%llums send/receive inactivity",_id.address().toString().c_str(),p->address().toString().c_str(),now - p->lastSend(),now - p->lastReceived()); _natKeepaliveBuf += (uint32_t)((now * 0x9e3779b1) >> 1); // tumble this around to send constantly varying (meaningless) payloads RR->node->putPacket(p->localAddress(),p->address(),&_natKeepaliveBuf,sizeof(_natKeepaliveBuf)); @@ -513,7 +513,7 @@ bool Peer::_checkPath(Path &p,const uint64_t now) * MAX_PROBATION threshold the path is considred dead. */ if ( (p.lastSend() > p.lastReceived()) && ((p.lastSend() - p.lastReceived()) >= ZT_PEER_DEAD_PATH_DETECTION_NO_ANSWER_TIMEOUT) && ((now - p.lastPing()) >= ZT_PEER_DEAD_PATH_DETECTION_NO_ANSWER_TIMEOUT) ) { - TRACE("%s(%s) has not answered, checking if dead (probation: %u)",_id.address().toString().c_str(),p.address().toString().c_str(),p.probation()); + TRACE("%s(%s) does not seem to be answering in a timely manner, checking if dead (probation == %u)",_id.address().toString().c_str(),p.address().toString().c_str(),p.probation()); if ( (_vProto >= 5) && ( !((_vMajor == 1)&&(_vMinor == 1)&&(_vRevision == 0)) ) ) { // 1.1.1 and newer nodes support ECHO, which is smaller -- but 1.1.0 has a bug so use HELLO there too