diff options
Diffstat (limited to 'node/Topology.cpp')
| -rw-r--r-- | node/Topology.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/node/Topology.cpp b/node/Topology.cpp index 6a72cf8c..49854f0e 100644 --- a/node/Topology.cpp +++ b/node/Topology.cpp @@ -215,10 +215,45 @@ 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. */ + unsigned int bestLatencyOverall = ~((unsigned int)0); + unsigned int bestLatencyNotAvoid = ~((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); + } + } + } + + if (bestNotAvoid) + return *bestNotAvoid; + else if ((!strictAvoid)&&(bestOverall)) + return *bestOverall; + return SharedPtr<Peer>(); + + /* unsigned int l,bestLatency = 65536; uint64_t lds,ldr; @@ -278,6 +313,7 @@ keep_searching_for_roots: } } } + */ } if (bestRoot) |
