예제 #1
0
 async def _get_services(self, host: IPv4Address, timeout: int) -> mdns.Response:
     port = int(os.environ.get("PYATV_UDNS_PORT", 5353))  # For testing purposes
     knocker = None
     try:
         knocker = await knock.knocker(host, KNOCK_PORTS, self.loop, timeout=timeout)
         response = await mdns.unicast(
             self.loop, str(host), ALL_SERVICES, port=port, timeout=timeout
         )
     except asyncio.TimeoutError:
         return mdns.Response([], False, None)
     finally:
         if knocker:
             knocker.cancel()
     return response
예제 #2
0
 async def _multicast(loop, services, **kwargs):
     hosts = set(service.address for service in udns_server.services.values())
     devices = {}
     sleep_proxy = udns_server.sleep_proxy
     udns_server.sleep_proxy = False
     for host in hosts:
         udns_server.ip_filter = host
         response = await mdns.unicast(
             loop, "127.0.0.1", services, port=udns_server.port
         )
         devices[IPv4Address(host)] = mdns.Response(
             response.services, sleep_proxy, response.model
         )
     return devices
예제 #3
0
 async def _multicast(loop, services, **kwargs):
     # Flatten list of lists of addresses: [["1.2.3.4"], ["2.2.2.2"]] -> ["1.2.3.4", "2.2.2.2"]
     hosts = set(
         chain(*[
             service.addresses for service in udns_server.services.values()
         ]))
     devices = {}
     sleep_proxy = udns_server.sleep_proxy
     udns_server.sleep_proxy = False
     for host in hosts:
         udns_server.ip_filter = host
         response = await mdns.unicast(loop,
                                       "127.0.0.1",
                                       services,
                                       port=udns_server.port)
         devices[IPv4Address(host)] = mdns.Response(response.services,
                                                    sleep_proxy,
                                                    response.model)
     return devices