From c20ab608903ae4b8b54312e71565143c91c36f01 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 13 Jun 2021 15:09:37 +0400 Subject: [PATCH] Network fixes --- .../PublicHeaders/MtProtoKit/MTSessionInfo.h | 2 ++ submodules/MtProtoKit/Sources/MTProto.m | 12 ++++-------- submodules/MtProtoKit/Sources/MTSessionInfo.m | 10 ++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTSessionInfo.h b/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTSessionInfo.h index ec32fbbce6..a3a3f2f262 100644 --- a/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTSessionInfo.h +++ b/submodules/MtProtoKit/PublicHeaders/MtProtoKit/MTSessionInfo.h @@ -19,6 +19,8 @@ - (bool)messageProcessed:(int64_t)messageId; - (void)setMessageProcessed:(int64_t)messageId; +- (bool)wasMessageSentOnce:(int64_t)messageId; +- (void)setMessageWasSentOnce:(int64_t)messageId; - (void)scheduleMessageConfirmation:(int64_t)messageId size:(NSInteger)size; - (NSArray *)scheduledMessageConfirmations; - (bool)scheduledMessageConfirmationsExceedSize:(NSInteger)sizeLimit orCount:(NSUInteger)countLimit; diff --git a/submodules/MtProtoKit/Sources/MTProto.m b/submodules/MtProtoKit/Sources/MTProto.m index 8bd36b4857..fa9cda74f5 100644 --- a/submodules/MtProtoKit/Sources/MTProto.m +++ b/submodules/MtProtoKit/Sources/MTProto.m @@ -1148,7 +1148,7 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64; { if (!_useUnauthorizedMode) { - NSMutableArray *currentContainerMessages = [[NSMutableArray alloc] init]; + NSMutableArray *currentContainerMessages = [[NSMutableArray alloc] init]; NSUInteger currentContainerSize = 0; for (NSUInteger j = i; j < transactionMessageList.count; j++, i++) @@ -1186,8 +1186,9 @@ static const NSUInteger MTMaxUnacknowledgedMessageCount = 64; } } - if (currentContainerMessages.count == 1) + if (currentContainerMessages.count == 1 && ![transactionSessionInfo wasMessageSentOnce:currentContainerMessages[0].messageId]) { + [transactionSessionInfo setMessageWasSentOnce:currentContainerMessages[0].messageId]; int32_t quickAckId = 0; NSData *messageData = [self _dataForEncryptedMessage:currentContainerMessages[0] authKey:authKey sessionInfo:transactionSessionInfo quickAckId:&quickAckId address:scheme.address extendedPadding:extendedPadding]; if (messageData != nil) @@ -2116,17 +2117,12 @@ static bool isDataEqualToDataConstTime(NSData *data1, NSData *data2) { if (data1.length != data2.length) { return false; } - uint8_t const *bytes1 = data1.bytes; uint8_t const *bytes2 = data2.bytes; - int result = 0; for (int i = 0; i < data1.length; i++) { - if (bytes1[i] != bytes2[i]) { - result |= i + 1; - } + result |= bytes1[i] != bytes2[i]; } - return result == 0; } diff --git a/submodules/MtProtoKit/Sources/MTSessionInfo.m b/submodules/MtProtoKit/Sources/MTSessionInfo.m index 1691592fa0..25d8e0dd07 100644 --- a/submodules/MtProtoKit/Sources/MTSessionInfo.m +++ b/submodules/MtProtoKit/Sources/MTSessionInfo.m @@ -52,6 +52,7 @@ NSMutableSet *_processedMessageIdsSet; NSMutableArray *_scheduledMessageConfirmations; NSMutableDictionary *_containerMessagesMappingDict; + NSMutableSet *_sentMessageIdsSet; } @end @@ -76,6 +77,7 @@ _scheduledMessageConfirmations = [[NSMutableArray alloc] init]; _processedMessageIdsSet = [[NSMutableSet alloc] init]; + _sentMessageIdsSet = [[NSMutableSet alloc] init]; _containerMessagesMappingDict = [[NSMutableDictionary alloc] init]; } return self; @@ -138,6 +140,14 @@ [_processedMessageIdsSet addObject:@(messageId)]; } +- (bool)wasMessageSentOnce:(int64_t)messageId { + return [_sentMessageIdsSet containsObject:@(messageId)]; +} + +- (void)setMessageWasSentOnce:(int64_t)messageId { + [_sentMessageIdsSet addObject:@(messageId)]; +} + - (void)scheduleMessageConfirmation:(int64_t)messageId size:(NSInteger)size { bool found = false;