diff --git a/shadowsocks/shell.py b/shadowsocks/shell.py index c4b7381..d53e461 100644 --- a/shadowsocks/shell.py +++ b/shadowsocks/shell.py @@ -237,6 +237,7 @@ def get_config(is_local): config['port_password'] = config.get('port_password', None) config['timeout'] = int(config.get('timeout', 300)) config['udp_timeout'] = int(config.get('udp_timeout', config['timeout'])) + config['udp_cache'] = int(config.get('udp_cache', 64)) config['fast_open'] = config.get('fast_open', False) config['workers'] = config.get('workers', 1) config['pid-file'] = config.get('pid-file', '/var/run/shadowsocks.pid') diff --git a/shadowsocks/udprelay.py b/shadowsocks/udprelay.py index 4737199..7fb67b1 100644 --- a/shadowsocks/udprelay.py +++ b/shadowsocks/udprelay.py @@ -882,6 +882,7 @@ class UDPRelay(object): self._method = config['method'] self._timeout = config['timeout'] self._is_local = is_local + self._udp_cache_size = config['udp_cache'] self._cache = lru_cache.LRUCache(timeout=config['udp_timeout'], close_callback=self._close_client) self._client_fd_to_server_addr = {} @@ -1086,7 +1087,7 @@ class UDPRelay(object): (common.to_str(server_addr), server_port, r_addr[0], r_addr[1])) - self._cache.clear(256) + self._cache.clear(self._udp_cache_size) if self._is_local: ref_iv = [encrypt.encrypt_new_iv(self._method)]