Instrument network errors.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 117bca7c48
commit 9587aab37b

@ -34,6 +34,10 @@ static NSString *const OWS103EnableVideoCallingMigrationId = @"103";
[self save]; [self save];
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(
@"error_enable_video_calling_request_failed", error);
}
DDLogError(@"%@ failed with error: %@", self.tag, error); DDLogError(@"%@ failed with error: %@", self.tag, error);
}]; }];
}]; }];

@ -115,23 +115,7 @@
return [thisVersionString compare:thatVersionString options:NSNumericSearch] == NSOrderedAscending; return [thisVersionString compare:thatVersionString options:NSNumericSearch] == NSOrderedAscending;
} }
#pragma mark Upgrading to 2.1 - Needs to register VOIP token + Removing video cache folder #pragma mark Upgrading to 2.1 - Removing video cache folder
+ (void)nonBlockingPushRegistration {
void (^failedBlock)(NSError *) = ^(NSError *error) {
DDLogError(@"Failed to register VOIP push token: %@", error.debugDescription);
};
[[PushManager sharedManager] requestPushTokenWithSuccess:^(NSString *pushToken, NSString *voipToken) {
[[TSAccountManager sharedInstance]
registerForPushNotificationsWithPushToken:pushToken
voipToken:voipToken
success:^{
DDLogWarn(@"Registered for VOIP Push.");
}
failure:failedBlock];
}
failure:failedBlock];
}
+ (void)clearVideoCache { + (void)clearVideoCache {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
@ -162,13 +146,16 @@
TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributesWithVoice]; TSUpdateAttributesRequest *request = [[TSUpdateAttributesRequest alloc] initWithUpdatedAttributesWithVoice];
[[TSNetworkManager sharedManager] makeRequest:request [[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) { success:^(NSURLSessionDataTask *task, id responseObject) {
success = YES; success = YES;
dispatch_semaphore_signal(sema); dispatch_semaphore_signal(sema);
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
success = NO; if (!IsNSErrorNetworkFailure(error)) {
DDLogError(@"Updating attributess failed with error: %@", error.description); OWSProdErrorWNSError(@"error_update_attributes_request_failed", error);
dispatch_semaphore_signal(sema); }
success = NO;
DDLogError(@"Updating attributess failed with error: %@", error.description);
dispatch_semaphore_signal(sema);
}]; }];

@ -159,6 +159,9 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
failure:failureHandler failure:failureHandler
remainingRetries:remainingRetries - 1]; remainingRetries:remainingRetries - 1];
} else { } else {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_register_push_tokens_failed", error);
}
failureHandler(error); failureHandler(error);
} }
}]; }];
@ -180,7 +183,7 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
// we make our verification code request. // we make our verification code request.
TSAccountManager *manager = [self sharedInstance]; TSAccountManager *manager = [self sharedInstance];
manager.phoneNumberAwaitingVerification = phoneNumber; manager.phoneNumberAwaitingVerification = phoneNumber;
[[TSNetworkManager sharedManager] [[TSNetworkManager sharedManager]
makeRequest:[[TSRequestVerificationCodeRequest alloc] makeRequest:[[TSRequestVerificationCodeRequest alloc]
initWithPhoneNumber:phoneNumber initWithPhoneNumber:phoneNumber
@ -193,6 +196,9 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
successBlock(); successBlock();
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_verification_code_request_failed", error);
}
DDLogError(@"%@ Failed to request verification code request with error:%@", self.tag, error); DDLogError(@"%@ Failed to request verification code request with error:%@", self.tag, error);
failureBlock(error); failureBlock(error);
}]; }];
@ -263,6 +269,9 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
} }
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_verify_account_request_failed", error);
}
DDLogWarn(@"%@ Error verifying code: %@", self.tag, error.debugDescription); DDLogWarn(@"%@ Error verifying code: %@", self.tag, error.debugDescription);
switch (error.code) { switch (error.code) {
case 403: { case 403: {
@ -316,6 +325,9 @@ NSString *const kNSNotificationName_LocalNumberDidChange = @"kNSNotificationName
userInfo:nil]; userInfo:nil];
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"accounts_error_unregister_account_request_failed", error);
}
DDLogError(@"%@ Failed to unregister with error: %@", self.tag, error); DDLogError(@"%@ Failed to unregister with error: %@", self.tag, error);
failureBlock(error); failureBlock(error);
}]; }];

