Browse Source

fix bugs

dns working in both v4 & v6
connecting problem in windows
dev
BreakWa11 9 years ago
parent
commit
e6d7a12afe
  1. 41
      shadowsocks/asyncdns.py
  2. 3
      shadowsocks/obfsplugin/http_simple.py
  3. 4
      shadowsocks/tcprelay.py
  4. 3
      shadowsocks/udprelay.py

41
shadowsocks/asyncdns.py

@ -83,9 +83,11 @@ def detect_ipv6_supprot():
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
try: try:
s.connect(('ipv6.google.com', 0)) s.connect(('ipv6.google.com', 0))
print('IPv6 support')
return True return True
except: except:
pass pass
print('IPv6 not support')
return False return False
IPV6_CONNECTION_SUPPORT = detect_ipv6_supprot() IPV6_CONNECTION_SUPPORT = detect_ipv6_supprot()
@ -356,19 +358,34 @@ class DNSResolver(object):
answer[2] == QCLASS_IN: answer[2] == QCLASS_IN:
ip = answer[0] ip = answer[0]
break break
if not ip and self._hostname_status.get(hostname, STATUS_IPV4) \ if IPV6_CONNECTION_SUPPORT:
== STATUS_IPV6: if not ip and self._hostname_status.get(hostname, STATUS_IPV4) \
self._hostname_status[hostname] = STATUS_IPV4 == STATUS_IPV6:
self._send_req(hostname, QTYPE_A) self._hostname_status[hostname] = STATUS_IPV4
self._send_req(hostname, QTYPE_A)
else:
if ip:
self._cache[hostname] = ip
self._call_callback(hostname, ip)
elif self._hostname_status.get(hostname, None) == STATUS_IPV4:
for question in response.questions:
if question[1] == QTYPE_A:
self._call_callback(hostname, None)
break
else: else:
if ip: if not ip and self._hostname_status.get(hostname, STATUS_IPV6) \
self._cache[hostname] = ip == STATUS_IPV4:
self._call_callback(hostname, ip) self._hostname_status[hostname] = STATUS_IPV6
elif self._hostname_status.get(hostname, None) == STATUS_IPV4: self._send_req(hostname, QTYPE_AAAA)
for question in response.questions: else:
if question[1] == QTYPE_A: if ip:
self._call_callback(hostname, None) self._cache[hostname] = ip
break self._call_callback(hostname, ip)
elif self._hostname_status.get(hostname, None) == STATUS_IPV6:
for question in response.questions:
if question[1] == QTYPE_AAAA:
self._call_callback(hostname, None)
break
def handle_event(self, sock, fd, event): def handle_event(self, sock, fd, event):
if sock != self._sock: if sock != self._sock:

3
shadowsocks/obfsplugin/http_simple.py

@ -192,6 +192,9 @@ class http2_simple(plain.plain):
return buf return buf
self.send_buffer += buf self.send_buffer += buf
if not self.has_sent_header: if not self.has_sent_header:
port = b''
if self.server_info.port != 80:
port = b':' + common.to_bytes(str(self.server_info.port))
self.has_sent_header = True self.has_sent_header = True
http_head = b"GET / HTTP/1.1\r\n" http_head = b"GET / HTTP/1.1\r\n"
http_head += b"Host: " + (self.server_info.param or self.server_info.host) + port + b"\r\n" http_head += b"Host: " + (self.server_info.param or self.server_info.host) + port + b"\r\n"

4
shadowsocks/tcprelay.py

@ -523,8 +523,8 @@ class TCPRelayHandler(object):
try: try:
remote_sock.connect((remote_addr, remote_port)) remote_sock.connect((remote_addr, remote_port))
except (OSError, IOError) as e: except (OSError, IOError) as e:
if eventloop.errno_from_exception(e) == \ if eventloop.errno_from_exception(e) in (errno.EINPROGRESS,
errno.EINPROGRESS: errno.EWOULDBLOCK):
pass # always goto here pass # always goto here
else: else:
raise e raise e

3
shadowsocks/udprelay.py

@ -207,7 +207,7 @@ class RecvQueue(object):
def set_end(self, end_id): def set_end(self, end_id):
if end_id > self.end_id: if end_id > self.end_id:
eid = self.end_id eid = self.end_id
while eid < pack_id: while eid < end_id:
self.miss_queue.add(eid) self.miss_queue.add(eid)
eid += 1 eid += 1
self.end_id = end_id self.end_id = end_id
@ -623,6 +623,7 @@ class TCPRelayHandler(object):
for pid in missing: for pid in missing:
data += struct.pack(">H", pid) data += struct.pack(">H", pid)
rsp_data = self._pack_post_data(CMD_SYN_STATUS, pack_id, data) rsp_data = self._pack_post_data(CMD_SYN_STATUS, pack_id, data)
addr = self.get_local_address()
self._write_to_sock(rsp_data, self._local_sock, addr) self._write_to_sock(rsp_data, self._local_sock, addr)
def handle_stream_sync_status(self, addr, cmd, request_id, pack_id, max_send_id, data): def handle_stream_sync_status(self, addr, cmd, request_id, pack_id, max_send_id, data):

Loading…
Cancel
Save