]> granicus.if.org Git - pdns/commitdiff
remove some more time(0) calls
authorBert Hubert <bert.hubert@netherlabs.nl>
Fri, 18 Feb 2005 23:52:08 +0000 (23:52 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Fri, 18 Feb 2005 23:52:08 +0000 (23:52 +0000)
remove outdated and #ifdeffed code
s/ogg/off/

git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@324 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/pdns_recursor.cc
pdns/syncres.cc
pdns/syncres.hh

index 8a7cbd1c9138b9081951b9c7646c7bd70f800bcb..499f8c75a7dc76abe7475a5ea766a696fcc53b68 100644 (file)
@@ -406,7 +406,7 @@ int main(int argc, char **argv)
     Utility::srandom(time(0));
     arg().set("soa-minimum-ttl","Don't change")="0";
     arg().set("soa-serial-offset","Don't change")="0";
-    arg().set("no-shuffle","Don't change")="ogg";
+    arg().set("no-shuffle","Don't change")="off";
     arg().set("aaaa-additional-processing","turn on to do AAAA additional processing (slow)")="off";
     arg().set("local-port","port to listen on")="53";
     arg().set("local-address","single address to listen on")="0.0.0.0";
index e9bcd66a8d97304ee38a2fcb904a71b190e20d7e..20e900eba4ce15d80a65e8d38d29684d2ffa6663 100644 (file)
@@ -376,7 +376,7 @@ int SyncRes::doResolveAt(set<string> nameservers, string auth, const string &qna
       }
       LOG<<prefix<<qname<<": Resolved '"+auth+"' NS "<<*tns<<" to "<<remoteIP<<", asking '"<<qname<<"|"<<qtype.getName()<<"'"<<endl;
 
-      if(s_throttle.shouldThrottle(remoteIP+"|"+qname+"|"+qtype.getName())) {
+      if(s_throttle.shouldThrottle(d_now, remoteIP+"|"+qname+"|"+qtype.getName())) {
        LOG<<prefix<<qname<<": query throttled "<<endl;
        s_throttledqueries++;
        d_throttledqueries++;
@@ -389,7 +389,7 @@ int SyncRes::doResolveAt(set<string> nameservers, string auth, const string &qna
          LOG<<prefix<<qname<<": error resolving (perhaps timeout?)"<<endl;
          nsSpeeds[toLower(*tns)].submit(1000000); // 1 sec
          d_timeouts++;
-         s_throttle.throttle(remoteIP+"|"+qname+"|"+qtype.getName(),20,5);
+         s_throttle.throttle(d_now, remoteIP+"|"+qname+"|"+qtype.getName(),20,5);
          continue;
        }
        d_now=time(0);
@@ -398,7 +398,7 @@ int SyncRes::doResolveAt(set<string> nameservers, string auth, const string &qna
       result=d_lwr.result();
       if(d_lwr.d_rcode==RCode::ServFail) {
        LOG<<prefix<<qname<<": "<<*tns<<" returned a ServFail, trying sibling NS"<<endl;
-       s_throttle.throttle(remoteIP+"|"+qname+"|"+qtype.getName(),60,3);
+       s_throttle.throttle(d_now,remoteIP+"|"+qname+"|"+qtype.getName(),60,3);
        continue;
       }
       LOG<<prefix<<qname<<": Got "<<result.size()<<" answers from "<<*tns<<" ("<<remoteIP<<"), rcode="<<d_lwr.d_rcode<<", in "<<d_lwr.d_usec/1000<<"ms"<<endl;
@@ -533,7 +533,7 @@ int SyncRes::doResolveAt(set<string> nameservers, string auth, const string &qna
       }
       else {
        LOG<<prefix<<qname<<": status=NS "<<*tns<<" is lame for '"<<auth<<"', trying sibling NS"<<endl;
-       s_throttle.throttle(remoteIP+"|"+qname+"|"+qtype.getName(),60,0);
+       s_throttle.throttle(d_now, remoteIP+"|"+qname+"|"+qtype.getName(),60,0);
       }
     }
   }
index 5fa9b28f6640882a092ba93b3f35d7f790b6d02b..ae89f77eee945c1c85ceef83eed6e026be79c16f 100644 (file)
@@ -33,9 +33,8 @@ public:
     d_ttl=60;
     d_last_clean=time(0);
   }
-  bool shouldThrottle(const Thing& t)
+  bool shouldThrottle(time_t now, const Thing& t)
   {
-    time_t now=time(0);
     if(now > d_last_clean + 60 ) {
       d_last_clean=now;
       for(typename cont_t::iterator i=d_cont.begin();i!=d_cont.end();) 
@@ -46,8 +45,6 @@ public:
          ++i;
     }
 
-      
-
     typename cont_t::iterator i=d_cont.find(t);
     if(i==d_cont.end())
       return false;
@@ -56,10 +53,10 @@ public:
       return true;
     }
   }
-  void throttle(const Thing& t, unsigned int ttl=0, unsigned int tries=0) 
+  void throttle(time_t now, const Thing& t, unsigned int ttl=0, unsigned int tries=0) 
   {
     typename cont_t::iterator i=d_cont.find(t);
-    entry e={ time_t(0)+(ttl ? ttl : d_ttl), tries ? tries : d_limit};
+    entry e={ now+(ttl ? ttl : d_ttl), tries ? tries : d_limit};
 
     if(i==d_cont.end()) {
       d_cont[t]=e;
@@ -82,51 +79,6 @@ private:
 };
 
 
-#if 0
-
-template<class Thing> class Throttle
-{
-public:
-  Throttle()
-  {
-    d_limit=3;
-    d_ttl=60;
-  }
-  bool shouldThrottle(const Thing& t)
-  {
-    time_t now=time(0);
-    while(!d_dq.empty() && d_dq.back().ttd < now) // remove expired entries from the end
-      d_dq.pop_back();
-
-    for(typename cont_t::iterator i=d_dq.begin();i!=d_dq.end();++i) 
-      if(i->T==t && i->count-- < 0)
-       return true; 
-    return false;
-  }
-
-  void throttle(const Thing& t, unsigned int ttl=0, unsigned int tries=0) 
-  {
-    entry e;
-    e.ttd=time(0)+ (ttl ? ttl : d_ttl) ; 
-    e.T=t; 
-    e.count=tries ? tries : d_limit;
-    d_dq.push_front(e);
-
-  }
-private:
-  int d_limit;
-  int d_ttl;
-  struct entry 
-  {
-    time_t ttd;
-    Thing T;
-    int count;
-  };
-  typedef deque<entry> cont_t;
-  cont_t d_dq;
-};
-#endif
-
 /** Class that implements a decaying EWMA.
     This class keeps an exponentially weighted moving average which, additionally, decays over time.
     The decaying is only done on get.