Ensure that deleting sessions happens on session queue

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent 2d93b8c6ec
commit bb38fce54e

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 31/12/14. //
// Copyright (c) 2014 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSInvalidIdentityKeyReceivingErrorMessage.h" #import "TSInvalidIdentityKeyReceivingErrorMessage.h"
#import "OWSFingerprint.h" #import "OWSFingerprint.h"
@ -78,20 +79,25 @@ NS_ASSUME_NONNULL_BEGIN
return; return;
} }
[[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:self.envelope.source]; // Saving a new identity mutates the session store so it must happen on the sessionStoreQueue
dispatch_async([OWSDispatch sessionStoreQueue], ^{
// Decrypt this and any old messages for the newly accepted key [[TSStorageManager sharedManager] saveRemoteIdentity:newKey recipientId:self.envelope.source];
NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *messagesToDecrypt =
[self.thread receivedMessagesForInvalidKey:newKey]; dispatch_async(dispatch_get_main_queue(), ^{
// Decrypt this and any old messages for the newly accepted key
for (TSInvalidIdentityKeyReceivingErrorMessage *errorMessage in messagesToDecrypt) { NSArray<TSInvalidIdentityKeyReceivingErrorMessage *> *messagesToDecrypt =
[[TSMessagesManager sharedManager] handleReceivedEnvelope:errorMessage.envelope]; [self.thread receivedMessagesForInvalidKey:newKey];
// Here we remove the existing error message because handleReceivedEnvelope will either for (TSInvalidIdentityKeyReceivingErrorMessage *errorMessage in messagesToDecrypt) {
// 1.) succeed and create a new successful message in the thread or... [[TSMessagesManager sharedManager] handleReceivedEnvelope:errorMessage.envelope];
// 2.) fail and create a new identical error message in the thread.
[errorMessage remove]; // Here we remove the existing error message because handleReceivedEnvelope will either
} // 1.) succeed and create a new successful message in the thread or...
// 2.) fail and create a new identical error message in the thread.
[errorMessage remove];
}
});
});
} }
- (NSData *)newIdentityKey - (NSData *)newIdentityKey

@ -1,5 +1,6 @@
// Created by Frederic Jacobs on 15/02/15. //
// Copyright (c) 2015 Open Whisper Systems. All rights reserved. // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSInvalidIdentityKeySendingErrorMessage.h" #import "TSInvalidIdentityKeySendingErrorMessage.h"
#import "OWSFingerprint.h" #import "OWSFingerprint.h"
@ -56,7 +57,10 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey";
- (void)acceptNewIdentityKey - (void)acceptNewIdentityKey
{ {
[[TSStorageManager sharedManager] saveRemoteIdentity:self.newIdentityKey recipientId:self.recipientId]; // Saving a new identity mutates the session store so it must happen on the sessionStoreQueue
dispatch_async([OWSDispatch sessionStoreQueue], ^{
[[TSStorageManager sharedManager] saveRemoteIdentity:self.newIdentityKey recipientId:self.recipientId];
});
} }
- (NSData *)newIdentityKey - (NSData *)newIdentityKey

@ -581,7 +581,9 @@ NS_ASSUME_NONNULL_BEGIN
} }
}]; }];
[[TSStorageManager sharedManager] deleteAllSessionsForContact:endSessionEnvelope.source]; dispatch_async([OWSDispatch sessionStoreQueue], ^{
[[TSStorageManager sharedManager] deleteAllSessionsForContact:endSessionEnvelope.source];
});
} }
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope - (void)handleExpirationTimerUpdateMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope

Loading…
Cancel
Save