Avoid packing more than 1024 messages in a single container

This commit is contained in:
Lonami Exo 2018-11-19 08:29:44 +01:00
parent f90dd76f4c
commit 207d5ebdcb
2 changed files with 8 additions and 2 deletions

View File

@ -53,8 +53,9 @@ class MessagePacker:
batch = [] batch = []
size = 0 size = 0
# Fill a new batch to return while the size is small enough # Fill a new batch to return while the size is small enough,
while self._deque: # as long as we don't exceed the maximum length of messages.
while self._deque and len(batch) <= MessageContainer.MAXIMUM_LENGTH:
state = self._deque.popleft() state = self._deque.popleft()
size += len(state.data) + TLMessage.SIZE_OVERHEAD size += len(state.data) + TLMessage.SIZE_OVERHEAD

View File

@ -15,6 +15,11 @@ class MessageContainer(TLObject):
# The overhead of the container itself is subtracted. # The overhead of the container itself is subtracted.
MAXIMUM_SIZE = 1044456 - 8 MAXIMUM_SIZE = 1044456 - 8
# Maximum amount of messages that can't be sent inside a single
# container, inclusive. Beyond this limit Telegram will respond
# with BAD_MESSAGE 64 (invalid container).
MAXIMUM_LENGTH = 1024
def __init__(self, messages): def __init__(self, messages):
self.messages = messages self.messages = messages