postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
881 stars 96 forks source link

Figure out if I can write my own zeroconf client #717

Closed postlund closed 4 years ago

postlund commented 4 years ago

What to investigate Currently I rely on aiozeroconf for regular scanning. This of course has its advantages since I don't have to write my own zeroconf client. The downside is that it's not actively maintained. It also doesn't support sending requests for multiple services at once (like I do with unicast scanning) and it doesn't seem possible to access additional records in the responses, so I can't implement #533. If I roll my own I have full control, one less dependency and likely less problems with timing issues with responses. It also gives me an opportunity to learn more about zeroconf. Since I only use a small part of the protocol, this should be fairly easy to do.

Expected outcome I should be able to re-use a lot from unicast scanning. Most likely I should be able to send the request via multicast and await responses. So first step would be to PoC that before going further.

The downside is that I rely on registering custom services as well, maybe I keep aiozeroconf for that as a start.

postlund commented 4 years ago

Prototyping this was actually pretty simple. Just make sure to not pass remote_addr to create_datagram_endpoint (to not filter incoming packets) and family=socket.AF_INET. I will try to make a more complete implementation of this later tonight and tomorrow.

postlund commented 4 years ago

And oh, just tried requesting both airplay and mediaremotetv in the same request and got response from both (in the same packet). So now I know that it works for sure.

postlund commented 4 years ago

I did manage to completely PoC this and verify that everything worked with atvremote, so no problem there. Implementation is not really that hard, it's doing something that is testable at some level that is a bit tricky. But I will try to manage something.

postlund commented 4 years ago

An interesting thing I noted is that a sleep proxy only include PTR records for the requested services. So whenever a device is sleeping, the response will surely come but not all the necessary information will be there. This is most likely one of the reason why scanning is so flaky. Hopefully I can "solve" this by using unicast scanning if such responses are received. A bit complex but should work...

postlund commented 4 years ago

Closing in favor of #723 and #724.