|
@ -103,6 +103,7 @@ class UDPRelay(object): |
|
|
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']) |
|
|
lru_cache.LRUCache(timeout=config['timeout']) |
|
|
|
|
|
self._dns_cache = lru_cache.LRUCache(timeout=300) |
|
|
self._eventloop = None |
|
|
self._eventloop = None |
|
|
self._closed = False |
|
|
self._closed = False |
|
|
self._last_time = time.time() |
|
|
self._last_time = time.time() |
|
@ -170,11 +171,15 @@ class UDPRelay(object): |
|
|
else: |
|
|
else: |
|
|
server_addr, server_port = dest_addr, dest_port |
|
|
server_addr, server_port = dest_addr, dest_port |
|
|
|
|
|
|
|
|
addrs = socket.getaddrinfo(server_addr, server_port, 0, |
|
|
addrs = self._dns_cache.get(server_addr, None) |
|
|
socket.SOCK_DGRAM, socket.SOL_UDP) |
|
|
if addrs is None: |
|
|
if not addrs: |
|
|
addrs = socket.getaddrinfo(server_addr, server_port, 0, |
|
|
# drop |
|
|
socket.SOCK_DGRAM, socket.SOL_UDP) |
|
|
return |
|
|
if not addrs: |
|
|
|
|
|
# drop |
|
|
|
|
|
return |
|
|
|
|
|
else: |
|
|
|
|
|
self._dns_cache[server_addr] = addrs |
|
|
|
|
|
|
|
|
af, socktype, proto, canonname, sa = addrs[0] |
|
|
af, socktype, proto, canonname, sa = addrs[0] |
|
|
key = client_key(r_addr, af) |
|
|
key = client_key(r_addr, af) |
|
|