Ejemplo n.º 1
0
    def start(self):
        while True:
            self.connection = Connection(
                DataCenter(self.dc_id, self.client.test_mode),
                self.client.proxy)

            try:
                self.connection.connect()

                for i in range(self.NET_WORKERS):
                    self.net_worker_list.append(
                        Thread(target=self.net_worker,
                               name="NetWorker#{}".format(i + 1)))

                    self.net_worker_list[-1].start()

                Thread(target=self.recv, name="RecvThread").start()

                self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
                self.current_salt = FutureSalt(
                    0, 0,
                    self._send(functions.Ping(0)).new_server_salt)
                self.current_salt = self._send(
                    functions.GetFutureSalts(1)).salts[0]

                self.next_salt_thread = Thread(target=self.next_salt,
                                               name="NextSaltThread")
                self.next_salt_thread.start()

                if not self.is_cdn:
                    self._send(
                        functions.InvokeWithLayer(
                            layer,
                            functions.InitConnection(
                                api_id=self.client.api_id,
                                app_version=self.client.app_version,
                                device_model=self.client.device_model,
                                system_version=self.client.system_version,
                                system_lang_code=self.client.lang_code,
                                lang_code=self.client.lang_code,
                                lang_pack="",
                                query=functions.help.GetConfig(),
                            )))

                self.ping_thread = Thread(target=self.ping, name="PingThread")
                self.ping_thread.start()

                log.info("Connection inited: Layer {}".format(layer))
            except (OSError, TimeoutError, Error):
                self.stop()
            except Exception as e:
                self.stop()
                raise e
            else:
                break

        self.is_connected.set()

        log.debug("Session started")
Ejemplo n.º 2
0
    async def start(self):
        while True:
            self.connection = Connection(self.dc_id,
                                         self.client.storage.test_mode(),
                                         self.client.ipv6, self.client.proxy)

            try:
                await self.connection.connect()

                self.net_worker_task = asyncio.ensure_future(self.net_worker())
                self.recv_task = asyncio.ensure_future(self.recv())

                self.current_salt = FutureSalt(0, 0, Session.INITIAL_SALT)
                self.current_salt = FutureSalt(0, 0, (await self._send(
                    functions.Ping(ping_id=0),
                    timeout=self.START_TIMEOUT)).new_server_salt)
                self.current_salt = \
                    (await self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT)).salts[0]

                self.next_salt_task = asyncio.ensure_future(self.next_salt())

                if not self.is_cdn:
                    await self._send(functions.InvokeWithLayer(
                        layer=layer,
                        query=functions.InitConnection(
                            api_id=self.client.api_id,
                            app_version=self.client.app_version,
                            device_model=self.client.device_model,
                            system_version=self.client.system_version,
                            system_lang_code=self.client.lang_code,
                            lang_code=self.client.lang_code,
                            lang_pack="",
                            query=functions.help.GetConfig(),
                        )),
                                     timeout=self.START_TIMEOUT)

                self.ping_task = asyncio.ensure_future(self.ping())

                log.info("Session initialized: Layer {}".format(layer))
                log.info("Device: {} - {}".format(self.client.device_model,
                                                  self.client.app_version))
                log.info("System: {} ({})".format(
                    self.client.system_version, self.client.lang_code.upper()))

            except AuthKeyDuplicated as e:
                await self.stop()
                raise e
            except (OSError, TimeoutError, RPCError):
                await self.stop()
            except Exception as e:
                await self.stop()
                raise e
            else:
                break

        self.is_connected.set()

        log.info("Session started")
