Skip to content

Commit 6efb3d0

Browse files
committedJan 16, 2015
fix #264
1 parent 1341326 commit 6efb3d0

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed
 

‎shadowsocks/asyncdns.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@ def build_address(address):
9393
return b''.join(results)
9494

9595

96-
def build_request(address, qtype, request_id):
97-
header = struct.pack('!HBBHHHH', request_id, 1, 0, 1, 0, 0, 0)
96+
def build_request(address, qtype):
97+
request_id = os.urandom(2)
98+
header = struct.pack('!BBHHHH', 1, 0, 1, 0, 0, 0)
9899
addr = build_address(address)
99100
qtype_qclass = struct.pack('!HH', qtype, QCLASS_IN)
100-
return header + addr + qtype_qclass
101+
return request_id + header + addr + qtype_qclass
101102

102103

103104
def parse_ip(addrtype, data, length, offset):
@@ -270,7 +271,6 @@ class DNSResolver(object):
270271

271272
def __init__(self):
272273
self._loop = None
273-
self._request_id = 1
274274
self._hosts = {}
275275
self._hostname_status = {}
276276
self._hostname_to_cb = {}
@@ -412,10 +412,7 @@ def remove_callback(self, callback):
412412
del self._hostname_status[hostname]
413413

414414
def _send_req(self, hostname, qtype):
415-
self._request_id += 1
416-
if self._request_id > 32768:
417-
self._request_id = 1
418-
req = build_request(hostname, qtype, self._request_id)
415+
req = build_request(hostname, qtype)
419416
for server in self._servers:
420417
logging.debug('resolving %s with type %d using server %s',
421418
hostname, qtype, server)

0 commit comments

Comments
 (0)