|
@ -902,7 +902,7 @@ class UDPRelay(object): |
|
|
self._cache_dns_client = lru_cache.LRUCache(timeout=10, |
|
|
self._cache_dns_client = lru_cache.LRUCache(timeout=10, |
|
|
close_callback=self._close_client_pair) |
|
|
close_callback=self._close_client_pair) |
|
|
self._client_fd_to_server_addr = {} |
|
|
self._client_fd_to_server_addr = {} |
|
|
self._dns_cache = lru_cache.LRUCache(timeout=300) |
|
|
self._dns_cache = lru_cache.LRUCache(timeout=1800) |
|
|
self._eventloop = None |
|
|
self._eventloop = None |
|
|
self._closed = False |
|
|
self._closed = False |
|
|
self.server_transfer_ul = 0 |
|
|
self.server_transfer_ul = 0 |
|
@ -1158,10 +1158,12 @@ class UDPRelay(object): |
|
|
connecttype, dest_addr, dest_port, header_length = header_result |
|
|
connecttype, dest_addr, dest_port, header_length = header_result |
|
|
|
|
|
|
|
|
if self._is_local: |
|
|
if self._is_local: |
|
|
|
|
|
connecttype = 3 |
|
|
server_addr, server_port = self._get_a_server() |
|
|
server_addr, server_port = self._get_a_server() |
|
|
else: |
|
|
else: |
|
|
server_addr, server_port = dest_addr, dest_port |
|
|
server_addr, server_port = dest_addr, dest_port |
|
|
|
|
|
|
|
|
|
|
|
if (connecttype & 7) == 3: |
|
|
addrs = self._dns_cache.get(server_addr, None) |
|
|
addrs = self._dns_cache.get(server_addr, None) |
|
|
if addrs is None: |
|
|
if addrs is None: |
|
|
# TODO async getaddrinfo |
|
|
# TODO async getaddrinfo |
|
@ -1172,6 +1174,12 @@ class UDPRelay(object): |
|
|
return |
|
|
return |
|
|
else: |
|
|
else: |
|
|
self._dns_cache[server_addr] = addrs |
|
|
self._dns_cache[server_addr] = addrs |
|
|
|
|
|
else: |
|
|
|
|
|
addrs = socket.getaddrinfo(server_addr, server_port, 0, |
|
|
|
|
|
socket.SOCK_DGRAM, socket.SOL_UDP) |
|
|
|
|
|
if not addrs: |
|
|
|
|
|
# drop |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
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) |
|
|