From 2924912931aa222a53ef7ed747e765fc832bcd47 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Tue, 5 Sep 2017 16:11:02 +0200 Subject: [PATCH] Fix CDN downloads not always calling GetCdnConfigRequest (#222) On previous tests, Telegram didn't return information about CDNs on the initial GetConfigRequest. However, it may do so, and it's necessary to call GetCdnConfigRequest even when a second call to GetConfigRequest isn't required. --- telethon/telegram_bare_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/telethon/telegram_bare_client.py b/telethon/telegram_bare_client.py index 328d4fe8..2ba3be5e 100644 --- a/telethon/telegram_bare_client.py +++ b/telethon/telegram_bare_client.py @@ -213,6 +213,11 @@ class TelegramBareClient: 'Stabilise a successful initial connection first.') try: + if cdn: + # Ensure we have the latest keys for the CDNs + for pk in self(GetCdnConfigRequest()).public_keys: + rsa.add_key(pk.public_key) + return next( dc for dc in self.dc_options if dc.id == dc_id and bool(dc.ipv6) == ipv6 and bool(dc.cdn) == cdn @@ -221,9 +226,7 @@ class TelegramBareClient: if not cdn: raise - for pk in self(GetCdnConfigRequest()).public_keys: - rsa.add_key(pk.public_key) - + # New configuration, perhaps a new CDN was added? self.dc_options = self(GetConfigRequest()).dc_options return self._get_dc(dc_id, ipv6=ipv6, cdn=cdn)