Example #1
0
 async def connect(
     self,
     destination: ConnectionDestination,
     metadata: Optional[Dict[str, str]] = None,
 ) -> CompanionInfo:
     self.logger.debug(f"Connecting directly to {destination} with meta {metadata}")
     if isinstance(destination, Address):
         channel = Channel(
             destination.host, destination.port, loop=asyncio.get_event_loop()
         )
         stub = CompanionServiceStub(channel=channel)
         with tempfile.NamedTemporaryFile(mode="w+b") as f:
             response = await stub.connect(
                 ConnectRequest(
                     destination=destination_to_grpc(destination),
                     metadata=metadata,
                     local_file_path=f.name,
                 )
             )
         companion = CompanionInfo(
             udid=response.companion.udid,
             host=destination.host,
             port=destination.port,
             is_local=response.companion.is_local,
         )
         self.logger.debug(f"Connected directly to {companion}")
         self.direct_companion_manager.add_companion(companion)
         channel.close()
         return companion
     else:
         companion = await self.spawn_companion(target_udid=destination)
         if companion:
             return companion
         else:
             raise IdbException(f"can't find target for udid {destination}")
Example #2
0
async def client(
    client: CompanionClient,
    destination: ConnectionDestination,
    disconnect_from_daemon: bool = False,
) -> None:
    await client.stub.disconnect(
        DisconnectRequest(
            destination=destination_to_grpc(destination),
            is_daemon=disconnect_from_daemon,
        ))
Example #3
0
async def client(
    client: CompanionClient,
    destination: ConnectionDestination,
    metadata: Optional[Dict[str, str]] = None,
) -> ConnectResponse:
    client.logger.debug(f"Connecting to {destination} with meta {metadata}")
    response = await client.stub.connect(
        GrpcConnectRequest(destination=destination_to_grpc(destination),
                           metadata=metadata))
    return companion_to_py(response.companion)