Browse Source

dns hacks: dns via proxy: special-case "localhost" string

fix https://github.com/spesmilo/electrum/issues/7546
patch-4
SomberNight 3 years ago
parent
commit
5c91212fab
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 12
      electrum/dns_hacks.py

12
electrum/dns_hacks.py

@ -26,7 +26,11 @@ def configure_dns_depending_on_proxy(is_proxy: bool) -> None:
socket._getaddrinfo = socket.getaddrinfo
if is_proxy:
# prevent dns leaks, see http://stackoverflow.com/questions/13184205/dns-over-proxy
socket.getaddrinfo = lambda *args: [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
def getaddrinfo(host, port, *args, **kwargs):
if _is_force_system_dns_for_host(host):
return socket._getaddrinfo(host, port, *args, **kwargs)
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (host, port))]
socket.getaddrinfo = getaddrinfo
else:
if sys.platform == 'win32':
# On Windows, socket.getaddrinfo takes a mutex, and might hold it for up to 10 seconds
@ -56,6 +60,10 @@ def _prepare_windows_dns_hack():
thread_name_prefix='dns_resolver')
def _is_force_system_dns_for_host(host: str) -> bool:
return str(host) in ('localhost', 'localhost.',)
def _fast_getaddrinfo(host, *args, **kwargs):
def needs_dns_resolving(host):
try:
@ -63,7 +71,7 @@ def _fast_getaddrinfo(host, *args, **kwargs):
return False # already valid IP
except ValueError:
pass # not an IP
if str(host) in ('localhost', 'localhost.',):
if _is_force_system_dns_for_host(host):
return False
return True

Loading…
Cancel
Save