diff --git a/lbrynet/dht/node.py b/lbrynet/dht/node.py index 5b20d952a..2cb4c3cf3 100644 --- a/lbrynet/dht/node.py +++ b/lbrynet/dht/node.py @@ -127,7 +127,7 @@ class Node: if 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: known_node_addresses.append((address, port)) url_to_addr[address] = host diff --git a/lbrynet/stream/downloader.py b/lbrynet/stream/downloader.py index c269275c4..3faedefd1 100644 --- a/lbrynet/stream/downloader.py +++ b/lbrynet/stream/downloader.py @@ -70,7 +70,7 @@ class StreamDownloader(StreamAssembler): def add_fixed_peers(self): async def _add_fixed_peers(): 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 ]) if self.config.reflector_servers: diff --git a/lbrynet/utils.py b/lbrynet/utils.py index 9b02c01bd..941748fc4 100644 --- a/lbrynet/utils.py +++ b/lbrynet/utils.py @@ -142,7 +142,9 @@ def drain_tasks(tasks: typing.List[typing.Optional[asyncio.Task]]): 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: if ipaddress.ip_address(url): return url @@ -150,6 +152,7 @@ async def resolve_host(url: str) -> str: pass loop = asyncio.get_running_loop() return (await loop.getaddrinfo( - url, 'https', - proto=socket.IPPROTO_TCP, + url, port, + proto=socket.IPPROTO_TCP if proto == 'tcp' else socket.SOCK_DGRAM, + type=socket.SOCK_STREAM ))[0][4][0]