allow user to override system dnsserver with config.

config item:
    dns_server     list

    eg:
        dns_server:[8.8.8.8,8.8.4.4]
This commit is contained in:
李林哲 2015-05-11 09:32:40 +08:00
parent eb033a8f6a
commit 0c4f79284e
2 changed files with 12 additions and 4 deletions

View file

@ -248,7 +248,7 @@ STATUS_IPV6 = 1
class DNSResolver(object):
def __init__(self):
def __init__(self, server_list=None):
self._loop = None
self._hosts = {}
self._hostname_status = {}
@ -256,8 +256,11 @@ class DNSResolver(object):
self._cb_to_hostname = {}
self._cache = lru_cache.LRUCache(timeout=300)
self._sock = None
self._servers = None
self._parse_resolv()
if server_list is None:
self._servers = None
self._parse_resolv()
else:
self._servers = server_list
self._parse_hosts()
# TODO monitor hosts change and reload hosts
# TODO parse /etc/gai.conf and follow its rules

View file

@ -57,7 +57,12 @@ def main():
tcp_servers = []
udp_servers = []
dns_resolver = asyncdns.DNSResolver()
if 'dns_server' in config: # allow override settings in resolv.conf
dns_resolver = asyncdns.DNSResolver(config['dns_server'])
else:
dns_resolver = asyncdns.DNSResolver()
port_password = config['port_password']
del config['port_password']
for port, password in port_password.items():