mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Fix DC migration and seqno
This commit is contained in:
parent
ac567ebf1d
commit
21ffa2f26b
|
@ -369,7 +369,7 @@ class TelegramBaseClient(abc.ABC):
|
|||
self.session.set_dc(dc.id, dc.ip_address, dc.port)
|
||||
# auth_key's are associated with a server, which has now changed
|
||||
# so it's not valid anymore. Set to None to force recreating it.
|
||||
self.session.auth_key = self._sender.state.auth_key = None
|
||||
self.session.auth_key = self._sender._connection._state.auth_key = None
|
||||
self.session.save()
|
||||
await self._disconnect()
|
||||
return await self.connect()
|
||||
|
|
|
@ -2,6 +2,7 @@ import io
|
|||
import struct
|
||||
|
||||
from .mtprotostate import MTProtoState
|
||||
from ..tl import TLRequest
|
||||
from ..tl.core.messagecontainer import MessageContainer
|
||||
|
||||
|
||||
|
@ -78,14 +79,15 @@ class MTProtoLayer:
|
|||
for state in state_list:
|
||||
if not isinstance(state, list):
|
||||
n += 1
|
||||
state.msg_id = \
|
||||
self._state.write_data_as_message(buffer, state.data)
|
||||
state.msg_id = self._state.write_data_as_message(
|
||||
buffer, state.data, isinstance(state.request, TLRequest))
|
||||
else:
|
||||
last_id = None
|
||||
for s in state:
|
||||
n += 1
|
||||
last_id = s.msg_id = self._state.write_data_as_message(
|
||||
buffer, s.data, after_id=last_id)
|
||||
buffer, s.data, isinstance(s.request, TLRequest),
|
||||
after_id=last_id)
|
||||
|
||||
if n > 1:
|
||||
# Inlined code to pack several messages into a container
|
||||
|
@ -97,7 +99,9 @@ class MTProtoLayer:
|
|||
'<Ii', MessageContainer.CONSTRUCTOR_ID, n
|
||||
) + buffer.getvalue()
|
||||
buffer = io.BytesIO()
|
||||
container_id = self._state.write_data_as_message(buffer, data)
|
||||
container_id = self._state.write_data_as_message(
|
||||
buffer, data, content_related=False
|
||||
)
|
||||
for state in state_list:
|
||||
if not isinstance(state, list):
|
||||
state.container_id = container_id
|
||||
|
|
|
@ -69,14 +69,15 @@ class MTProtoState:
|
|||
|
||||
return aes_key, aes_iv
|
||||
|
||||
def write_data_as_message(self, buffer, data, after_id=None):
|
||||
def write_data_as_message(self, buffer, data, content_related,
|
||||
*, after_id=None):
|
||||
"""
|
||||
Writes a message containing the given data into buffer.
|
||||
|
||||
Returns the message id.
|
||||
"""
|
||||
msg_id = self._get_new_msg_id()
|
||||
seq_no = self._get_seq_no(True) # TODO ack/ping are not content-related
|
||||
seq_no = self._get_seq_no(content_related)
|
||||
if after_id is None:
|
||||
body = GzipPacked.gzip_if_smaller(data)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user