Browse Source

optimize

akkariiin/dev
AkaneAkaza 7 years ago
parent
commit
ca740c8c9b
  1. 11
      shadowsocks/obfsplugin/auth_chain.py
  2. 5
      shadowsocks/tcprelay.py

11
shadowsocks/obfsplugin/auth_chain.py

@ -87,19 +87,20 @@ class xorshift128plus(object):
y = self.v1 y = self.v1
self.v0 = y self.v0 = y
x ^= ((x & xorshift128plus.mov_mask) << 23) x ^= ((x & xorshift128plus.mov_mask) << 23)
x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int x ^= (y ^ (x >> 17) ^ (y >> 26))
self.v1 = x self.v1 = x
return (x + y) & xorshift128plus.max_int return (x + y) & xorshift128plus.max_int
def init_from_bin(self, bin): def init_from_bin(self, bin):
bin += b'\0' * 16 if len(bin) < 16:
bin += b'\0' * 16
self.v0 = struct.unpack('<Q', bin[:8])[0] self.v0 = struct.unpack('<Q', bin[:8])[0]
self.v1 = struct.unpack('<Q', bin[8:16])[0] self.v1 = struct.unpack('<Q', bin[8:16])[0]
def init_from_bin_len(self, bin, length): def init_from_bin_len(self, bin, length):
bin += b'\0' * 16 if len(bin) < 16:
bin = struct.pack('<H', length) + bin[2:] bin += b'\0' * 16
self.v0 = struct.unpack('<Q', bin[:8])[0] self.v0 = struct.unpack('<Q', struct.pack('<H', length) + bin[2:8])[0]
self.v1 = struct.unpack('<Q', bin[8:16])[0] self.v1 = struct.unpack('<Q', bin[8:16])[0]
for i in range(4): for i in range(4):

5
shadowsocks/tcprelay.py

@ -1163,8 +1163,9 @@ class TCPRelayHandler(object):
self._protocol.dispose() self._protocol.dispose()
self._protocol = None self._protocol = None
self._encryptor.dispose() if self._encryptor:
self._encryptor = None self._encryptor.dispose()
self._encryptor = None
self._dns_resolver.remove_callback(self._handle_dns_resolved) self._dns_resolver.remove_callback(self._handle_dns_resolved)
self._server.remove_handler(self) self._server.remove_handler(self)
if self._add_ref > 0: if self._add_ref > 0:

Loading…
Cancel
Save