From ea12ed4c238c74b9f70b05464764a691e22edc08 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 13 Feb 2018 08:31:02 -0800 Subject: [PATCH] Fix dynamic type check which was too restrictive // FREEBIE --- SignalServiceKit/src/Messages/OWSIdentityManager.m | 8 +++++--- SignalServiceKit/src/Messages/OWSMessageSender.m | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSIdentityManager.m b/SignalServiceKit/src/Messages/OWSIdentityManager.m index 6f9cfc9b1..76cc4a8a5 100644 --- a/SignalServiceKit/src/Messages/OWSIdentityManager.m +++ b/SignalServiceKit/src/Messages/OWSIdentityManager.m @@ -154,11 +154,13 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa return identityKeyPair; } +// This method should only be called from SignalProtocolKit, which doesn't know about YapDatabaseTransactions. +// Whenever possible, prefer to call the strongly typed variant: `identityKeyPairWithTransaction:`. - (nullable ECKeyPair *)identityKeyPair:(nullable id)protocolContext { - OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadWriteTransaction class]]); + OWSAssert([protocolContext isKindOfClass:[YapDatabaseReadTransaction class]]); - YapDatabaseReadWriteTransaction *transaction = protocolContext; + YapDatabaseReadTransaction *transaction = protocolContext; return [self identityKeyPairWithTransaction:transaction]; } @@ -449,7 +451,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa OWSAssert(transaction); if ([[TSAccountManager localNumber] isEqualToString:recipientId]) { - ECKeyPair *_Nullable localIdentityKeyPair = [self identityKeyPair:transaction]; + ECKeyPair *_Nullable localIdentityKeyPair = [self identityKeyPairWithTransaction:transaction]; if ([localIdentityKeyPair.publicKey isEqualToData:identityKey]) { return YES; diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index 642835e3f..6d8320b1d 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1328,6 +1328,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } dispatch_semaphore_signal(sema); }]; + // FIXME: Currently this happens within a readwrite transaction - meaning our read-write transaction blocks + // on a network request. dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER); if (exception) { @throw exception;