mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-12 17:12:23 +03:00
Update time offset if first message is badMsgNotification
This should prevent the library from getting stuck during connect.
This commit is contained in:
parent
11658d3bbf
commit
9545011de6
|
@ -152,7 +152,7 @@ class MTProtoState:
|
||||||
"""
|
"""
|
||||||
Inverse of `encrypt_message_data` for incoming server messages.
|
Inverse of `encrypt_message_data` for incoming server messages.
|
||||||
"""
|
"""
|
||||||
now = time.time() + self.time_offset # get the time as early as possible, even if other checks make it go unused
|
now = time.time() # get the time as early as possible, even if other checks make it go unused
|
||||||
|
|
||||||
if len(body) < 8:
|
if len(body) < 8:
|
||||||
raise InvalidBufferError(body)
|
raise InvalidBufferError(body)
|
||||||
|
@ -204,8 +204,14 @@ class MTProtoState:
|
||||||
#
|
#
|
||||||
# This means we skip the time check for certain types of messages.
|
# This means we skip the time check for certain types of messages.
|
||||||
if obj.CONSTRUCTOR_ID not in (BadServerSalt.CONSTRUCTOR_ID, BadMsgNotification.CONSTRUCTOR_ID):
|
if obj.CONSTRUCTOR_ID not in (BadServerSalt.CONSTRUCTOR_ID, BadMsgNotification.CONSTRUCTOR_ID):
|
||||||
|
if not self._highest_remote_id and not self.time_offset:
|
||||||
|
# If the first message we receive is a bad notification, take this opportunity
|
||||||
|
# to adjust the time offset. Assume it will remain stable afterwards. Updating
|
||||||
|
# the offset unconditionally would make the next checks pointless.
|
||||||
|
self.update_time_offset(remote_msg_id)
|
||||||
|
|
||||||
remote_msg_time = remote_msg_id >> 32
|
remote_msg_time = remote_msg_id >> 32
|
||||||
time_delta = now - remote_msg_time
|
time_delta = (now + self.time_offset) - remote_msg_time
|
||||||
|
|
||||||
if time_delta > MSG_TOO_OLD_DELTA:
|
if time_delta > MSG_TOO_OLD_DELTA:
|
||||||
self._log.warning('Server sent a very old message with ID %d, ignoring (see FAQ for details)', remote_msg_id)
|
self._log.warning('Server sent a very old message with ID %d, ignoring (see FAQ for details)', remote_msg_id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user