From 6ed0c28aecc3c6d05c1e92c0e939794899deca87 Mon Sep 17 00:00:00 2001 From: phonedph1 Date: Thu, 11 Jan 2018 15:04:50 +0000 Subject: [PATCH] Use speedOrderCA and be slightly less abusive on the amount of conversions done. --- pdns/syncres.cc | 25 ++++++++----------------- pdns/syncres.hh | 2 +- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 2a1137f7e..67b888228 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1282,43 +1282,34 @@ inline vector SyncRes::shuffleInSpeedOrder(NsSet &tnameservers, const s return rnameservers; } -inline vector SyncRes::shuffleForwardSpeed(vector &nameservers, const string &prefix, const bool wasRd) +inline vector SyncRes::shuffleForwardSpeed(vector &rnameservers, const string &prefix, const bool wasRd) { - vector out_nameservers; - vector rnameservers; - for(const auto& ns:nameservers) { - rnameservers.push_back(DNSName(ns.toStringWithPort())); - } - - map speeds; + map speeds; for(const auto& val: rnameservers) { double speed; - speed=t_sstorage.nsSpeeds[val].get(&d_now); + DNSName nsName = DNSName(val.toStringWithPort()); + speed=t_sstorage.nsSpeeds[nsName].get(&d_now); speeds[val]=speed; } random_shuffle(rnameservers.begin(),rnameservers.end(), dns_random); - speedOrder so(speeds); + speedOrderCA so(speeds); stable_sort(rnameservers.begin(),rnameservers.end(), so); - for(vector::const_iterator i=rnameservers.cbegin();i!=rnameservers.cend();++i) { - out_nameservers.push_back(ComboAddress(i->toStringNoDot())); - } - if(doLog()) { LOG(prefix<<"Nameservers: "); - for(vector::const_iterator i=rnameservers.cbegin();i!=rnameservers.cend();++i) { + for(vector::const_iterator i=rnameservers.cbegin();i!=rnameservers.cend();++i) { if(i!=rnameservers.cbegin()) { LOG(", "); if(!((i-rnameservers.cbegin())%3)) { LOG(endl<toStringNoDot() <<"(" << (boost::format("%0.2f") % (speeds[*i]/1000.0)).str() <<"ms)"); + LOG((wasRd ? string("+") : string("-")) << i->toStringWithPort() <<"(" << (boost::format("%0.2f") % (speeds[*i]/1000.0)).str() <<"ms)"); } LOG(endl); } - return out_nameservers; + return rnameservers; } static uint32_t getRRSIGTTL(const time_t now, const std::shared_ptr& rrsig) diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 89346906a..702c27486 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -739,7 +739,7 @@ private: DNSName getBestNSNamesFromCache(const DNSName &qname, const QType &qtype, NsSet& nsset, bool* flawedNSSet, unsigned int depth, set&beenthere); inline vector shuffleInSpeedOrder(NsSet &nameservers, const string &prefix); - inline vector shuffleForwardSpeed(vector &nameservers, const string &prefix, const bool wasRd); + inline vector shuffleForwardSpeed(vector &rnameservers, const string &prefix, const bool wasRd); bool moreSpecificThan(const DNSName& a, const DNSName &b) const; vector getAddrs(const DNSName &qname, unsigned int depth, set& beenthere, bool cacheOnly); -- 2.40.0