async def start_peer(self, peer: BasePeer) -> None:
        self.manager.run_child_service(peer.connection)
        await asyncio.wait_for(peer.connection.get_manager().wait_started(),
                               timeout=PEER_READY_TIMEOUT)

        try:
            await peer.connection.run_peer(peer)
        except asyncio.TimeoutError as err:
            self.logger.debug('Timout waiting for peer to start: %s', err)
            return

        if peer.get_manager().is_running:
            self._add_peer(peer)
        else:
            self.logger.debug(
                "%s was cancelled immediately, not adding to pool", peer)
            return

        peer.start_protocol_streams()
        try:
            await asyncio.wait_for(
                peer.boot_manager.get_manager().wait_finished(),
                timeout=self._peer_boot_timeout)
        except asyncio.TimeoutError as err:
            self.logger.debug('Timout waiting for peer to boot: %s', err)
            await peer.disconnect(DisconnectReason.TIMEOUT)
            return
        else:
            if not peer.get_manager().is_running:
                self.logger.debug(
                    '%s disconnected during boot-up, dropped from pool', peer)
示例#2
0
    async def _add_peer_and_bootstrap(self, peer: BasePeer) -> None:
        # Add the peer to ourselves, ensuring it has subscribers before we start the protocol
        # streams.
        self._add_peer(peer)
        peer.start_protocol_streams()

        try:
            await asyncio.wait_for(
                peer.boot_manager.get_manager().wait_finished(),
                timeout=self._peer_boot_timeout)
        except asyncio.TimeoutError as err:
            self.logger.debug('Timout waiting for peer to boot: %s', err)
            await peer.disconnect(DisconnectReason.TIMEOUT)
            return