From 14632c9bb1faec8f6ad45fcfce0a0f8715ed8ef4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 19 Dec 2017 11:38:15 +0100 Subject: [PATCH] Don't call InitConnection on CDN DCs --- pyrogram/session/session.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 1cd21014..aad0928a 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -68,12 +68,14 @@ class Session: notice_displayed = False - def __init__(self, dc_id: int, test_mode: bool, auth_key: bytes, api_id: str): + def __init__(self, dc_id: int, test_mode: bool, auth_key: bytes, api_id: str, is_cdn: bool = False): if not Session.notice_displayed: print("Pyrogram v{}, {}".format(__version__, __copyright__)) print("Licensed under the terms of the " + __license__, end="\n\n") Session.notice_displayed = True + self.is_cdn = is_cdn + self.connection = Connection(DataCenter(dc_id, test_mode)) self.api_id = api_id @@ -107,6 +109,8 @@ class Session: self.total_bytes = 0 def start(self): + terms = None + while True: try: self.connection.connect() @@ -128,19 +132,20 @@ class Session: self.next_salt_thread = Thread(target=self.next_salt, name="NextSaltThread") self.next_salt_thread.start() - 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(), + 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 if self.ping_thread is not None: self.ping_thread.join() @@ -161,7 +166,7 @@ class Session: log.debug("Session started") - return terms.text + return terms def stop(self): self.is_connected.clear()