Browse Source

windows DNS resolution: follow-up 9b0773cf2b

related: #5176, #4421

prev was failing on systems where
IPv6 is not available but DNS can resolve AAAA records
(my artificial test environment with IPv6 disabled was also filtering AAAA DNS)
regtest_lnd
SomberNight 6 years ago
parent
commit
c4fb58cd74
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 17
      electrum/network.py

17
electrum/network.py

@ -526,10 +526,11 @@ class Network(PrintError):
return False
return True
def resolve_with_dnspython(host):
addrs = []
# try IPv6
try:
answers = dns.resolver.query(host, dns.rdatatype.AAAA)
return str(answers[0])
addrs += [str(answer) for answer in answers]
except dns.exception.DNSException as e:
pass
except BaseException as e:
@ -537,7 +538,7 @@ class Network(PrintError):
# try IPv4
try:
answers = dns.resolver.query(host, dns.rdatatype.A)
return str(answers[0])
addrs += [str(answer) for answer in answers]
except dns.exception.DNSException as e:
# dns failed for some reason, e.g. dns.resolver.NXDOMAIN
# this is normal. Simply report back failure:
@ -545,12 +546,16 @@ class Network(PrintError):
except BaseException as e:
# Possibly internal error in dnspython :( see #4483
print_error(f'dnspython failed to resolve dns (A) with error: {e}')
if addrs:
return addrs
# Fall back to original socket.getaddrinfo to resolve dns.
return host
addr = host
return [host]
addrs = [host]
if needs_dns_resolving(host):
addr = resolve_with_dnspython(host)
return socket._getaddrinfo(addr, *args, **kwargs)
addrs = resolve_with_dnspython(host)
list_of_list_of_socketinfos = [socket._getaddrinfo(addr, *args, **kwargs) for addr in addrs]
list_of_socketinfos = [item for lst in list_of_list_of_socketinfos for item in lst]
return list_of_socketinfos
@log_exceptions
async def set_parameters(self, net_params: NetworkParameters):

Loading…
Cancel
Save