diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-07 19:31:11 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-04-07 19:31:11 -0700 |
| commit | 49f031ccb4d518e8a715777f5d848759bae0def8 (patch) | |
| tree | 6f5d2fe9a753d36ac1da657142fc50645804466d /node/Peer.cpp | |
| parent | 9e55f882d3ca5a5615c21ebaec0702aaaf436e2b (diff) | |
| download | infinitytier-49f031ccb4d518e8a715777f5d848759bae0def8.tar.gz infinitytier-49f031ccb4d518e8a715777f5d848759bae0def8.zip | |
Tons of refactoring, change to desperation algorithm to use max of core or link, porting over core loop code from old Node.cpp to new CAPI version, etc.
Diffstat (limited to 'node/Peer.cpp')
| -rw-r--r-- | node/Peer.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/node/Peer.cpp b/node/Peer.cpp index ea94fd9e..e66722e8 100644 --- a/node/Peer.cpp +++ b/node/Peer.cpp @@ -187,6 +187,24 @@ void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &at RR->node->putPacket(atAddress,outp.data(),outp.size(),linkDesperation); } +void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now) +{ + Path *const bestPath = getBestPath(now); + if ((bestPath)&&(bestPath->active(now))) { + if ((now - bestPath->lastReceived()) >= ZT_PEER_DIRECT_PING_DELAY) { + attemptToContactAt(RR,bestPath->address(),bestPath->desperation(now),now); + bestPath->sent(now); + } else if ((now - bestPath->lastSend()) >= ZT_NAT_KEEPALIVE_DELAY) { + // We only do keepalive if desperation is zero right now, since higher + // desperation paths involve things like tunneling that do not need it. + if (bestPath->desperation() == 0) { + RR->node->putPacket(_paths[p].address(),"",0,0); + bestPath->sent(now); + } + } + } +} + void Peer::addPath(const Path &newp) { unsigned int np = _numPaths; |
