summaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-26 16:09:56 -0700
committerAdam Ierymenko <adam.ierymenko@gmail.com>2015-10-26 16:09:56 -0700
commit0b82c9ebad55181b9d668498371be84fb5c81b01 (patch)
tree74b545ed449283b0071785dd742e6614e8e778cf /node
parentde761c5a82b7928decf94e93aff4af7adc309e7a (diff)
downloadinfinitytier-0b82c9ebad55181b9d668498371be84fb5c81b01.tar.gz
infinitytier-0b82c9ebad55181b9d668498371be84fb5c81b01.zip
Fix infinite loop if there are no live roots (never happened before?!? wow!)
Diffstat (limited to 'node')
-rw-r--r--node/Topology.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/node/Topology.cpp b/node/Topology.cpp
index ff4b7225..6a72cf8c 100644
--- a/node/Topology.cpp
+++ b/node/Topology.cpp
@@ -202,18 +202,16 @@ SharedPtr<Peer> Topology::getBestRoot(const Address *avoid,unsigned int avoidCou
* circumnavigate the globe rather than bouncing between just two. */
if (_rootAddresses.size() > 1) { // gotta be one other than me for this to work
- std::vector<Address>::const_iterator sna(std::find(_rootAddresses.begin(),_rootAddresses.end(),RR->identity.address()));
- if (sna != _rootAddresses.end()) { // sanity check -- _amRoot should've been false in this case
- for(;;) {
- if (++sna == _rootAddresses.end())
- sna = _rootAddresses.begin(); // wrap around at end
- if (*sna != RR->identity.address()) { // pick one other than us -- starting from me+1 in sorted set order
- SharedPtr<Peer> *p = _peers.get(*sna);
- if ((p)&&((*p)->hasActiveDirectPath(now))) {
- bestRoot = *p;
+ for(unsigned long p=0;p<_rootAddresses.size();++p) {
+ if (_rootAddresses[p] == RR->identity.address()) {
+ for(unsigned long q=1;q<_rootAddresses.size();++q) {
+ SharedPtr<Peer> *nextsn = _peers.get(_rootAddresses[(p + q) % _rootAddresses.size()]);
+ if ((nextsn)&&((*nextsn)->hasActiveDirectPath(now))) {
+ bestRoot = *nextsn;
break;
}
}
+ break;
}
}
}