Commit f8818c07 authored by Sam Rushing's avatar Sam Rushing

resolver interface for coro.socket

parent 05f45e9f
......@@ -834,9 +834,12 @@ class dns_cache:
del self.cache[key]
def permute (x):
x0 = list (x)
random.shuffle (x0)
return x0
if len(x) == 1:
return x
else:
x0 = list (x)
random.shuffle (x0)
return x0
import coro
import coro.dns
......@@ -856,6 +859,24 @@ set_seed (os.urandom (128))
if not coro.has_ipv6():
root_hints = [ x for x in root_hints if not ':' in x ]
class resolver:
def __init__ (self):
self.cache = dns_cache()
def gethostbyname (self, name, qtype):
for ttl, addr in permute (self.cache.query (name, qtype)):
return addr
def resolve_ipv4 (self, name):
return self.gethostbyname (name, 'A')
def resolve_ipv6 (self, name):
return self.gethostbyname (name, 'AAAA')
def install():
"install the builtin resolver into the coro socket layer"
coro.set_resolver (resolver())
# emulate 'statsmon' module
class StaticCounter:
def __init__ (self, name):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment