Browse Source

UDP use only 1 lru cache (_client_fd_to_server_addr set to dict type)

dev
BreakWa11 9 years ago
parent
commit
691aa0970a
  1. 11
      shadowsocks/udprelay.py

11
shadowsocks/udprelay.py

@ -693,7 +693,7 @@ class TCPRelayHandler(object):
self._stage = STAGE_DNS self._stage = STAGE_DNS
self._dns_resolver.resolve(remote_addr, self._dns_resolver.resolve(remote_addr,
self._handle_dns_resolved) self._handle_dns_resolved)
logging.info('TCP connect %s:%d from %s:%d' % (remote_addr, remote_port, addr[0], addr[1])) logging.info('TCPonUDP connect %s:%d from %s:%d' % (remote_addr, remote_port, addr[0], addr[1]))
else: else:
# ileagal request # ileagal request
rsp_data = self._pack_rsp_data(CMD_DISCONNECT, RSP_STATE_EMPTY) rsp_data = self._pack_rsp_data(CMD_DISCONNECT, RSP_STATE_EMPTY)
@ -882,8 +882,7 @@ class UDPRelay(object):
self._is_local = is_local self._is_local = is_local
self._cache = lru_cache.LRUCache(timeout=config['timeout'], self._cache = lru_cache.LRUCache(timeout=config['timeout'],
close_callback=self._close_client) close_callback=self._close_client)
self._client_fd_to_server_addr = \ self._client_fd_to_server_addr = {}
lru_cache.LRUCache(timeout=config['timeout'])
self._dns_cache = lru_cache.LRUCache(timeout=300) self._dns_cache = lru_cache.LRUCache(timeout=300)
self._eventloop = None self._eventloop = None
self._closed = False self._closed = False
@ -945,6 +944,7 @@ class UDPRelay(object):
if hasattr(client, 'close'): if hasattr(client, 'close'):
self._sockets.remove(client.fileno()) self._sockets.remove(client.fileno())
self._eventloop.remove(client) self._eventloop.remove(client)
del self._client_fd_to_server_addr[client.fileno()]
client.close() client.close()
else: else:
# just an address # just an address
@ -1330,15 +1330,14 @@ class UDPRelay(object):
if self._server_socket: if self._server_socket:
self._server_socket.close() self._server_socket.close()
self._server_socket = None self._server_socket = None
for sock in self._sockets: #for sock in self._sockets:
sock.close() # sock.close()
logging.info('closed UDP port %d', self._listen_port) logging.info('closed UDP port %d', self._listen_port)
before_sweep_size = len(self._sockets) before_sweep_size = len(self._sockets)
self._cache.sweep() self._cache.sweep()
self._dns_cache.sweep() self._dns_cache.sweep()
if before_sweep_size != len(self._sockets): if before_sweep_size != len(self._sockets):
logging.debug('UDP port %5d sockets %d' % (self._listen_port, len(self._sockets))) logging.debug('UDP port %5d sockets %d' % (self._listen_port, len(self._sockets)))
self._client_fd_to_server_addr.sweep()
self._sweep_timeout() self._sweep_timeout()
def close(self, next_tick=False): def close(self, next_tick=False):

Loading…
Cancel
Save