Respond to CR.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-06-07 17:48:12 -04:00
parent e27e55ca99
commit 0e11566824
5 changed files with 40 additions and 31 deletions

View file

@ -198,8 +198,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *collection, NSString *key, id object, id metadata, NSUInteger index, BOOL *stop) {
if (![object conformsToProtocol:@protocol(OWSReadTracking)]) {
DDLogError(@"%@ Unexpected object in unseen messages: %@", self.tag, object);
OWSFail(@"Unexpected object in unseen messages.");
OWSFail(@"%@ Unexpected object in unseen messages: %@", self.tag, object);
return;
}
[messages addObject:(id<OWSReadTracking>)object];

View file

@ -67,17 +67,17 @@ NS_ASSUME_NONNULL_BEGIN
OWSSignalServiceProtosSyncMessageBuilder *syncMessageBuilder = [OWSSignalServiceProtosSyncMessageBuilder new];
for (OWSVerificationStateTuple *tuple in self.tuples) {
OWSSignalServiceProtosSyncMessageVerificationBuilder *verificationBuilder = [OWSSignalServiceProtosSyncMessageVerificationBuilder new];
[verificationBuilder setDestination:tuple.recipientId];
[verificationBuilder setIdentityKey:tuple.identityKey];
verificationBuilder.destination = tuple.recipientId;
verificationBuilder.identityKey = tuple.identityKey;
switch (tuple.verificationState) {
case OWSVerificationStateDefault:
[verificationBuilder setState:OWSSignalServiceProtosSyncMessageVerificationStateDefault];
verificationBuilder.state = OWSSignalServiceProtosSyncMessageVerificationStateDefault;
break;
case OWSVerificationStateVerified:
[verificationBuilder setState:OWSSignalServiceProtosSyncMessageVerificationStateVerified];
verificationBuilder.state = OWSSignalServiceProtosSyncMessageVerificationStateVerified;
break;
case OWSVerificationStateNoLongerVerified:
[verificationBuilder setState:OWSSignalServiceProtosSyncMessageVerificationStateNoLongerVerified];
verificationBuilder.state = OWSSignalServiceProtosSyncMessageVerificationStateNoLongerVerified;
break;
}
[syncMessageBuilder addVerification:[verificationBuilder build]];
@ -93,8 +93,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(tuple.recipientId.length > 0);
[result addObject:tuple.recipientId];
}
return result;
return [result copy];
}
@end

View file

@ -25,7 +25,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
// We don't store the phone numbers as instances of PhoneNumber to avoid
// consistency issues between clients, but these should all be valid e164
// phone numbers.
@property (nonatomic, readonly) NSMutableSet<NSString *> *blockedPhoneNumberSet;
@property (atomic, readonly) NSMutableSet<NSString *> *blockedPhoneNumberSet;
@end
@ -95,7 +95,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
@synchronized(self)
{
[self lazyLoadBlockedPhoneNumbersIfNecessary];
[self ensureLazyInitialization];
if ([_blockedPhoneNumberSet containsObject:phoneNumber]) {
// Ignore redundant changes.
@ -116,7 +116,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
@synchronized(self)
{
[self lazyLoadBlockedPhoneNumbersIfNecessary];
[self ensureLazyInitialization];
if (![_blockedPhoneNumberSet containsObject:phoneNumber]) {
// Ignore redundant changes.
@ -137,7 +137,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
@synchronized(self)
{
[self lazyLoadBlockedPhoneNumbersIfNecessary];
[self ensureLazyInitialization];
NSSet *newSet = [NSSet setWithArray:blockedPhoneNumbers];
if ([_blockedPhoneNumberSet isEqualToSet:newSet]) {
@ -154,7 +154,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
{
@synchronized(self)
{
[self lazyLoadBlockedPhoneNumbersIfNecessary];
[self ensureLazyInitialization];
return [_blockedPhoneNumberSet.allObjects sortedArrayUsingSelector:@selector(compare:)];
}
@ -202,7 +202,7 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
}
// This method should only be called from within a synchronized block.
- (void)lazyLoadBlockedPhoneNumbersIfNecessary
- (void)ensureLazyInitialization
{
if (_blockedPhoneNumberSet) {
// _blockedPhoneNumberSet has already been loaded, abort.
@ -272,7 +272,10 @@ NSString *const kOWSBlockingManager_SyncedBlockedPhoneNumbersKey = @"kOWSBlockin
{
OWSAssert([NSThread isMainThread]);
[self syncBlockedPhoneNumbersIfNecessary];
@synchronized(self)
{
[self syncBlockedPhoneNumbersIfNecessary];
}
}
#pragma mark - Logging

View file

@ -310,10 +310,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
if ([[self identityKeyPair].publicKey isEqualToData:identityKey]) {
return YES;
} else {
DDLogError(@"%@ Wrong identity: %@ for local key: %@",
DDLogError(@"%@ Wrong identity: %@ for local key: %@, recipientId: %@",
self.tag,
identityKey,
[self identityKeyPair].publicKey);
[self identityKeyPair].publicKey,
recipientId);
OWSAssert(NO);
return NO;
}
@ -448,7 +449,9 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
// We don't want to sync "no longer verified" state. Other clients can
// figure this out from the /profile/ endpoint, and this can cause data
// loss as a user's devices overwrite each other's verification.
OWSFail(@"Queue verification state had unexpected value: %@ recipientId: %@", OWSVerificationStateToString(recipientIdentity.verificationState), recipientId);
OWSFail(@"Queue verification state had unexpected value: %@ recipientId: %@",
OWSVerificationStateToString(recipientIdentity.verificationState),
recipientId);
continue;
}
[message addVerificationState:recipientIdentity.verificationState
@ -531,14 +534,14 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
- (void)processIncomingSyncMessage:(NSArray<OWSSignalServiceProtosSyncMessageVerification *> *)verifications
{
for (OWSSignalServiceProtosSyncMessageVerification *verification in verifications) {
NSString *recipientId = [verification destination];
NSString *recipientId = verification.destination;
if (recipientId.length < 1) {
OWSFail(@"Verification state sync message missing recipientId.");
continue;
}
NSData *identityKey = [verification identityKey];
NSData *identityKey = verification.identityKey;
if (identityKey.length < 1) {
OWSFail(@"Verification state sync message missing identityKey.");
OWSFail(@"Verification state sync message missing identityKey: %@", recipientId);
continue;
}
switch (verification.state) {
@ -573,7 +576,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
return;
}
if (identityKey.length < 1) {
OWSFail(@"Verification state sync message missing identityKey.");
OWSFail(@"Verification state sync message missing identityKey: %@", recipientId);
return;
}
@ -607,7 +610,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
}
if (![recipientIdentity.identityKey isEqualToData:identityKey]) {
OWSFail(@"recipientIdentity has unexpected identityKey");
OWSFail(@"recipientIdentity has unexpected identityKey: %@", recipientId);
return;
}
@ -635,11 +638,11 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
// whose identity key disagrees with the local identity key for
// this recipient.
if (!overwriteOnConflict) {
DDLogWarn(@"recipientIdentity has non-matching identityKey");
DDLogWarn(@"recipientIdentity has non-matching identityKey: %@", recipientId);
return;
}
DDLogWarn(@"recipientIdentity has non-matching identityKey; overwriting.");
DDLogWarn(@"recipientIdentity has non-matching identityKey; overwriting: %@", recipientId);
[self saveRemoteIdentity:identityKey recipientId:recipientId];
recipientIdentity = [OWSRecipientIdentity fetchObjectWithUniqueID:recipientId];
@ -655,7 +658,7 @@ NSString *const kNSNotificationName_IdentityStateDidChange = @"kNSNotificationNa
}
if (![recipientIdentity.identityKey isEqualToData:identityKey]) {
OWSFail(@"recipientIdentity has unexpected identityKey");
OWSFail(@"recipientIdentity has unexpected identityKey: %@", recipientId);
return;
}
}

View file

@ -18,20 +18,23 @@
#define OWSAssert(X) \
if (!(X)) { \
NSLog(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \
DDLogError(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \
[DDLog flushLog]; \
NSAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \
}
#define OWSCAssert(X) \
if (!(X)) { \
NSLog(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \
DDLogError(@"%s Assertion failed: %s", __PRETTY_FUNCTION__, CONVERT_EXPR_TO_STRING(X)); \
[DDLog flushLog]; \
NSCAssert(0, @"Assertion failed: %s", CONVERT_EXPR_TO_STRING(X)); \
}
#define OWSFail(message, ...) \
{ \
NSString *formattedMessage = [NSString stringWithFormat:message, ##__VA_ARGS__]; \
NSLog(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \
DDLogError(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \
[DDLog flushLog]; \
NSAssert(0, formattedMessage); \
}
@ -39,7 +42,8 @@
{ \
if (!(X)) { \
NSString *formattedMessage = [NSString stringWithFormat:message, ##__VA_ARGS__]; \
NSLog(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \
DDLogError(@"%s %@", __PRETTY_FUNCTION__, formattedMessage); \
[DDLog flushLog]; \
NSCAssert(0, formattedMessage); \
}