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.
This commit is contained in:
Lonami Exo 2017-09-05 16:11:02 +02:00
parent d5cd59de8a
commit 2924912931

View File

@ -213,6 +213,11 @@ class TelegramBareClient:
'Stabilise a successful initial connection first.') 'Stabilise a successful initial connection first.')
try: 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( return next(
dc for dc in self.dc_options if dc.id == dc_id and dc for dc in self.dc_options if dc.id == dc_id and
bool(dc.ipv6) == ipv6 and bool(dc.cdn) == cdn bool(dc.ipv6) == ipv6 and bool(dc.cdn) == cdn
@ -221,9 +226,7 @@ class TelegramBareClient:
if not cdn: if not cdn:
raise raise
for pk in self(GetCdnConfigRequest()).public_keys: # New configuration, perhaps a new CDN was added?
rsa.add_key(pk.public_key)
self.dc_options = self(GetConfigRequest()).dc_options self.dc_options = self(GetConfigRequest()).dc_options
return self._get_dc(dc_id, ipv6=ipv6, cdn=cdn) return self._get_dc(dc_id, ipv6=ipv6, cdn=cdn)