clowwindy 10 years ago
parent
commit
6efb3d00e4
  1. 13
      shadowsocks/asyncdns.py

13
shadowsocks/asyncdns.py

@ -93,11 +93,12 @@ def build_address(address):
return b''.join(results) return b''.join(results)
def build_request(address, qtype, request_id): def build_request(address, qtype):
header = struct.pack('!HBBHHHH', request_id, 1, 0, 1, 0, 0, 0) request_id = os.urandom(2)
header = struct.pack('!BBHHHH', 1, 0, 1, 0, 0, 0)
addr = build_address(address) addr = build_address(address)
qtype_qclass = struct.pack('!HH', qtype, QCLASS_IN) qtype_qclass = struct.pack('!HH', qtype, QCLASS_IN)
return header + addr + qtype_qclass return request_id + header + addr + qtype_qclass
def parse_ip(addrtype, data, length, offset): def parse_ip(addrtype, data, length, offset):
@ -270,7 +271,6 @@ class DNSResolver(object):
def __init__(self): def __init__(self):
self._loop = None self._loop = None
self._request_id = 1
self._hosts = {} self._hosts = {}
self._hostname_status = {} self._hostname_status = {}
self._hostname_to_cb = {} self._hostname_to_cb = {}
@ -412,10 +412,7 @@ class DNSResolver(object):
del self._hostname_status[hostname] del self._hostname_status[hostname]
def _send_req(self, hostname, qtype): def _send_req(self, hostname, qtype):
self._request_id += 1 req = build_request(hostname, qtype)
if self._request_id > 32768:
self._request_id = 1
req = build_request(hostname, qtype, self._request_id)
for server in self._servers: for server in self._servers:
logging.debug('resolving %s with type %d using server %s', logging.debug('resolving %s with type %d using server %s',
hostname, qtype, server) hostname, qtype, server)

Loading…
Cancel
Save