@ -181,10 +181,12 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
[TSPreKeyManager clearPreKeyUpdateFailureCount]; [TSPreKeyManager clearPreKeyUpdateFailureCount];
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (modeCopy == RefreshPreKeysMode_SignedAndOneTime) { if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_prekeys_update_failed_signed_and_onetime", error); if (modeCopy == RefreshPreKeysMode_SignedAndOneTime) {
} else { OWSProdErrorWNSError(@"error_prekeys_update_failed_signed_and_onetime", error);
OWSProdErrorWNSError(@"error_prekeys_update_failed_just_signed", error); } else {
OWSProdErrorWNSError(@"error_prekeys_update_failed_just_signed", error);
}
} }
// Mark the prekeys as _NOT_ checked on failure. // Mark the prekeys as _NOT_ checked on failure.
@ -302,6 +304,9 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
} }
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_prekeys_current_signed_prekey_request_failed", error);
}
DDLogWarn(@"%@ Could not retrieve current signed key from the service.", self.tag); DDLogWarn(@"%@ Could not retrieve current signed key from the service.", self.tag);
// Mark the prekeys as _NOT_ checked on failure. // Mark the prekeys as _NOT_ checked on failure.
@ -310,6 +315,9 @@ static const NSTimeInterval kSignedPreKeyUpdateFailureMaxFailureDuration = 10 *
} }
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_prekeys_available_prekeys_request_failed", error);
}
DDLogError(@"%@ Failed to retrieve the number of available prekeys.", self.tag); DDLogError(@"%@ Failed to retrieve the number of available prekeys.", self.tag);
// Mark the prekeys as _NOT_ checked on failure. // Mark the prekeys as _NOT_ checked on failure.

@ -166,45 +166,49 @@ NS_ASSUME_NONNULL_BEGIN
TSRequest *request = [[TSContactsIntersectionRequest alloc] initWithHashesArray:hashes]; TSRequest *request = [[TSContactsIntersectionRequest alloc] initWithHashesArray:hashes];
[[TSNetworkManager sharedManager] makeRequest:request [[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *tsTask, id responseDict) { success:^(NSURLSessionDataTask *tsTask, id responseDict) {
NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary]; NSMutableDictionary *attributesForIdentifier = [NSMutableDictionary dictionary];
NSArray *contactsArray = [(NSDictionary *)responseDict objectForKey:@"contacts"]; NSArray *contactsArray = [(NSDictionary *)responseDict objectForKey:@"contacts"];
// Map attributes to phone numbers // Map attributes to phone numbers
if (contactsArray) { if (contactsArray) {
for (NSDictionary *dict in contactsArray) { for (NSDictionary *dict in contactsArray) {
NSString *hash = [dict objectForKey:@"token"]; NSString *hash = [dict objectForKey:@"token"];
NSString *identifier = [phoneNumbersByHashes objectForKey:hash]; NSString *identifier = [phoneNumbersByHashes objectForKey:hash];
if (!identifier) { if (!identifier) {
DDLogWarn(@"%@ An interesecting hash wasn't found in the mapping.", self.tag); DDLogWarn(@"%@ An interesecting hash wasn't found in the mapping.", self.tag);
break; break;
} }
[attributesForIdentifier setObject:dict forKey:identifier]; [attributesForIdentifier setObject:dict forKey:identifier];
} }
} }
// Insert or update contact attributes // Insert or update contact attributes
[[TSStorageManager sharedManager].dbReadWriteConnection [[TSStorageManager sharedManager].dbReadWriteConnection
readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
for (NSString *identifier in attributesForIdentifier) { for (NSString *identifier in attributesForIdentifier) {
SignalRecipient *recipient = SignalRecipient *recipient = [SignalRecipient recipientWithTextSecureIdentifier:identifier
[SignalRecipient recipientWithTextSecureIdentifier:identifier withTransaction:transaction]; withTransaction:transaction];
if (!recipient) { if (!recipient) {
recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:identifier relay:nil]; recipient = [[SignalRecipient alloc] initWithTextSecureIdentifier:identifier relay:nil];
} }
NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier]; NSDictionary *attributes = [attributesForIdentifier objectForKey:identifier];
recipient.relay = attributes[@"relay"]; recipient.relay = attributes[@"relay"];
[recipient saveWithTransaction:transaction]; [recipient saveWithTransaction:transaction];
} }
}]; }];
success([NSSet setWithArray:attributesForIdentifier.allKeys]); success([NSSet setWithArray:attributesForIdentifier.allKeys]);
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"contacts_error_contacts_intersection_failed", error);
}
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
if (response.statusCode == 413) { if (response.statusCode == 413) {
failure(OWSErrorWithCodeDescription( failure(OWSErrorWithCodeDescription(

@ -143,67 +143,68 @@ static const CGFloat kAttachmentDownloadProgressTheta = 0.001f;
TSAttachmentRequest *attachmentRequest = [[TSAttachmentRequest alloc] initWithId:attachment.serverId relay:attachment.relay]; TSAttachmentRequest *attachmentRequest = [[TSAttachmentRequest alloc] initWithId:attachment.serverId relay:attachment.relay];
[self.networkManager makeRequest:attachmentRequest [self.networkManager makeRequest:attachmentRequest
success:^(NSURLSessionDataTask *task, id responseObject) { success:^(NSURLSessionDataTask *task, id responseObject) {
if (![responseObject isKindOfClass:[NSDictionary class]]) { if (![responseObject isKindOfClass:[NSDictionary class]]) {
DDLogError(@"%@ Failed retrieval of attachment. Response had unexpected format.", DDLogError(@"%@ Failed retrieval of attachment. Response had unexpected format.", self.tag);
self.tag); NSError *error = OWSErrorMakeUnableToProcessServerResponseError();
NSError *error = OWSErrorMakeUnableToProcessServerResponseError(); return markAndHandleFailure(error);
return markAndHandleFailure(error); }
} NSString *location = [(NSDictionary *)responseObject objectForKey:@"location"];
NSString *location = [(NSDictionary *)responseObject objectForKey:@"location"]; if (!location) {
if (!location) { DDLogError(@"%@ Failed retrieval of attachment. Response had no location.", self.tag);
DDLogError( NSError *error = OWSErrorMakeUnableToProcessServerResponseError();
@"%@ Failed retrieval of attachment. Response had no location.", self.tag); return markAndHandleFailure(error);
NSError *error = OWSErrorMakeUnableToProcessServerResponseError(); }
return markAndHandleFailure(error);
} dispatch_async([OWSDispatch attachmentsQueue], ^{
[self downloadFromLocation:location
dispatch_async([OWSDispatch attachmentsQueue], ^{ pointer:attachment
[self downloadFromLocation:location success:^(NSData *_Nonnull encryptedData) {
pointer:attachment [self decryptAttachmentData:encryptedData
success:^(NSData *_Nonnull encryptedData) { pointer:attachment
[self decryptAttachmentData:encryptedData success:markAndHandleSuccess
pointer:attachment failure:markAndHandleFailure];
success:markAndHandleSuccess }
failure:markAndHandleFailure]; failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) {
} if (attachment.serverId < 100) {
failure:^(NSURLSessionDataTask *_Nullable task, NSError *_Nonnull error) { // This looks like the symptom of the "frequent 404
if (attachment.serverId < 100) { // downloading attachments with low server ids".
// This looks like the symptom of the "frequent 404 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
// downloading attachments with low server ids". NSInteger statusCode = [httpResponse statusCode];
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response; DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@",
NSInteger statusCode = [httpResponse statusCode]; self.tag,
DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@", (int)statusCode,
self.tag, (unsigned long long)attachment.serverId,
(int)statusCode, error);
(unsigned long long)attachment.serverId, [DDLog flushLog];
error); OWSAssert(0);
[DDLog flushLog]; }
OWSAssert(0); if (markAndHandleFailure) {
} markAndHandleFailure(error);
if (markAndHandleFailure) { }
markAndHandleFailure(error); }];
} });
}]; }
}); failure:^(NSURLSessionDataTask *task, NSError *error) {
} if (!IsNSErrorNetworkFailure(error)) {
failure:^(NSURLSessionDataTask *task, NSError *error) { OWSProdErrorWNSError(@"error_attachment_request_failed", error);
DDLogError(@"Failed retrieval of attachment with error: %@", error); }
if (attachment.serverId < 100) { DDLogError(@"Failed retrieval of attachment with error: %@", error);
// This _shouldn't_ be the symptom of the "frequent 404 if (attachment.serverId < 100) {
// downloading attachments with low server ids". // This _shouldn't_ be the symptom of the "frequent 404
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response; // downloading attachments with low server ids".
NSInteger statusCode = [httpResponse statusCode]; NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)task.response;
DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@", NSInteger statusCode = [httpResponse statusCode];
self.tag, DDLogError(@"%@ %d Failure with suspicious attachment id: %llu, %@",
(int)statusCode, self.tag,
(unsigned long long)attachment.serverId, (int)statusCode,
error); (unsigned long long)attachment.serverId,
[DDLog flushLog]; error);
OWSAssert(0); [DDLog flushLog];
} OWSAssert(0);
return markAndHandleFailure(error); }
}]; return markAndHandleFailure(error);
}];
} }
- (void)decryptAttachmentData:(NSData *)cipherText - (void)decryptAttachmentData:(NSData *)cipherText

@ -1216,6 +1216,9 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
dispatch_semaphore_signal(sema); dispatch_semaphore_signal(sema);
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"message_sender_error_recipient_prekey_request_failed", error);
}
DDLogError(@"Server replied to PreKeyBundle request with error: %@", error); DDLogError(@"Server replied to PreKeyBundle request with error: %@", error);
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
if (response.statusCode == 404) { if (response.statusCode == 404) {

@ -1,4 +1,6 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningCodeService.h" #import "OWSDeviceProvisioningCodeService.h"
#import "OWSDeviceProvisioningCodeRequest.h" #import "OWSDeviceProvisioningCodeRequest.h"
@ -48,6 +50,9 @@ NSString *const OWSDeviceProvisioningCodeServiceProvisioningCodeKey = @"verifica
} }
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_provisioning_code_request_failed", error);
}
DDLogVerbose(@"ProvisioningCode request failed with error: %@", error); DDLogVerbose(@"ProvisioningCode request failed with error: %@", error);
failureCallback(error); failureCallback(error);
}]; }];

@ -1,4 +1,6 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningService.h" #import "OWSDeviceProvisioningService.h"
#import "OWSDeviceProvisioningRequest.h" #import "OWSDeviceProvisioningRequest.h"
@ -45,6 +47,9 @@ NS_ASSUME_NONNULL_BEGIN
successCallback(); successCallback();
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_provisioning_request_failed", error);
}
DDLogVerbose(@"Provisioning request failed with error: %@", error); DDLogVerbose(@"Provisioning request failed with error: %@", error);
failureCallback(error); failureCallback(error);
}]; }];

@ -1,4 +1,6 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "OWSDevicesService.h" #import "OWSDevicesService.h"
#import "OWSDeleteDeviceRequest.h" #import "OWSDeleteDeviceRequest.h"
@ -30,6 +32,9 @@ NS_ASSUME_NONNULL_BEGIN
} }
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_get_devices_failed", error);
}
DDLogVerbose(@"Get devices request failed with error: %@", error); DDLogVerbose(@"Get devices request failed with error: %@", error);
failureCallback(error); failureCallback(error);
}]; }];
@ -47,6 +52,9 @@ NS_ASSUME_NONNULL_BEGIN
successCallback(); successCallback();
} }
failure:^(NSURLSessionDataTask *task, NSError *error) { failure:^(NSURLSessionDataTask *task, NSError *error) {
if (!IsNSErrorNetworkFailure(error)) {
OWSProdErrorWNSError(@"error_unlink_device_failed", error);
}
DDLogVerbose(@"Get devices request failed with error: %@", error); DDLogVerbose(@"Get devices request failed with error: %@", error);
failureCallback(error); failureCallback(error);
}]; }];

@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString *const TSNetworkManagerDomain; extern NSString *const TSNetworkManagerDomain;
BOOL IsNSErrorNetworkFailure(NSError *_Nullable error);
@interface TSNetworkManager : NSObject @interface TSNetworkManager : NSObject
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;

@ -12,6 +12,11 @@
NSString *const TSNetworkManagerDomain = @"org.whispersystems.signal.networkManager"; NSString *const TSNetworkManagerDomain = @"org.whispersystems.signal.networkManager";
BOOL IsNSErrorNetworkFailure(NSError *_Nullable error)
{
return ([error.domain isEqualToString:TSNetworkManagerDomain] && error.code == 0);
}
@interface TSNetworkManager () @interface TSNetworkManager ()
typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error); typedef void (^failureBlock)(NSURLSessionDataTask *task, NSError *error);

Loading…
Cancel
Save