Browse Source

refine recv size

try more data_size_list
dev
破娃酱 7 years ago
parent
commit
cb1dcacd4b
  1. 13
      shadowsocks/obfsplugin/auth_chain.py
  2. 6
      shadowsocks/tcprelay.py

13
shadowsocks/obfsplugin/auth_chain.py

@ -640,16 +640,22 @@ class auth_chain_b(auth_chain_a):
self.salt = b"auth_chain_b" self.salt = b"auth_chain_b"
self.no_compatible_method = 'auth_chain_b' self.no_compatible_method = 'auth_chain_b'
self.data_size_list = [] self.data_size_list = []
self.data_size_list2 = []
def init_data_size(self, key): def init_data_size(self, key):
if self.data_size_list: if self.data_size_list:
self.data_size_list = [] self.data_size_list = []
self.data_size_list2 = []
random = xorshift128plus() random = xorshift128plus()
random.init_from_bin(key) random.init_from_bin(key)
list_len = random.next() % 16 + 4; list_len = random.next() % 16 + 4
for i in range(0, list_len): for i in range(0, list_len):
self.data_size_list.append((int)(random.next() % 1440)) self.data_size_list.append((int)(random.next() % 1440))
self.data_size_list.sort() self.data_size_list.sort()
list_len = random.next() % 32 + 32
for i in range(0, list_len):
self.data_size_list2.append((int)(random.next() % 1440))
self.data_size_list2.sort()
def set_server_info(self, server_info): def set_server_info(self, server_info):
self.server_info = server_info self.server_info = server_info
@ -669,6 +675,11 @@ class auth_chain_b(auth_chain_a):
if final_pos < len(self.data_size_list): if final_pos < len(self.data_size_list):
return self.data_size_list[final_pos] - buf_size - self.server_info.overhead return self.data_size_list[final_pos] - buf_size - self.server_info.overhead
pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
final_pos = pos + random.next() % (len(self.data_size_list2) + 1 - pos)
if final_pos < len(self.data_size_list2):
return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
if buf_size > 1300: if buf_size > 1300:
return random.next() % 31 return random.next() % 31
if buf_size > 900: if buf_size > 900:

6
shadowsocks/tcprelay.py

@ -816,15 +816,15 @@ class TCPRelayHandler(object):
if self._overhead == 0: if self._overhead == 0:
return recv_buffer_size return recv_buffer_size
buffer_size = len(sock.recv(recv_buffer_size, socket.MSG_PEEK)) buffer_size = len(sock.recv(recv_buffer_size, socket.MSG_PEEK))
frame_size = self._tcp_mss - self._overhead
if up: if up:
buffer_size = min(buffer_size, self._recv_u_max_size) buffer_size = min(buffer_size, self._recv_u_max_size)
self._recv_u_max_size = min(self._recv_u_max_size + self._tcp_mss - self._overhead, BUF_SIZE) self._recv_u_max_size = min(self._recv_u_max_size + frame_size, BUF_SIZE)
else: else:
buffer_size = min(buffer_size, self._recv_d_max_size) buffer_size = min(buffer_size, self._recv_d_max_size)
self._recv_d_max_size = min(self._recv_d_max_size + self._tcp_mss - self._overhead, BUF_SIZE) self._recv_d_max_size = min(self._recv_d_max_size + frame_size, BUF_SIZE)
if buffer_size == recv_buffer_size: if buffer_size == recv_buffer_size:
return buffer_size return buffer_size
frame_size = self._tcp_mss - self._overhead
if buffer_size > frame_size: if buffer_size > frame_size:
buffer_size = int(buffer_size / frame_size) * frame_size buffer_size = int(buffer_size / frame_size) * frame_size
return buffer_size return buffer_size

Loading…
Cancel
Save