mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 04:52:30 +00:00
Fix valid auth_key never being saved after switching DC
This commit is contained in:
@@ -61,6 +61,7 @@ class MTProtoSender:
|
||||
"""
|
||||
def __init__(self, auth_key, loop, *,
|
||||
retries=5, delay=1, auto_reconnect=True, connect_timeout=None,
|
||||
auth_key_callback=None,
|
||||
update_callback=None, auto_reconnect_callback=None):
|
||||
self._connection = None
|
||||
self._loop = loop
|
||||
@@ -68,6 +69,7 @@ class MTProtoSender:
|
||||
self._delay = delay
|
||||
self._auto_reconnect = auto_reconnect
|
||||
self._connect_timeout = connect_timeout
|
||||
self._auth_key_callback = auth_key_callback
|
||||
self._update_callback = update_callback
|
||||
self._auto_reconnect_callback = auto_reconnect_callback
|
||||
|
||||
@@ -232,6 +234,13 @@ class MTProtoSender:
|
||||
self.auth_key.key, self._state.time_offset =\
|
||||
await authenticator.do_authentication(plain)
|
||||
|
||||
# This is *EXTREMELY* important since we don't control
|
||||
# external references to the authorization key, we must
|
||||
# notify whenever we change it. This is crucial when we
|
||||
# switch to different data centers.
|
||||
if self._auth_key_callback:
|
||||
self._auth_key_callback(self.auth_key)
|
||||
|
||||
break
|
||||
except (SecurityError, AssertionError) as e:
|
||||
__log__.warning('Attempt {} at new auth_key failed: {}'
|
||||
@@ -420,6 +429,9 @@ class MTProtoSender:
|
||||
__log__.warning('Invalid buffer %s', e)
|
||||
|
||||
self.auth_key.key = None
|
||||
if self._auth_key_callback:
|
||||
self._auth_key_callback(None)
|
||||
|
||||
self._start_reconnect()
|
||||
return
|
||||
except Exception:
|
||||
|
Reference in New Issue
Block a user