async def _create_sender(self) -> MTProtoSender: # Check if we're connecting to the same DC we're connected to if self.dc_id == self.client.session.dc_id: return self.client._sender dc = await self.client._get_dc(self.dc_id) sender = MTProtoSender(self.auth_key, self.loop, loggers=self.client._log) await sender.connect( self.client._connection( dc.ip_address, dc.port, dc.id, loop=self.loop, loggers=self.client._log, proxy=self.client._proxy, )) if not self.auth_key: log.debug(f"Exporting auth to DC {self.dc_id}") auth = await self.client(ExportAuthorizationRequest(self.dc_id)) req = self.client._init_with( ImportAuthorizationRequest(id=auth.id, bytes=auth.bytes)) await sender.send(req) self.auth_key = sender.auth_key return sender
async def _export_auth_key(self, conn: Connection) -> None: try: auth = await self.client(ExportAuthorizationRequest(self.dc.id)) except DcIdInvalidError: self.auth_key = self.client.session.auth_key conn.sender.auth_key = self.auth_key return req = self.client._init_with( ImportAuthorizationRequest(id=auth.id, bytes=auth.bytes)) await conn.sender.send(req) self.auth_key = conn.sender.auth_key
async def _export_auth_key(self, conn: Connection) -> None: self.log.info(f'Exporting auth to DC {self.dc.id}' f' (main client is in {self.client.session.dc_id})') try: auth = await self.client(ExportAuthorizationRequest(self.dc.id)) except DcIdInvalidError: self.log.debug('Got DcIdInvalidError') self.auth_key = self.client.session.auth_key conn.sender.auth_key = self.auth_key return req = self.client._init_with( ImportAuthorizationRequest(id=auth.id, bytes=auth.bytes)) await conn.sender.send(req) self.auth_key = conn.sender.auth_key
async def _create_sender(self) -> MTProtoSender: dc = await self.client._get_dc(self.dc_id) sender = MTProtoSender(self.auth_key, loggers=self.client._log) await sender.connect(self.client._connection(dc.ip_address, dc.port, dc.id, loggers=self.client._log, proxy=self.client._proxy)) if not self.auth_key: log.debug(f"Exporting auth to DC {self.dc_id}") auth = await self.client(ExportAuthorizationRequest(self.dc_id)) self.client._init_request.query = ImportAuthorizationRequest( id=auth.id, bytes=auth.bytes) await sender.send(InvokeWithLayerRequest(LAYER, self.client._init_request)) self.auth_key = sender.auth_key return sender
async def _create_sender(self) -> MTProtoSender: dc = await self.client._get_dc(self.dc_id) sender = MTProtoSender(self.auth_key, loggers=self.client._log) await sender.connect( self.client._connection(dc.ip_address, dc.port, dc.id, loggers=self.client._log, proxy=self.client._proxy)) if not self.auth_key: log.debug(f"Kimlik doğrulama DC'ye aktarılıyor {self.dc_id}") auth = await self.client(ExportAuthorizationRequest(self.dc_id)) req = self.client._init_with( ImportAuthorizationRequest(id=auth.id, bytes=auth.bytes)) await sender.send(req) self.auth_key = sender.auth_key return sender