From 36601e4bbeac575782167e4d482dd77e73b8ae30 Mon Sep 17 00:00:00 2001 From: Nora Trapp Date: Sat, 16 Jan 2021 17:41:58 -0800 Subject: [PATCH] Don't archive sessions when they are fresh. --- AxolotlKit/Classes/Sessions/SessionRecord.m | 4 ++++ AxolotlKit/Classes/Sessions/SessionState.h | 2 ++ AxolotlKit/Classes/Sessions/SessionState.m | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/AxolotlKit/Classes/Sessions/SessionRecord.m b/AxolotlKit/Classes/Sessions/SessionRecord.m index 3e945be..404b653 100644 --- a/AxolotlKit/Classes/Sessions/SessionRecord.m +++ b/AxolotlKit/Classes/Sessions/SessionRecord.m @@ -86,6 +86,10 @@ } - (void)archiveCurrentState{ + if (self.sessionState.isFresh) { + OWSLogInfo(@"Skipping archive, current session state is fresh."); + return; + } [self promoteState:[SessionState new]]; } diff --git a/AxolotlKit/Classes/Sessions/SessionState.h b/AxolotlKit/Classes/Sessions/SessionState.h index 2344b05..1035264 100644 --- a/AxolotlKit/Classes/Sessions/SessionState.h +++ b/AxolotlKit/Classes/Sessions/SessionState.h @@ -39,6 +39,8 @@ @property(nonatomic)int remoteRegistrationId; @property(nonatomic)int localRegistrationId; +@property (nonatomic, readonly) BOOL isFresh; + - (NSData*)senderRatchetKey; - (ECKeyPair*)senderRatchetKeyPair; diff --git a/AxolotlKit/Classes/Sessions/SessionState.m b/AxolotlKit/Classes/Sessions/SessionState.m index e501133..cabcd73 100644 --- a/AxolotlKit/Classes/Sessions/SessionState.m +++ b/AxolotlKit/Classes/Sessions/SessionState.m @@ -119,6 +119,11 @@ static NSString* const kCoderPendingPrekey = @"kCoderPendingPrekey"; [aCoder encodeObject:self.pendingPreKey forKey:kCoderPendingPrekey]; } +- (BOOL)isFresh +{ + return self.remoteIdentityKey == nil && self.localIdentityKey == nil && self.sendingChain == nil && self.receivingChains.count == 0 && self.pendingPreKey == nil; +} + - (NSData*)senderRatchetKey{ return [[self senderRatchetKeyPair] publicKey]; }