From bf6f0131536a685e6e2d00be532e6485c3a30e65 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 25 Apr 2017 10:57:59 -0400 Subject: [PATCH] debug tool: print signed prekey report Example output: SignedPreKeys Report: currentId: 111111111 firstPrekeyUpdateFailureDate: (null) prekeyUpdateFailureCount: 0 All Keys (count: 2): #1 #2 // FREEBIE --- .../TSStorageManager+SignedPreKeyStore.h | 4 ++ .../TSStorageManager+SignedPreKeyStore.m | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.h b/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.h index 0297f23a4..27b4d802f 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.h +++ b/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.h @@ -30,6 +30,10 @@ extern NSString *const TSStorageManagerSignedPreKeyStoreCollection; - (void)setFirstPrekeyUpdateFailureDate:(nonnull NSDate *)value; - (void)clearFirstPrekeyUpdateFailureDate; +#pragma mark - Debugging + +- (void)logSignedPreKeyReport; + @end NS_ASSUME_NONNULL_END diff --git a/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m b/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m index 9684d06c1..ed9ffc848 100644 --- a/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m +++ b/src/Storage/AxolotlStore/TSStorageManager+SignedPreKeyStore.m @@ -137,6 +137,53 @@ NSString *const TSStorageManagerKeyPrekeyCurrentSignedPrekeyId = @"currentSigned inCollection:TSStorageManagerSignedPreKeyMetadataCollection]; } +#pragma mark - Debugging + +- (void)logSignedPreKeyReport +{ + NSString *tag = @"[TSStorageManager (SignedPreKeyStore)]"; + + NSNumber *currentId = [self currentSignedPrekeyId]; + NSDate *firstPrekeyUpdateFailureDate = [self firstPrekeyUpdateFailureDate]; + NSUInteger prekeyUpdateFailureCount = [self prekeyUpdateFailureCount]; + + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + __block int i = 0; + + DDLogInfo(@"%@ SignedPreKeys Report:", tag); + DDLogInfo(@"%@ currentId: %@", tag, currentId); + DDLogInfo(@"%@ firstPrekeyUpdateFailureDate: %@", tag, firstPrekeyUpdateFailureDate); + DDLogInfo(@"%@ prekeyUpdateFailureCount: %d", tag, prekeyUpdateFailureCount); + + NSUInteger count = [transaction numberOfKeysInCollection:TSStorageManagerSignedPreKeyStoreCollection]; + DDLogInfo(@"%@ All Keys (count: %lu):", tag, (unsigned long)count); + + [transaction + enumerateKeysAndObjectsInCollection:TSStorageManagerSignedPreKeyStoreCollection + usingBlock:^( + NSString *_Nonnull key, id _Nonnull signedPreKeyObject, BOOL *_Nonnull stop) { + i++; + if (![signedPreKeyObject isKindOfClass:[SignedPreKeyRecord class]]) { + DDLogError(@"%@ Was expecting SignedPreKeyRecord, but found: %@", + tag, + signedPreKeyObject); + OWSAssert(NO); + return; + } + SignedPreKeyRecord *signedPreKeyRecord + = (SignedPreKeyRecord *)signedPreKeyObject; + DDLogInfo(@"%@ #%d