Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Jan 16, 2015
1 parent 1341326 commit 6efb3d0
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions shadowsocks/asyncdns.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ def build_address(address):
return b''.join(results)


def build_request(address, qtype, request_id):
header = struct.pack('!HBBHHHH', request_id, 1, 0, 1, 0, 0, 0)
def build_request(address, qtype):
request_id = os.urandom(2)
header = struct.pack('!BBHHHH', 1, 0, 1, 0, 0, 0)
addr = build_address(address)
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):
Expand Down Expand Up @@ -270,7 +271,6 @@ class DNSResolver(object):

def __init__(self):
self._loop = None
self._request_id = 1
self._hosts = {}
self._hostname_status = {}
self._hostname_to_cb = {}
Expand Down Expand Up @@ -412,10 +412,7 @@ def remove_callback(self, callback):
del self._hostname_status[hostname]

def _send_req(self, hostname, qtype):
self._request_id += 1
if self._request_id > 32768:
self._request_id = 1
req = build_request(hostname, qtype, self._request_id)
req = build_request(hostname, qtype)
for server in self._servers:
logging.debug('resolving %s with type %d using server %s',
hostname, qtype, server)
Expand Down

0 comments on commit 6efb3d0

Please sign in to comment.