Listen on ::0 so we can respond to both ipv4 and ipv6 (#14731)

* Listen on ::0 so we can respond to both ipv4 and ipv6

* Move the initial sleep to the end of the first attempt to load reliable peers, so that if we already have a database, it doesn't take 60 seconds to start responding
This commit is contained in:
Chris Marslender 2023-03-03 19:59:54 -06:00 committed by GitHub
parent 69a91d24ef
commit db6bf72af3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -93,15 +93,13 @@ class DNSServer:
# One protocol instance will be created to serve all
# client requests.
self.transport, self.protocol = await loop.create_datagram_endpoint(
lambda: EchoServerProtocol(self.dns_response), local_addr=("0.0.0.0", 53)
lambda: EchoServerProtocol(self.dns_response), local_addr=("::0", 53)
)
self.reliable_task = asyncio.create_task(self.periodically_get_reliable_peers())
async def periodically_get_reliable_peers(self):
sleep_interval = 0
while True:
sleep_interval = min(15, sleep_interval + 1)
await asyncio.sleep(sleep_interval * 60)
try:
# TODO: double check this. It shouldn't take this long to connect.
crawl_db = await aiosqlite.connect(self.db_path, timeout=600)
@ -143,6 +141,9 @@ class DNSServer:
except Exception as e:
log.error(f"Exception: {e}. Traceback: {traceback.format_exc()}.")
sleep_interval = min(15, sleep_interval + 1)
await asyncio.sleep(sleep_interval * 60)
async def get_peers_to_respond(self, ipv4_count, ipv6_count):
peers = []
async with self.lock: