More root cleanup.

This commit is contained in:
Adam Ierymenko 2015-10-27 10:40:31 -07:00
parent 8a7a0b6b88
commit 17e7528e2c

View File

@ -191,7 +191,6 @@ void Topology::saveIdentity(const Identity &id)
SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCount,bool strictAvoid) SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCount,bool strictAvoid)
{ {
SharedPtr<Peer> bestRoot;
const uint64_t now = RR->node->now(); const uint64_t now = RR->node->now();
Mutex::Lock _l(_lock); Mutex::Lock _l(_lock);
@ -207,8 +206,8 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
for(unsigned long q=1;q<_rootAddresses.size();++q) { for(unsigned long q=1;q<_rootAddresses.size();++q) {
SharedPtr<Peer> *nextsn = _peers.get(_rootAddresses[(p + q) % _rootAddresses.size()]); SharedPtr<Peer> *nextsn = _peers.get(_rootAddresses[(p + q) % _rootAddresses.size()]);
if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) { if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) {
bestRoot = *nextsn; (*nextsn)->use(now);
break; return *nextsn;
} }
} }
break; break;
@ -247,11 +246,13 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
} }
} }
if (bestNotAvoid) if (bestNotAvoid) {
(*bestNotAvoid)->use(now);
return *bestNotAvoid; return *bestNotAvoid;
else if ((!strictAvoid)&&(bestOverall)) } else if ((!strictAvoid)&&(bestOverall)) {
(*bestOverall)->use(now);
return *bestOverall; return *bestOverall;
return SharedPtr<Peer>(); }
/* /*
unsigned int l,bestLatency = 65536; unsigned int l,bestLatency = 65536;
@ -315,10 +316,7 @@ keep_searching_for_roots:
} }
*/ */
} }
return SharedPtr<Peer>();
if (bestRoot)
bestRoot->use(now);
return bestRoot;
} }
bool Topology::isUpstream(const Identity &id) const bool Topology::isUpstream(const Identity &id) const