diff options
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; |
