Skip to content

Commit

Permalink
Merge pull request shadowsocks#335 from slayercat/master
Browse files Browse the repository at this point in the history
allow user to override system dnsserver with config.
  • Loading branch information
clowwindy committed Aug 17, 2015
2 parents eb033a8 + ffed9b2 commit e52aa9d
Show file tree
Hide file tree
Showing 4 changed files with 24 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
1 change: 1 addition & 0 deletions tests/jenkins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ run_test python tests/test.py --with-coverage -c tests/chacha20.json
run_test python tests/test.py --with-coverage -c tests/table.json
run_test python tests/test.py --with-coverage -c tests/server-multi-ports.json
run_test python tests/test.py --with-coverage -s tests/aes.json -c tests/client-multi-server-ip.json
run_test python tests/test.py --with-coverage -s tests/server-dnsserver.json -c tests/client-multi-server-ip.json
run_test python tests/test.py --with-coverage -s tests/server-multi-passwd.json -c tests/server-multi-passwd-client-side.json
run_test python tests/test.py --with-coverage -c tests/workers.json
run_test python tests/test.py --with-coverage -s tests/ipv6.json -c tests/ipv6-client-side.json
Expand Down
11 changes: 11 additions & 0 deletions tests/server-dnsserver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"server":"127.0.0.1",
"server_port":8388,
"local_port":1081,
"password":"aes_password",
"timeout":60,
"method":"aes-256-cfb",
"local_address":"127.0.0.1",
"fast_open":false,
"dns_server": ["8.8.8.8","8.8.4.4"]
}

0 comments on commit e52aa9d

Please sign in to comment.