Ejemplo n.º 3
0
    def start(self):
        while True:
            try:
                self.connection.connect()

                for i in range(self.NET_WORKERS):
                    self.net_worker_list.append(
                        Thread(target=self.net_worker,
                               name="NetWorker#{}".format(i + 1)))

                    self.net_worker_list[-1].start()

                Thread(target=self.recv, name="RecvThread").start()

                self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
                self.current_salt = FutureSalt(
                    0, 0,
                    self._send(functions.Ping(0)).new_server_salt)
                self.current_salt = self._send(
                    functions.GetFutureSalts(1)).salts[0]

                self.next_salt_thread = Thread(target=self.next_salt,
                                               name="NextSaltThread")
                self.next_salt_thread.start()

                if not self.is_cdn:
                    self._send(
                        functions.InvokeWithLayer(
                            layer,
                            functions.InitConnection(
                                self.api_id,
                                self.DEVICE_MODEL,
                                self.SYSTEM_VERSION,
                                self.APP_VERSION,
                                "en",
                                "",
                                "en",
                                functions.help.GetConfig(),
                            )))

                self.ping_thread = Thread(target=self.ping, name="PingThread")
                self.ping_thread.start()

                log.info("Connection inited: Layer {}".format(layer))
            except (OSError, TimeoutError, Error):
                self.stop()
            except Exception as e:
                self.stop()
                raise e
            else:
                break

        self.is_connected.set()

        log.debug("Session started")
Ejemplo n.º 4
0
    def start(self):
        terms = None

        while True:
            try:
                self.connection.connect()

                for i in range(self.WORKERS):
                    Thread(target=self.worker,
                           name="Worker#{}".format(i + 1)).start()

                Thread(target=self.recv, name="RecvThread").start()

                self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
                self.current_salt = FutureSalt(
                    0, 0,
                    self._send(functions.Ping(0)).new_server_salt)
                self.current_salt = self._send(
                    functions.GetFutureSalts(1)).salts[0]

                self.next_salt_thread = Thread(target=self.next_salt,
                                               name="NextSaltThread")
                self.next_salt_thread.start()

                if not self.is_cdn:
                    terms = self._send(
                        functions.InvokeWithLayer(
                            layer,
                            functions.InitConnection(
                                self.api_id,
                                self.DEVICE_MODEL,
                                self.SYSTEM_VERSION,
                                self.APP_VERSION,
                                "en",
                                "",
                                "en",
                                functions.help.GetTermsOfService(),
                            ))).text

                self.ping_thread = Thread(target=self.ping, name="PingThread")
                self.ping_thread.start()

                log.info("Connection inited: Layer {}".format(layer))
            except (OSError, TimeoutError):
                self.stop()
            else:
                break

        self.is_connected.set()
        self.total_connections += 1

        log.debug("Session started")

        return terms
Ejemplo n.º 5
0
    def start(self):
        while True:
            self.connection = Connection(self.dc_id,
                                         self.client.storage.test_mode(),
                                         self.client.ipv6, self.client.proxy)

            try:
                self.connection.connect()

                for i in range(self.NET_WORKERS):
                    self.net_worker_list.append(
                        Thread(target=self.net_worker,
                               name="NetWorker#{}".format(i + 1)))

                    self.net_worker_list[-1].start()

                Thread(target=self.recv, name="RecvThread").start()

                self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
                self.current_salt = FutureSalt(
                    0, 0,
                    self._send(functions.Ping(ping_id=0),
                               timeout=self.START_TIMEOUT).new_server_salt)
                self.current_salt = self._send(
                    functions.GetFutureSalts(num=1),
                    timeout=self.START_TIMEOUT).salts[0]

                self.next_salt_thread = Thread(target=self.next_salt,
                                               name="NextSaltThread")
                self.next_salt_thread.start()

                if not self.is_cdn:
                    self._send(functions.InvokeWithLayer(
                        layer=layer,
                        query=functions.InitConnection(
                            api_id=self.client.api_id,
                            app_version=self.client.app_version,
                            device_model=self.client.device_model,
                            system_version=self.client.system_version,
                            system_lang_code=self.client.lang_code,
                            lang_code=self.client.lang_code,
                            lang_pack="",
                            query=functions.help.GetConfig(),
                        )),
                               timeout=self.START_TIMEOUT)

                self.ping_thread = Thread(target=self.ping, name="PingThread")
                self.ping_thread.start()

                log.info("Session initialized: Layer {}".format(layer))
                log.info("Device: {} - {}".format(self.client.device_model,
                                                  self.client.app_version))
                log.info("System: {} ({})".format(
                    self.client.system_version, self.client.lang_code.upper()))

            except AuthKeyDuplicated as e:
                self.stop()
                raise e
            except (OSError, TimeoutError, RPCError):
                self.stop()
            except Exception as e:
                self.stop()
                raise e
            else:
                break

        self.is_connected.set()

        log.debug("Session started")