fix resolve_host
This commit is contained in:
parent
43d424978d
commit
7fe211d134
3 changed files with 8 additions and 5 deletions
|
@ -127,7 +127,7 @@ class Node:
|
||||||
|
|
||||||
if known_node_urls:
|
if known_node_urls:
|
||||||
for host, port in known_node_urls:
|
for host, port in known_node_urls:
|
||||||
address = await resolve_host(host)
|
address = await resolve_host(host, port, proto='udp')
|
||||||
if (address, port) not in known_node_addresses:
|
if (address, port) not in known_node_addresses:
|
||||||
known_node_addresses.append((address, port))
|
known_node_addresses.append((address, port))
|
||||||
url_to_addr[address] = host
|
url_to_addr[address] = host
|
||||||
|
|
|
@ -70,7 +70,7 @@ class StreamDownloader(StreamAssembler):
|
||||||
def add_fixed_peers(self):
|
def add_fixed_peers(self):
|
||||||
async def _add_fixed_peers():
|
async def _add_fixed_peers():
|
||||||
self.peer_queue.put_nowait([
|
self.peer_queue.put_nowait([
|
||||||
KademliaPeer(self.loop, address=(await resolve_host(url)), tcp_port=port + 1)
|
KademliaPeer(self.loop, address=(await resolve_host(url, port + 1, proto='tcp')), tcp_port=port + 1)
|
||||||
for url, port in self.config.reflector_servers
|
for url, port in self.config.reflector_servers
|
||||||
])
|
])
|
||||||
if self.config.reflector_servers:
|
if self.config.reflector_servers:
|
||||||
|
|
|
@ -142,7 +142,9 @@ def drain_tasks(tasks: typing.List[typing.Optional[asyncio.Task]]):
|
||||||
cancel_task(tasks.pop())
|
cancel_task(tasks.pop())
|
||||||
|
|
||||||
|
|
||||||
async def resolve_host(url: str) -> str:
|
async def resolve_host(url: str, port: int, proto: str) -> str:
|
||||||
|
if proto not in ['udp', 'tcp']:
|
||||||
|
raise Exception("invalid protocol")
|
||||||
try:
|
try:
|
||||||
if ipaddress.ip_address(url):
|
if ipaddress.ip_address(url):
|
||||||
return url
|
return url
|
||||||
|
@ -150,6 +152,7 @@ async def resolve_host(url: str) -> str:
|
||||||
pass
|
pass
|
||||||
loop = asyncio.get_running_loop()
|
loop = asyncio.get_running_loop()
|
||||||
return (await loop.getaddrinfo(
|
return (await loop.getaddrinfo(
|
||||||
url, 'https',
|
url, port,
|
||||||
proto=socket.IPPROTO_TCP,
|
proto=socket.IPPROTO_TCP if proto == 'tcp' else socket.SOCK_DGRAM,
|
||||||
|
type=socket.SOCK_STREAM
|
||||||
))[0][4][0]
|
))[0][4][0]
|
||||||
|
|
Loading…
Reference in a new issue