vshymanskyy / aiodns

A small async DNS client for MicroPython
MIT License
9 stars 1 forks source link

Some queries #1

Closed peterhinch closed 5 days ago

peterhinch commented 6 days ago

I have two queries on this code.

The official code does not appear to use a hard coded list of DNS servers; I assume it uses the LAN's DNS server by default. Is there a reason why your code does not do this? A user might have a local DNS server (PiHole or suchlike) and it would seem reasonable to use this by default. An option to override this with a specific list might be useful.

My second query is on your use of nonblocking sockets. My understanding is that .sendto, .recvfrom and other read/write methods prioritise immediate return over completion. Consequently write methods can return when only partially complete and read methods can return short results. My understanding is that these methods should be called in a loop, terminating when the expected number of bytes have been processed. See for example MQTT_base._as_read.

The official docs touch on the issue of short reads, but the explanation is terse.

Problems with partial completion may only be evident on slow networks.

vshymanskyy commented 6 days ago

Thank you, your points are very valid.

vshymanskyy commented 5 days ago

I assume it uses the LAN's DNS server by default.

Yes, it uses a single global DNS server an causes issues like this. To fix this and give more flexibility, I decided that DNS addresses need to be explicitly added upon each network interface connection (i.e. wifi, cellular, ethernet). With the added API you can have full control over DNS server list.

For .sendto, i have implemented a simple retry mechanism. For .recvfrom, I don't believe this is needed because it already runs in a loop. These APIs really work with datagrams so there should be no concept of short reads or writes. It either succeeds or fails.

This was tested on a 2G network over PPP

peterhinch commented 5 days ago

These APIs really work with datagrams so there should be no concept of short reads or writes. It either succeeds or fails.

Good point.

vshymanskyy commented 5 days ago

This https://github.com/vshymanskyy/aiodns/commit/88d7406238ce6209ec846ec52e12ba8357fd3d79 the default behavior is changed:

Now system dns is used by default (along with additionally configured servers). If no DNS servers are configured, it falls back to the hardcoded list