prefer archiving vs deleting sessions.

This gives us a little resiliency to handling messages out of order
across key change.

We still *always* print SN when they change.
And we still verify that the session used for encrypt/decrypt is the trusted
session

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent f2f654af19
commit 1db9c8b344

@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN
if (transcript.isEndSessionMessage) { if (transcript.isEndSessionMessage) {
DDLogInfo(@"%@ EndSession was sent to recipient: %@.", self.tag, transcript.recipientId); DDLogInfo(@"%@ EndSession was sent to recipient: %@.", self.tag, transcript.recipientId);
[self.storageManager deleteAllSessionsForContact:transcript.recipientId]; [self.storageManager archiveAllSessionsForContact:transcript.recipientId];
[[[TSInfoMessage alloc] initWithTimestamp:transcript.timestamp [[[TSInfoMessage alloc] initWithTimestamp:transcript.timestamp
inThread:transcript.thread inThread:transcript.thread
messageType:TSInfoMessageTypeSessionDidEnd] save]; messageType:TSInfoMessageTypeSessionDidEnd] save];

@ -721,7 +721,7 @@ NS_ASSUME_NONNULL_BEGIN
}]; }];
dispatch_async([OWSDispatch sessionStoreQueue], ^{ dispatch_async([OWSDispatch sessionStoreQueue], ^{
[[TSStorageManager sharedManager] deleteAllSessionsForContact:endSessionEnvelope.source]; [[TSStorageManager sharedManager] archiveAllSessionsForContact:endSessionEnvelope.source];
}); });
} }

@ -7,6 +7,8 @@
@interface TSStorageManager (SessionStore) <SessionStore> @interface TSStorageManager (SessionStore) <SessionStore>
- (void)archiveAllSessionsForContact:(NSString *)contactIdentifier;
#pragma mark - debug #pragma mark - debug
- (void)printAllSessions; - (void)printAllSessions;

@ -3,6 +3,7 @@
// //
#import "TSStorageManager+SessionStore.h" #import "TSStorageManager+SessionStore.h"
#import <AxolotlKit/SessionRecord.h>
NSString *const TSStorageManagerSessionStoreCollection = @"TSStorageManagerSessionStoreCollection"; NSString *const TSStorageManagerSessionStoreCollection = @"TSStorageManagerSessionStoreCollection";
NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey"; NSString *const kSessionStoreDBConnectionKey = @"kSessionStoreDBConnectionKey";
@ -158,6 +159,35 @@ void AssertIsOnSessionStoreQueue()
}]; }];
} }
- (void)archiveAllSessionsForContact:(NSString *)contactIdentifier
{
AssertIsOnSessionStoreQueue();
DDLogInfo(@"[TSStorageManager (SessionStore)] archiving all sessions for contact: %@", contactIdentifier);
__block NSDictionary<NSNumber *, SessionRecord *> *sessionRecords;
[self.sessionDBConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
sessionRecords =
[transaction objectForKey:contactIdentifier inCollection:TSStorageManagerSessionStoreCollection];
for (id deviceId in sessionRecords) {
id object = sessionRecords[deviceId];
if (![object isKindOfClass:[SessionRecord class]]) {
OWSFail(@"Unexpected object in session dict: %@", object);
continue;
}
SessionRecord *sessionRecord = (SessionRecord *)object;
[sessionRecord archiveCurrentState];
}
[transaction setObject:sessionRecords
forKey:contactIdentifier
inCollection:TSStorageManagerSessionStoreCollection];
}];
}
#pragma mark - debug #pragma mark - debug
- (void)printAllSessions - (void)printAllSessions

Loading…
Cancel
Save