Clean up some YAGNI issues with implementation of GitHub issue #180, and make best path choice aware of path rank.
This commit is contained in:
parent
0b9524f23d
commit
0b354803f3
11 changed files with 117 additions and 100 deletions
|
@ -161,6 +161,21 @@ void Peer::received(
|
|||
_lastMulticastFrame = now;
|
||||
}
|
||||
|
||||
RemotePath *Peer::getBestPath(uint64_t now)
|
||||
{
|
||||
RemotePath *bestPath = (RemotePath *)0;
|
||||
uint64_t lrMax = 0;
|
||||
int rank = 0;
|
||||
for(unsigned int p=0,np=_numPaths;p<np;++p) {
|
||||
if ( (_paths[p].active(now)) && ((_paths[p].lastReceived() >= lrMax)||(_paths[p].preferenceRank() >= rank)) ) {
|
||||
lrMax = _paths[p].lastReceived();
|
||||
rank = _paths[p].preferenceRank();
|
||||
bestPath = &(_paths[p]);
|
||||
}
|
||||
}
|
||||
return bestPath;
|
||||
}
|
||||
|
||||
void Peer::attemptToContactAt(const RuntimeEnvironment *RR,const InetAddress &atAddress,uint64_t now)
|
||||
{
|
||||
Packet outp(_id.address(),RR->identity.address(),Packet::VERB_HELLO);
|
||||
|
@ -200,7 +215,7 @@ void Peer::doPingAndKeepalive(const RuntimeEnvironment *RR,uint64_t now)
|
|||
TRACE("PING %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
|
||||
attemptToContactAt(RR,bestPath->address(),now);
|
||||
bestPath->sent(now);
|
||||
} else if ((now - bestPath->lastSend()) >= ZT_NAT_KEEPALIVE_DELAY) {
|
||||
} else if (((now - bestPath->lastSend()) >= ZT_NAT_KEEPALIVE_DELAY)&&(!bestPath->reliable())) {
|
||||
TRACE("NAT keepalive %s(%s)",_id.address().toString().c_str(),bestPath->address().toString().c_str());
|
||||
RR->node->putPacket(bestPath->address(),"",0);
|
||||
bestPath->sent(now);
|
||||
|
@ -230,31 +245,24 @@ void Peer::pushDirectPaths(const RuntimeEnvironment *RR,RemotePath *path,uint64_
|
|||
case AF_INET6:
|
||||
addressType = 6;
|
||||
break;
|
||||
default:
|
||||
default: // we currently only push IP addresses
|
||||
++p;
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t flags = 0;
|
||||
if (p->metric() < 0)
|
||||
flags |= (0x01 | 0x02); // forget and blacklist
|
||||
else {
|
||||
if (p->reliable())
|
||||
flags |= 0x04; // no NAT keepalives and such
|
||||
switch(p->trust()) {
|
||||
default:
|
||||
break;
|
||||
case Path::TRUST_PRIVACY:
|
||||
flags |= 0x08; // no encryption
|
||||
break;
|
||||
case Path::TRUST_ULTIMATE:
|
||||
flags |= (0x08 | 0x10); // no encryption, no authentication (redundant but go ahead and set both)
|
||||
break;
|
||||
}
|
||||
switch(p->trust()) {
|
||||
default:
|
||||
break;
|
||||
case Path::TRUST_PRIVACY:
|
||||
flags |= 0x04; // no encryption
|
||||
break;
|
||||
case Path::TRUST_ULTIMATE:
|
||||
flags |= (0x04 | 0x08); // no encryption, no authentication (redundant but go ahead and set both)
|
||||
break;
|
||||
}
|
||||
|
||||
outp.append(flags);
|
||||
outp.append((uint8_t)((p->metric() >= 0) ? ((p->metric() <= 255) ? p->metric() : 255) : 0));
|
||||
outp.append((uint16_t)0); // no extensions
|
||||
outp.append(addressType);
|
||||
outp.append((uint8_t)((addressType == 4) ? 6 : 18));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue