Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort ptr discovery on error_received #10

Merged
merged 3 commits into from
Apr 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion aiodiscover/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, destination):
self.responses = {}
self.send_qid = None
self.responded = asyncio.Event()
self.error = None

def connection_lost(self, transport):
"""Connection lost."""
Expand All @@ -74,12 +75,19 @@ def datagram_received(self, data, addr):
if msg.qid == self.send_qid:
self.responded.set()

def error_received(self, exc):
"""Error received."""
self.error = exc
self.responded.set()

async def send_query(self, query):
"""Send a query and wait for a response."""
self.responded.clear()
self.send_qid = query.qid
self.transport.sendto(query.pack(), self.destination)
await self.responded.wait()
if self.error:
raise self.error


async def async_query_for_ptrs(nameserver, ips_to_lookup):
Expand Down Expand Up @@ -115,6 +123,8 @@ async def _async_query_for_ptrs(protocol, ips_to_lookup):
time_outs += 1
if time_outs == MAX_DNS_TIMEOUT_DECLARE_DEAD_NAMESERVER:
break
except OSError:
break

return [protocol.responses.get(query_for_ip.get(ip)) for ip in ips_to_lookup]

Expand Down Expand Up @@ -161,7 +171,7 @@ async def async_get_hostnames(self, sys_network_data):
ips = []
for host in sys_network_data.network.hosts():
if len(ips) > MAX_ADDRESSES:
_LOGGER.warning(
_LOGGER.debug(
"Max addresses of %s reached for network: %s",
MAX_ADDRESSES,
sys_network_data.network,
Expand Down