/[straw]/straw/src/lib/LookupManager.py
ViewVC logotype

Diff of /straw/src/lib/LookupManager.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.7 by juri, Mon Sep 1 16:19:54 2003 UTC revision 1.8 by juri, Sat Oct 18 10:33:44 2003 UTC
# Line 11  except ImportError: Line 11  except ImportError:
11      log("No ADNS library found, using synchronous name lookups.")      log("No ADNS library found, using synchronous name lookups.")
12      _have_adns = False      _have_adns = False
13    
14    MAX_TIMES = 3
15    
16  class NameFormatException(Exception):  class NameFormatException(Exception):
17      pass      pass
18    
# Line 39  if _have_adns: Line 41  if _have_adns:
41              self.queryengine.lookup_a_record(name, callback, cbw)              self.queryengine.lookup_a_record(name, callback, cbw)
42    
43          def lookup(self, name, callback, data=None):          def lookup(self, name, callback, data=None):
             cbw = CBWrapper(name, callback, data)  
44              try:              try:
45                  name = name.encode('ascii')                  name = name.encode('ascii')
46              except UnicodeError:              except UnicodeError:
47                  raise NameFormatException, "Host names must be ASCII"                  raise NameFormatException, "Host names must be ASCII"
48                cbw = CBWrapper(name, callback, data)
49              self._lookup(name, self.adns_callback, cbw)              self._lookup(name, self.adns_callback, cbw)
50                    
51          def adns_callback(self, answer, qname, rr, flags, cbwrapper):          def adns_callback(self, answer, qname, rr, flags, cbwrapper):
# Line 58  if _have_adns: Line 60  if _have_adns:
60                  ip = ips[0]                  ip = ips[0]
61                  self.namecache[qname] = (ip, now+random.randint(self.mintime,                  self.namecache[qname] = (ip, now+random.randint(self.mintime,
62                                                                  self.maxtime))                                                                  self.maxtime))
63                else:
64                    # try again
65                    if cbwrapper.times < MAX_TIMES:
66                        cbwrapper.times += 1
67                        self._lookup(cbwrapper.name, self.adns_callback, cbwrapper)
68              cbwrapper.cb(ip)              cbwrapper.cb(ip)
69    
70          def poll(self, timeout=0.1):          def poll(self, timeout=0.1):
71              self.queryengine.run(timeout)              self.queryengine.run(timeout)
72    
73      class CBWrapper:      class CBWrapper:
74          def __init__(self, name, callback, data):          def __init__(self, name, callback, data, times = 0):
75              self.name = name              self.name = name
76              self.data = data              self.data = data
77              self.callback = callback              self.callback = callback
78                self.times = 0
79    
80          def cb(self, ip):          def cb(self, ip):
81              self.callback(self.name, ip, self.data)              self.callback(self.name, ip, self.data)

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26