Clean up logging & documentation

pull/105/head
Niels Andriesse 5 years ago
parent 85083d1969
commit 0c18e82524

@ -1 +1 @@
Subproject commit 0454d60e8db0ebe90ba21ee23d66b2a1e4ab0543 Subproject commit 6fae72d48c06c35c8219ebfc58116450c473b8f1

@ -3919,8 +3919,6 @@ typedef enum : NSUInteger {
- (void)tryToSendAttachments:(NSArray<SignalAttachment *> *)attachments messageText:(NSString *_Nullable)messageText - (void)tryToSendAttachments:(NSArray<SignalAttachment *> *)attachments messageText:(NSString *_Nullable)messageText
{ {
OWSLogError(@"");
DispatchMainThreadSafe(^{ DispatchMainThreadSafe(^{
__weak ConversationViewController *weakSelf = self; __weak ConversationViewController *weakSelf = self;
if ([self isBlockedConversation]) { if ([self isBlockedConversation]) {

@ -180,7 +180,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
[SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI]; [SignalAttachment attachmentWithDataSource:dataSource dataUTI:kOversizeTextAttachmentUTI];
attachments = [mediaAttachments arrayByAddingObject:oversizeTextAttachment]; attachments = [mediaAttachments arrayByAddingObject:oversizeTextAttachment];
} else { } else {
OWSFailDebug(@"dataSource was unexpectedly nil"); OWSFailDebug(@"dataSource was unexpectedly nil.");
} }
} }
@ -232,8 +232,7 @@ typedef void (^BuildOutgoingMessageCompletionBlock)(TSOutgoingMessage *savedMess
NSMutableArray<OWSOutgoingAttachmentInfo *> *attachmentInfos = [NSMutableArray new]; NSMutableArray<OWSOutgoingAttachmentInfo *> *attachmentInfos = [NSMutableArray new];
for (SignalAttachment *attachment in attachments) { for (SignalAttachment *attachment in attachments) {
OWSOutgoingAttachmentInfo *attachmentInfo = OWSOutgoingAttachmentInfo *attachmentInfo = [attachment buildOutgoingAttachmentInfoWithMessage:message];
[attachment buildOutgoingAttachmentInfoWithMessage:message];
[attachmentInfos addObject:attachmentInfo]; [attachmentInfos addObject:attachmentInfo];
} }
completionBlock(message, attachmentInfos, writeTransaction); completionBlock(message, attachmentInfos, writeTransaction);

@ -759,14 +759,10 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
[self applyChangeToSelfAndLatestCopy:transaction [self applyChangeToSelfAndLatestCopy:transaction
changeBlock:^(TSOutgoingMessage *message) { changeBlock:^(TSOutgoingMessage *message) {
TSOutgoingMessageRecipientState *_Nullable recipientState TSOutgoingMessageRecipientState *_Nullable recipientState = message.recipientStateMap[recipientId];
= message.recipientStateMap[recipientId]; if (!recipientState) { return; }
if (!recipientState) {
// OWSFailDebug(@"Missing recipient state for delivered recipient: %@", recipientId);
return;
}
if (recipientState.state != OWSOutgoingMessageRecipientStateSent) { if (recipientState.state != OWSOutgoingMessageRecipientStateSent) {
OWSLogWarn(@"marking unsent message as delivered."); OWSLogWarn(@"Marking unsent message as delivered.");
} }
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.readTimestamp = @(readTimestamp); recipientState.readTimestamp = @(readTimestamp);

@ -186,9 +186,7 @@ void AssertIsOnSendingQueue()
- (nullable NSError *)checkForPreconditionError - (nullable NSError *)checkForPreconditionError
{ {
__block NSError *_Nullable error = [super checkForPreconditionError]; __block NSError *_Nullable error = [super checkForPreconditionError];
if (error) { if (error) { return error; }
return error;
}
// Sanity check preconditions // Sanity check preconditions
if (self.message.hasAttachments) { if (self.message.hasAttachments) {
@ -214,9 +212,8 @@ void AssertIsOnSendingQueue()
{ {
// If the message has been deleted, abort send. // If the message has been deleted, abort send.
if (self.message.shouldBeSaved && ![TSOutgoingMessage fetchObjectWithUniqueID:self.message.uniqueId]) { if (self.message.shouldBeSaved && ![TSOutgoingMessage fetchObjectWithUniqueID:self.message.uniqueId]) {
OWSLogInfo(@"aborting message send; message deleted."); OWSLogInfo(@"Aborting message send; message deleted.");
NSError *error = OWSErrorWithCodeDescription( NSError *error = OWSErrorWithCodeDescription(OWSErrorCodeMessageDeletedBeforeSent, @"Message was deleted before it could be sent.");
OWSErrorCodeMessageDeletedBeforeSent, @"Message was deleted before it could be sent.");
error.isFatal = YES; error.isFatal = YES;
[self reportError:error]; [self reportError:error];
return; return;
@ -233,16 +230,12 @@ void AssertIsOnSendingQueue()
- (void)didSucceed - (void)didSucceed
{ {
if (self.message.messageState != TSOutgoingMessageStateSent) {
// OWSFailDebug(@"unexpected message status: %@", self.message.statusDescription);
}
self.successHandler(); self.successHandler();
} }
- (void)didFailWithError:(NSError *)error - (void)didFailWithError:(NSError *)error
{ {
OWSLogError(@"failed with error: %@", error); OWSLogError(@"Message failed to send due to error: %@.", error);
self.failureHandler(error); self.failureHandler(error);
} }
@ -373,7 +366,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// is complete. For example, we wouldn't want to auto-reply to a // is complete. For example, we wouldn't want to auto-reply to a
// group info request before that group info request's batch was // group info request before that group info request's batch was
// finished processing. Otherwise, we might receive a delivery // finished processing. Otherwise, we might receive a delivery
// notice for a group update we hadn't yet saved to the db. // notice for a group update we hadn't yet saved to the database.
// //
// So we're using YDB behavior to ensure this invariant, which is a bit // So we're using YDB behavior to ensure this invariant, which is a bit
// unorthodox. // unorthodox.
@ -634,7 +627,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
successHandlerParam(); successHandlerParam();
} }
failure:^(NSError *error) { failure:^(NSError *error) {
OWSLogError(@"Error sending sync message for message: %@ timestamp: %llu", OWSLogError(@"Error sending sync message for message: %@ timestamp: %llu.",
message.class, message.class,
message.timestamp); message.timestamp);
@ -650,13 +643,12 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
failureHandlerParam(error); failureHandlerParam(error);
} }
failure:^(NSError *syncError) { failure:^(NSError *syncError) {
OWSLogError(@"Error sending sync message for message: %@ timestamp: %llu, %@", OWSLogError(@"Error sending sync message for message: %@ timestamp: %llu, %@.",
message.class, message.class,
message.timestamp, message.timestamp,
syncError); syncError);
// Discard the "sync message" error in favor of the // Discard the sync message error in favor of the original error
// original error.
failureHandlerParam(error); failureHandlerParam(error);
}]; }];
}); });
@ -1046,7 +1038,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return messageSend.success(); return messageSend.success();
} }
OWSLogInfo(@"attempting to send message: %@, timestamp: %llu, recipient: %@", OWSLogInfo(@"Attempting to send message: %@, timestamp: %llu, recipient: %@.",
message.class, message.class,
message.timestamp, message.timestamp,
recipient.uniqueId); recipient.uniqueId);
@ -1062,13 +1054,13 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// re-enable message sending. // re-enable message sending.
[TSPreKeyManager [TSPreKeyManager
rotateSignedPreKeyWithSuccess:^{ rotateSignedPreKeyWithSuccess:^{
OWSLogInfo(@"New prekeys registered with server."); OWSLogInfo(@"New pre keys registered with server.");
NSError *error = OWSErrorMakeMessageSendDisabledDueToPreKeyUpdateFailuresError(); NSError *error = OWSErrorMakeMessageSendDisabledDueToPreKeyUpdateFailuresError();
[error setIsRetryable:YES]; [error setIsRetryable:YES];
return messageSend.failure(error); return messageSend.failure(error);
} }
failure:^(NSError *error) { failure:^(NSError *error) {
OWSLogWarn(@"Failed to update prekeys with the server: %@", error); OWSLogWarn(@"Failed to update pre keys with the server due to error: %@.", error);
return messageSend.failure(error); return messageSend.failure(error);
}]; }];
} }
@ -1191,16 +1183,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// Loki: TSFriendRequestMessageType represents a Loki friend request // Loki: TSFriendRequestMessageType represents a Loki friend request
NSArray *validMessageTypes = @[ @(TSEncryptedWhisperMessageType), @(TSPreKeyWhisperMessageType), @(TSFriendRequestMessageType) ]; NSArray *validMessageTypes = @[ @(TSEncryptedWhisperMessageType), @(TSPreKeyWhisperMessageType), @(TSFriendRequestMessageType) ];
hasValidMessageType = [validMessageTypes containsObject:messageType]; hasValidMessageType = [validMessageTypes containsObject:messageType];
/* Loki: Original code
* ========
hasValidMessageType = ([messageType isEqualToNumber:@(TSEncryptedWhisperMessageType)] || [messageType isEqualToNumber:@(TSPreKeyWhisperMessageType)]);
* ========
*/
} }
if (!hasValidMessageType) { if (!hasValidMessageType) {
OWSFailDebug(@"Invalid message type: %@", messageType); OWSFailDebug(@"Invalid message type: %@.", messageType);
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
[error setIsRetryable:NO]; [error setIsRetryable:NO];
return messageSend.failure(error); return messageSend.failure(error);
@ -1286,7 +1272,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}]; }];
[self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false]; [self messageSendDidSucceed:messageSend deviceMessages:deviceMessages wasSentByUD:messageSend.isUDSend wasSentByWebsocket:false];
}) })
.catchOn(OWSDispatch.sendingQueue, ^(NSError *error) { // The snode is unreachable .catchOn(OWSDispatch.sendingQueue, ^(NSError *error) {
failedMessageSend(error); failedMessageSend(error);
}) retainUntilComplete]; }) retainUntilComplete];
} else { } else {
@ -1342,7 +1328,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// Handle the error // Handle the error
failedMessageSend(error); failedMessageSend(error);
}; };
// Send the message using the Loki API // Send the message
[[LKAPI sendSignalMessage:signalMessage onP2PSuccess:onP2PSuccess] [[LKAPI sendSignalMessage:signalMessage onP2PSuccess:onP2PSuccess]
.thenOn(OWSDispatch.sendingQueue, ^(id result) { .thenOn(OWSDispatch.sendingQueue, ^(id result) {
NSSet<AnyPromise *> *promises = (NSSet<AnyPromise *> *)result; NSSet<AnyPromise *> *promises = (NSSet<AnyPromise *> *)result;
@ -1718,12 +1704,11 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSData *_Nullable plainText = [messageSend.message buildPlainTextData:recipient]; NSData *_Nullable plainText = [messageSend.message buildPlainTextData:recipient];
if (!plainText) { if (!plainText) {
OWSRaiseException(InvalidMessageException, @"Failed to build message proto"); OWSRaiseException(InvalidMessageException, @"Failed to build message proto.");
} }
OWSLogDebug( OWSLogDebug(@"Built message: %@ plainTextData.length: %lu", [messageSend.message class], (unsigned long)plainText.length);
@"built message: %@ plainTextData.length: %lu", [messageSend.message class], (unsigned long)plainText.length);
OWSLogVerbose(@"building device messages for: %@ %@ (isLocalNumber: %d, isUDSend: %d)", OWSLogVerbose(@"Building device messages for: %@ %@ (isLocalNumber: %d, isUDSend: %d).",
recipient.recipientId, recipient.recipientId,
recipient.devices, recipient.devices,
messageSend.isLocalNumber, messageSend.isLocalNumber,
@ -1737,7 +1722,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// This may involve blocking network requests, so we do it _before_ // This may involve blocking network requests, so we do it _before_
// we open a transaction. // we open a transaction.
// Loki: Both for friend request messages and device link messages we don't require a session // Loki: We don't require a session for friend requests, session requests and device link requests
BOOL isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class]; BOOL isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class];
BOOL isSessionRequest = [messageSend.message isKindOfClass:LKSessionRequestMessage.class]; BOOL isSessionRequest = [messageSend.message isKindOfClass:LKSessionRequestMessage.class];
BOOL isDeviceLinkMessage = [messageSend.message isKindOfClass:LKDeviceLinkMessage.class]; BOOL isDeviceLinkMessage = [messageSend.message isKindOfClass:LKDeviceLinkMessage.class];
@ -1760,14 +1745,14 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}]; }];
if (encryptionException) { if (encryptionException) {
OWSLogInfo(@"Exception during encryption: %@", encryptionException); OWSLogInfo(@"Exception during encryption: %@.", encryptionException);
@throw encryptionException; @throw encryptionException;
} }
if (messageDict) { if (messageDict) {
[messagesArray addObject:messageDict]; [messagesArray addObject:messageDict];
} else { } else {
OWSRaiseException(InvalidMessageException, @"Failed to encrypt message"); OWSRaiseException(InvalidMessageException, @"Failed to encrypt message.");
} }
} @catch (NSException *exception) { } @catch (NSException *exception) {
if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) { if ([exception.name isEqualToString:OWSMessageSenderInvalidDeviceException]) {
@ -1984,16 +1969,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
OWSPrimaryStorage *storage = self.primaryStorage; OWSPrimaryStorage *storage = self.primaryStorage;
TSOutgoingMessage *message = messageSend.message; TSOutgoingMessage *message = messageSend.message;
// Loki: Both for friend request messages and device link messages we use fallback encryption as we don't necessarily have a session yet // Loki: Use fallback encryption for friend requests, session requests and device link requests
BOOL isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class]; BOOL isFriendRequest = [messageSend.message isKindOfClass:LKFriendRequestMessage.class];
BOOL isSessionRequest = [messageSend.message isKindOfClass:LKSessionRequestMessage.class]; BOOL isSessionRequest = [messageSend.message isKindOfClass:LKSessionRequestMessage.class];
BOOL isDeviceLinkMessage = [messageSend.message isKindOfClass:LKDeviceLinkMessage.class] && ((LKDeviceLinkMessage *)messageSend.message).kind == LKDeviceLinkMessageKindRequest; BOOL isDeviceLinkMessage = [messageSend.message isKindOfClass:LKDeviceLinkMessage.class] && ((LKDeviceLinkMessage *)messageSend.message).kind == LKDeviceLinkMessageKindRequest;
// This may throw an exception. // This may throw an exception
if (!isFriendRequest && !isSessionRequest && !isDeviceLinkMessage && ![storage containsSession:recipientID deviceId:@(OWSDevicePrimaryDeviceId).intValue protocolContext:transaction]) { if (!isFriendRequest && !isSessionRequest && !isDeviceLinkMessage && ![storage containsSession:recipientID deviceId:@(OWSDevicePrimaryDeviceId).intValue protocolContext:transaction]) {
NSString *missingSessionException = @"missingSessionException"; NSString *missingSessionException = @"missingSessionException";
OWSRaiseException(missingSessionException, OWSRaiseException(missingSessionException,
@"Unexpectedly missing session for recipient: %@, device: %@", @"Unexpectedly missing session for recipient: %@, device: %@.",
recipientID, recipientID,
@(OWSDevicePrimaryDeviceId)); @(OWSDevicePrimaryDeviceId));
} }
@ -2026,14 +2011,15 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
protocolContext:transaction protocolContext:transaction
isFriendRequest:isFriendRequest || isDeviceLinkMessage isFriendRequest:isFriendRequest || isDeviceLinkMessage
error:&error]; error:&error];
SCKRaiseIfExceptionWrapperError(error); SCKRaiseIfExceptionWrapperError(error);
if (!serializedMessage || error) { if (!serializedMessage || error) {
OWSFailDebug(@"error while UD encrypting message: %@", error); OWSFailDebug(@"Error while UD encrypting message: %@.", error);
return nil; return nil;
} }
messageType = TSUnidentifiedSenderMessageType; messageType = TSUnidentifiedSenderMessageType;
} else { } else {
// This may throw an exception. // This may throw an exception
id<CipherMessage> encryptedMessage = id<CipherMessage> encryptedMessage =
[cipher throws_encryptMessage:[plainText paddedMessageBody] protocolContext:transaction]; [cipher throws_encryptMessage:[plainText paddedMessageBody] protocolContext:transaction];
serializedMessage = encryptedMessage.serialized; serializedMessage = encryptedMessage.serialized;
@ -2168,7 +2154,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if ([attachment isKindOfClass:[TSAttachmentStream class]]) { if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
[attachmentIds addObject:attachment.uniqueId]; [attachmentIds addObject:attachment.uniqueId];
} else { } else {
OWSFailDebug(@"unexpected avatarAttachment: %@", attachment); OWSFailDebug(@"Unexpected avatarAttachment: %@.", attachment);
} }
} }
@ -2178,7 +2164,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if ([attachment isKindOfClass:[TSAttachmentStream class]]) { if ([attachment isKindOfClass:[TSAttachmentStream class]]) {
[attachmentIds addObject:attachment.uniqueId]; [attachmentIds addObject:attachment.uniqueId];
} else { } else {
OWSFailDebug(@"unexpected attachment: %@", attachment); OWSFailDebug(@"Unexpected attachment: %@.", attachment);
} }
} }
@ -2206,6 +2192,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
sourceFilename:attachmentInfo.sourceFilename sourceFilename:attachmentInfo.sourceFilename
caption:attachmentInfo.caption caption:attachmentInfo.caption
albumMessageId:attachmentInfo.albumMessageId]; albumMessageId:attachmentInfo.albumMessageId];
if (outgoingMessage.isVoiceMessage) { if (outgoingMessage.isVoiceMessage) {
attachmentStream.attachmentType = TSAttachmentTypeVoiceMessage; attachmentStream.attachmentType = TSAttachmentTypeVoiceMessage;
} }

@ -425,14 +425,14 @@ public class OWSUDManagerImpl: NSObject, OWSUDManager {
private func generateSenderCertificate() -> Promise<(certificateData: Data, certificate: SMKSenderCertificate)> { private func generateSenderCertificate() -> Promise<(certificateData: Data, certificate: SMKSenderCertificate)> {
return Promise<(certificateData: Data, certificate: SMKSenderCertificate)> { seal in return Promise<(certificateData: Data, certificate: SMKSenderCertificate)> { seal in
//Loki: Generate a sender certifate locally // Loki: Generate a sender certifate locally
let sender = OWSIdentityManager.shared().identityKeyPair()?.hexEncodedPublicKey let sender = OWSIdentityManager.shared().identityKeyPair()?.hexEncodedPublicKey
let certificate = SMKSenderCertificate(senderDeviceId: OWSDevicePrimaryDeviceId, senderRecipientId: sender!) let certificate = SMKSenderCertificate(senderDeviceId: OWSDevicePrimaryDeviceId, senderRecipientId: sender!)
let certificateData = try certificate.serialized() let certificateAsData = try certificate.serialized()
guard self.isValidCertificate(certificate) else { guard isValidCertificate(certificate) else {
throw OWSUDError.invalidData(description: "Invalid sender certificate returned by server") throw OWSUDError.invalidData(description: "Invalid sender certificate.")
} }
seal.fulfill((certificateData: certificateData, certificate: certificate)) seal.fulfill((certificateData: certificateAsData, certificate: certificate))
} }
} }

@ -34,8 +34,6 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
} }
} }
// MARK:
@objc(addMessage:transaction:) @objc(addMessage:transaction:)
public func add(message: TSOutgoingMessage, transaction: YapDatabaseReadWriteTransaction) { public func add(message: TSOutgoingMessage, transaction: YapDatabaseReadWriteTransaction) {
self.add(message: message, removeMessageAfterSending: false, transaction: transaction) self.add(message: message, removeMessageAfterSending: false, transaction: transaction)
@ -71,7 +69,7 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
do { do {
jobRecord = try SSKMessageSenderJobRecord(message: message, removeMessageAfterSending: false, label: self.jobRecordLabel) jobRecord = try SSKMessageSenderJobRecord(message: message, removeMessageAfterSending: false, label: self.jobRecordLabel)
} catch { } catch {
owsFailDebug("failed to build job: \(error)") owsFailDebug("Failed to build job due to error: \(error).")
return return
} }
self.add(jobRecord: jobRecord, transaction: transaction) self.add(jobRecord: jobRecord, transaction: transaction)
@ -121,7 +119,7 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
message = fetchedMessage message = fetchedMessage
} else { } else {
assert(jobRecord.messageId != nil) assert(jobRecord.messageId != nil)
throw JobError.obsolete(description: "message no longer exists") throw JobError.obsolete(description: "Message no longer exists.")
} }
return MessageSenderOperation(message: message, jobRecord: jobRecord) return MessageSenderOperation(message: message, jobRecord: jobRecord)
@ -205,8 +203,6 @@ public class MessageSenderOperation: OWSOperation, DurableOperation {
} }
override public func didReportError(_ error: Error) { override public func didReportError(_ error: Error) {
Logger.debug("remainingRetries: \(self.remainingRetries)")
self.dbConnection.readWrite { transaction in self.dbConnection.readWrite { transaction in
self.durableOperationDelegate?.durableOperation(self, didReportError: error, transaction: transaction) self.durableOperationDelegate?.durableOperation(self, didReportError: error, transaction: transaction)
} }

Loading…
Cancel
Save