Skip to content

Commit c2a29c8

Browse files
committed
Tune stored_msg_ids max size
1 parent 2a1af2b commit c2a29c8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

pyrogram/crypto/mtproto.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from . import aes
2727
from ..session.internals import MsgId
2828

29+
STORED_MSG_IDS_MAX_SIZE = 1000 * 2
30+
2931

3032
def kdf(auth_key: bytes, msg_key: bytes, outgoing: bool) -> tuple:
3133
# https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector
@@ -97,8 +99,8 @@ def unpack(
9799
# https://core.telegram.org/mtproto/security_guidelines#checking-msg-id
98100
assert message.msg_id % 2 != 0
99101

100-
if len(stored_msg_ids) > 200:
101-
stored_msg_ids = stored_msg_ids[50:]
102+
if len(stored_msg_ids) > STORED_MSG_IDS_MAX_SIZE:
103+
del stored_msg_ids[:STORED_MSG_IDS_MAX_SIZE // 2]
102104

103105
if stored_msg_ids:
104106
# Ignored message: msg_id is lower than all of the stored values

0 commit comments

Comments
 (0)