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)
return c < SWEEP_MAX_ITEMS
def clear(self):
def clear(self, keep):
now = time.time()
c = 0
while c < SWEEP_MAX_ITEMS:
while len(self._keys_to_last_time) > keep:
if len(self._keys_to_last_time) == 0:
break
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,
r_addr[0], r_addr[1]))
self._cache.clear(256)
if self._is_local:
ref_iv = [encrypt.encrypt_new_iv(self._method)]
self._protocol.obfs.server_info.iv = ref_iv[0]
@ -1344,7 +1346,7 @@ class UDPRelay(object):
logging.debug('UDP close')
self._closed = True
if not next_tick:
self._cache.clear()
self._cache.clear(0)
if self._eventloop:
self._eventloop.remove_periodic(self.handle_periodic)
self._eventloop.remove(self._server_socket)

Loading…
Cancel
Save