async def discover(self, addr: str = None, tries: int = 5, blocking: bool = True, timeout: int = 5) -> Dict[str, XStruct]: """ Discover consoles on the network Args: addr (str): IP address tries (int): Discover attempts blocking (bool): Wait a given time for responses, otherwise return immediately timeout (int): Timeout in seconds (only if `blocking` is `True`) Returns: list: List of discovered consoles """ self._discovered = {} msg = factory.discovery() task = asyncio.create_task(self._discover(msg, addr, tries)) # Blocking for a discovery is different than connect or regular message if blocking: try: await asyncio.wait_for(task, timeout) except asyncio.TimeoutError: pass return self.discovered
def discover(self, addr=None, tries=5, blocking=True, timeout=5): """ Discover consoles on the network Args: addr (str): IP address tries (int): Discover attempts blocking (bool): Wait a given time for responses, otherwise return immediately timeout (int): Timeout in seconds (only if `blocking` is `True`) Returns: list: List of discovered consoles """ self._discovered = {} msg = factory.discovery() greenlet = gevent.spawn(self._discover, msg, addr, tries) # Blocking for a discovery is different than connect or regular message if blocking: with gevent.Timeout(timeout, False): greenlet.join() return self.discovered
def test_discovery_request(packets, crypto): bin_name = 'discovery_request' msg = factory.discovery(client_type=enum.ClientType.Android) packed = _pack(msg, crypto) assert msg.header.pkt_type == enum.PacketType.DiscoveryRequest assert msg.header.version == 0 assert msg.unprotected_payload.flags == 0 assert msg.unprotected_payload.client_type == enum.ClientType.Android assert msg.unprotected_payload.minimum_version == 0 assert msg.unprotected_payload.maximum_version == 2 assert len(packed) == len(packets[bin_name]) assert packed == packets[bin_name]