From 2d1eeb5c85c0f393c1d29a8c47bb7e71ab886bb2 Mon Sep 17 00:00:00 2001 From: Akkariiin Date: Sat, 29 Jul 2017 04:58:07 +0800 Subject: [PATCH] update DNSResolver black_hostname_list --- shadowsocks/asyncdns.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/shadowsocks/asyncdns.py b/shadowsocks/asyncdns.py index 899fec9..316c6d1 100644 --- a/shadowsocks/asyncdns.py +++ b/shadowsocks/asyncdns.py @@ -476,8 +476,8 @@ class DNSResolver(object): logging.debug('hit cache: %s', hostname) ip = self._cache[hostname] callback((hostname, ip), None) - elif hostname in self._black_hostname_list: - callback(None, Exception('hostname <%s> in the black hostname list' % hostname)) + elif any(hostname.endswith(t) for t in self._black_hostname_list): + callback(None, Exception('hostname <%s> is block by the black hostname list' % hostname)) return else: if not is_valid_hostname(hostname): @@ -521,7 +521,8 @@ class DNSResolver(object): def test(): black_hostname_list = [ - 'baidu.com' + 'baidu.com', + 'yahoo.com', ] dns_resolver = DNSResolver(black_hostname_list=black_hostname_list) loop = eventloop.EventLoop() @@ -538,7 +539,7 @@ def test(): # TODO: what can we assert? print(result, error) counter += 1 - if counter == 9: + if counter == 12: dns_resolver.close() loop.stop() @@ -550,6 +551,8 @@ def test(): dns_resolver.resolve(b'google.com', make_callback()) dns_resolver.resolve('google.com', make_callback()) dns_resolver.resolve('baidu.com', make_callback()) + dns_resolver.resolve('map.baidu.com', make_callback()) + dns_resolver.resolve('yahoo.com', make_callback()) dns_resolver.resolve('example.com', make_callback()) dns_resolver.resolve('ipv6.google.com', make_callback()) dns_resolver.resolve('www.facebook.com', make_callback())