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.

This commit is contained in:
Adam Ierymenko 2015-04-07 19:31:11 -07:00
parent 9e55f882d3
commit 49f031ccb4
14 changed files with 277 additions and 254 deletions

View file

@ -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;