Merge pull request #335 from slayercat/master
allow user to override system dnsserver with config.
This commit is contained in:
commit
e52aa9db0c
4 changed files with 24 additions and 4 deletions
|
@ -248,7 +248,7 @@ STATUS_IPV6 = 1
|
||||||
|
|
||||||
class DNSResolver(object):
|
class DNSResolver(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, server_list=None):
|
||||||
self._loop = None
|
self._loop = None
|
||||||
self._hosts = {}
|
self._hosts = {}
|
||||||
self._hostname_status = {}
|
self._hostname_status = {}
|
||||||
|
@ -256,8 +256,11 @@ class DNSResolver(object):
|
||||||
self._cb_to_hostname = {}
|
self._cb_to_hostname = {}
|
||||||
self._cache = lru_cache.LRUCache(timeout=300)
|
self._cache = lru_cache.LRUCache(timeout=300)
|
||||||
self._sock = None
|
self._sock = None
|
||||||
self._servers = None
|
if server_list is None:
|
||||||
self._parse_resolv()
|
self._servers = None
|
||||||
|
self._parse_resolv()
|
||||||
|
else:
|
||||||
|
self._servers = server_list
|
||||||
self._parse_hosts()
|
self._parse_hosts()
|
||||||
# TODO monitor hosts change and reload hosts
|
# TODO monitor hosts change and reload hosts
|
||||||
# TODO parse /etc/gai.conf and follow its rules
|
# TODO parse /etc/gai.conf and follow its rules
|
||||||
|
|
|
@ -57,7 +57,12 @@ def main():
|
||||||
|
|
||||||
tcp_servers = []
|
tcp_servers = []
|
||||||
udp_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']
|
port_password = config['port_password']
|
||||||
del config['port_password']
|
del config['port_password']
|
||||||
for port, password in port_password.items():
|
for port, password in port_password.items():
|
||||||
|
|
|
@ -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/table.json
|
||||||
run_test python tests/test.py --with-coverage -c tests/server-multi-ports.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/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 -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 -c tests/workers.json
|
||||||
run_test python tests/test.py --with-coverage -s tests/ipv6.json -c tests/ipv6-client-side.json
|
run_test python tests/test.py --with-coverage -s tests/ipv6.json -c tests/ipv6-client-side.json
|
||||||
|
|
11
tests/server-dnsserver.json
Normal file
11
tests/server-dnsserver.json
Normal file
|
@ -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"]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue