Skip to content

Commit

Permalink
allow user to override system dnsserver with config.
Browse files Browse the repository at this point in the history
config item:
    dns_server     list

    eg:
        dns_server:[8.8.8.8,8.8.4.4]
  • Loading branch information
李林哲 committed Aug 17, 2015
1 parent eb033a8 commit 0c4f792
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions shadowsocks/asyncdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,19 @@ def __str__(self):

class DNSResolver(object):

def __init__(self):
def __init__(self, server_list=None):
self._loop = None
self._hosts = {}
self._hostname_status = {}
self._hostname_to_cb = {}
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
Expand Down
7 changes: 6 additions & 1 deletion shadowsocks/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 0c4f792

Please sign in to comment.