Update of /cvsroot/spambayes/spambayes/spambayes In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv15971
Modified Files: Tag: CORESVR dnscache.py Log Message: Handful of changes I've been running with for quite awhile. The only truly functional change was to make MinTTL a global and set it to one day. It was set to 0. The other stuff: * print messages to stderr * use "not container" instead of "len(container) > 0" * be a bit less aggressive in our pruning Index: dnscache.py =================================================================== RCS file: /cvsroot/spambayes/spambayes/spambayes/dnscache.py,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -C2 -d -r1.3 -r1.3.2.1 *** dnscache.py 13 Aug 2006 02:05:43 -0000 1.3 --- dnscache.py 24 May 2007 03:14:41 -0000 1.3.2.1 *************** *** 23,29 **** kCheckForPruneEvery=20 ! kMaxTTL=60 * 60 * 24 * 7 # One week ! kPruneThreshold=1500 # May go over slightly; numbers chosen at random ! kPruneDownTo=1000 --- 23,32 ---- kCheckForPruneEvery=20 ! kMaxTTL=60 * 60 * 24 * 7 # One week ! # Some servers always return a TTL of zero. We'll hold onto data a bit ! # longer. ! kMinTTL=24 * 60 * 60 * 1 # one day ! kPruneThreshold=5000 # May go over slightly; numbers chosen at random ! kPruneDownTo=2500 *************** *** 89,97 **** self.dnsTimeout=10 - # Some servers always return a TTL of zero. - # In those cases, turning this up a bit is - # probably reasonable. - self.minTTL=0 - # end of user-settable attributes --- 92,95 ---- *************** *** 160,164 **** c=self.caches[answer.qType] c[answer.question].remove(answer) ! if len(c[answer.question])==0: del c[answer.question] --- 158,162 ---- c=self.caches[answer.qType] c[answer.question].remove(answer) ! if not c[answer.question]: del c[answer.question] *************** *** 180,184 **** c=self.caches[answer.qType] c[answer.question].remove(answer) ! if len(c[answer.question])==0: del c[answer.question] --- 178,182 ---- c=self.caches[answer.qType] c[answer.question].remove(answer) ! if not c[answer.question]: del c[answer.question] *************** *** 218,233 **** pass else: ! assert len(answers)>0 ! ind=0 ! # No guarantee that expire has already been done ! while ind<len(answers): ! thisAnswer=answers[ind] ! if thisAnswer.expiresAt<now: ! del answers[ind] ! else: ! thisAnswer.lastUsed=now ! ind+=1 ! if len(answers)==0: del cacheToLookIn[question] else: --- 216,233 ---- pass else: ! if answers: ! ind=0 ! # No guarantee that expire has already been done ! while ind<len(answers): ! thisAnswer=answers[ind] ! if thisAnswer.expiresAt<now: ! del answers[ind] ! else: ! thisAnswer.lastUsed=now ! ind+=1 ! else: ! print >> sys.stderr, "lookup failure:", question ! if not answers: del cacheToLookIn[question] else: *************** *** 250,275 **** except DNS.Base.DNSError,detail: if detail.args[0]<>"Timeout": ! print "Error, fixme",detail ! print "Question was",queryQuestion ! print "Origianal question was",question ! print "Type was",qType objs=[ lookupResult(qType,None,question,self.cacheErrorSecs+now,now) ] cacheToLookIn[question]=objs # Add to format for return? return self.formatForReturn(objs) except socket.gaierror,detail: ! print "DNS connection failure:", self.queryObj.ns, detail ! print "Defaults:", DNS.defaults objs=[] for answer in reply.answers: if answer["typename"]==qType: ! # PyDNS returns TTLs as longs but RFC 1035 says that the ! # TTL value is a signed 32-bit value and must be positive, ! # so it should be safe to coerce it to a Python integer. ! # And anyone who sets a time to live of more than 2^31-1 ! # seconds (68 years and change) is drunk. ! # Arguably, I ought to impose a maximum rather than continuing ! # with longs (int(long) returns long in recent versions of Python). ! ttl=max(min(int(answer["ttl"]),kMaxTTL),self.minTTL) # RFC 2308 says that you should cache an NXDOMAIN for the # minimum of the minimum field of the SOA record and the TTL --- 250,275 ---- except DNS.Base.DNSError,detail: if detail.args[0]<>"Timeout": ! print >> sys.stderr, "Error, fixme", detail ! print >> sys.stderr, "Question was", queryQuestion ! print >> sys.stderr, "Original question was", question ! print >> sys.stderr, "Type was", qType objs=[ lookupResult(qType,None,question,self.cacheErrorSecs+now,now) ] cacheToLookIn[question]=objs # Add to format for return? return self.formatForReturn(objs) except socket.gaierror,detail: ! print >> sys.stderr, "DNS connection failure:", self.queryObj.ns, detail ! print >> sys.stderr, "Defaults:", DNS.defaults objs=[] for answer in reply.answers: if answer["typename"]==qType: ! # PyDNS returns TTLs as longs but RFC 1035 says that the TTL ! # value is a signed 32-bit value and must be positive, so it ! # should be safe to coerce it to a Python integer. And ! # anyone who sets a time to live of more than 2^31-1 seconds ! # (68 years and change) is drunk. Arguably, I ought to ! # impose a maximum rather than continuing with longs ! # (int(long) returns long in recent versions of Python). ! ttl=max(min(int(answer["ttl"]),kMaxTTL),kMinTTL) # RFC 2308 says that you should cache an NXDOMAIN for the # minimum of the minimum field of the SOA record and the TTL *************** *** 279,288 **** objs.append(item) ! if len(objs)>0: cacheToLookIn[question]=objs return self.formatForReturn(objs) # Probably SERVFAIL or the like ! if len(reply.authority)==0: objs=[ lookupResult(qType,None,question,self.cacheErrorSecs+now,now) ] cacheToLookIn[question]=objs --- 279,288 ---- objs.append(item) ! if objs: cacheToLookIn[question]=objs return self.formatForReturn(objs) # Probably SERVFAIL or the like ! if not reply.authority: objs=[ lookupResult(qType,None,question,self.cacheErrorSecs+now,now) ] cacheToLookIn[question]=objs *************** *** 319,329 **** "www.seeputofor.com", "www.completegarbage.tv", "www.tradelinkllc.com"]: ! print "checking", host now=time.time() ips=c.lookup(host) ! print ips,time.time()-now now=time.time() ips=c.lookup(host) ! print ips,time.time()-now if ips: --- 319,329 ---- "www.seeputofor.com", "www.completegarbage.tv", "www.tradelinkllc.com"]: ! print >> sys.stderr, "checking", host now=time.time() ips=c.lookup(host) ! print >> sys.stderr, ips,time.time()-now now=time.time() ips=c.lookup(host) ! print >> sys.stderr, ips,time.time()-now if ips: *************** *** 331,340 **** now=time.time() name=c.lookup(ip,qType="PTR") ! print name,time.time()-now now=time.time() name=c.lookup(ip,qType="PTR") ! print name,time.time()-now else: ! print "unknown" c.close() --- 331,340 ---- now=time.time() name=c.lookup(ip,qType="PTR") ! print >> sys.stderr, name,time.time()-now now=time.time() name=c.lookup(ip,qType="PTR") ! print >> sys.stderr, name,time.time()-now else: ! print >> sys.stderr, "unknown" c.close() _______________________________________________ Spambayes-checkins mailing list Spambayes-checkins@python.org http://mail.python.org/mailman/listinfo/spambayes-checkins