backend.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:parsec-cloud 作者: Scille 项目源码 文件源码
def open_connection(self, identity):
        logger.debug('Connection to backend opened')
        assert not self._websocket, "Connection to backend already opened"
        try:
            self._websocket = await websockets.connect(self.url)
            # Handle handshake
            raw = await self._websocket.recv()
            challenge = ejson_loads(raw)
            answer = identity.private_key.sign(challenge['challenge'].encode())
            await self._websocket.send(ejson_dumps({
                'handshake': 'answer',
                'identity': identity.id,
                'answer': to_jsonb64(answer)
            }))
            resp = ejson_loads(await self._websocket.recv())
            if resp['status'] != 'ok':
                await self.close_connection()
                raise exception_from_status(resp['status'])(resp['label'])
            self._ws_recv_handler_task = asyncio.ensure_future(
                self._ws_recv_handler(), loop=self.loop)
            if self.watchdog_time:
                self._watchdog_task = asyncio.ensure_future(self._watchdog(), loop=self.loop)
        except (ConnectionRefusedError, websockets.exceptions.ConnectionClosed) as exc:
            raise BackendConnectionError('Cannot connect to backend (%s)' % exc)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号