Browse Source

limit active UDP client to 256

dev
BreakWa11 9 years ago
parent
commit
4e43a4932d
  1. 4
      shadowsocks/lru_cache.py
  2. 4
      shadowsocks/udprelay.py

4
shadowsocks/lru_cache.py

@ -107,10 +107,10 @@ class LRUCache(collections.MutableMapping):
logging.debug('%d keys swept' % c) logging.debug('%d keys swept' % c)
return c < SWEEP_MAX_ITEMS return c < SWEEP_MAX_ITEMS
def clear(self): def clear(self, keep):
now = time.time() now = time.time()
c = 0 c = 0
while c < SWEEP_MAX_ITEMS: while len(self._keys_to_last_time) > keep:
if len(self._keys_to_last_time) == 0: if len(self._keys_to_last_time) == 0:
break break
for key in self._keys_to_last_time: for key in self._keys_to_last_time:

4
shadowsocks/udprelay.py

@ -1138,6 +1138,8 @@ class UDPRelay(object):
(common.to_str(server_addr), server_port, (common.to_str(server_addr), server_port,
r_addr[0], r_addr[1])) r_addr[0], r_addr[1]))
self._cache.clear(256)
if self._is_local: if self._is_local:
ref_iv = [encrypt.encrypt_new_iv(self._method)] ref_iv = [encrypt.encrypt_new_iv(self._method)]
self._protocol.obfs.server_info.iv = ref_iv[0] self._protocol.obfs.server_info.iv = ref_iv[0]
@ -1344,7 +1346,7 @@ class UDPRelay(object):
logging.debug('UDP close') logging.debug('UDP close')
self._closed = True self._closed = True
if not next_tick: if not next_tick:
self._cache.clear() self._cache.clear(0)
if self._eventloop: if self._eventloop:
self._eventloop.remove_periodic(self.handle_periodic) self._eventloop.remove_periodic(self.handle_periodic)
self._eventloop.remove(self._server_socket) self._eventloop.remove(self._server_socket)

Loading…
Cancel
Save