mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-31 09:21:39 +00:00
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)
This commit is contained in:
parent
1cfac928f9
commit
c4fb58cd74
1 changed files with 11 additions and 6 deletions
|
@ -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…
Add table
Reference in a new issue