Make root and relay selection somewhat more robust.
This commit is contained in:
parent
00dcb0f22c
commit
4e9d430476
3 changed files with 44 additions and 26 deletions
|
@ -227,33 +227,30 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
|
|||
|
||||
} else {
|
||||
/* If I am not a root server, the best root server is the active one with
|
||||
* the lowest latency. */
|
||||
* the lowest quality score. (lower == better) */
|
||||
|
||||
unsigned int bestLatencyOverall = ~((unsigned int)0);
|
||||
unsigned int bestLatencyNotAvoid = ~((unsigned int)0);
|
||||
unsigned int bestQualityOverall = ~((unsigned int)0);
|
||||
unsigned int bestQualityNotAvoid = ~((unsigned int)0);
|
||||
const SharedPtr<Peer> *bestOverall = (const SharedPtr<Peer> *)0;
|
||||
const SharedPtr<Peer> *bestNotAvoid = (const SharedPtr<Peer> *)0;
|
||||
|
||||
for(std::vector< SharedPtr<Peer> >::const_iterator r(_rootPeers.begin());r!=_rootPeers.end();++r) {
|
||||
if ((*r)->hasActiveDirectPath(now)) {
|
||||
bool avoiding = false;
|
||||
for(unsigned int i=0;i<avoidCount;++i) {
|
||||
if (avoid[i] == (*r)->address()) {
|
||||
avoiding = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unsigned int l = (*r)->latency();
|
||||
if (!l) l = ~l; // zero latency indicates no measurment, so make this 'max'
|
||||
if (l <= bestLatencyOverall) {
|
||||
bestLatencyOverall = l;
|
||||
bestOverall = &(*r);
|
||||
}
|
||||
if ((!avoiding)&&(l <= bestLatencyNotAvoid)) {
|
||||
bestLatencyNotAvoid = l;
|
||||
bestNotAvoid = &(*r);
|
||||
bool avoiding = false;
|
||||
for(unsigned int i=0;i<avoidCount;++i) {
|
||||
if (avoid[i] == (*r)->address()) {
|
||||
avoiding = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
const unsigned int q = (*r)->relayQuality(now);
|
||||
if (q <= bestQualityOverall) {
|
||||
bestQualityOverall = q;
|
||||
bestOverall = &(*r);
|
||||
}
|
||||
if ((!avoiding)&&(q <= bestQualityNotAvoid)) {
|
||||
bestQualityNotAvoid = q;
|
||||
bestNotAvoid = &(*r);
|
||||
}
|
||||
}
|
||||
|
||||
if (bestNotAvoid) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue