Make logging more useful

This commit is contained in:
gmbnt 2020-03-31 16:34:31 +11:00
parent 7f29bc9719
commit 1106ca5eb1
12 changed files with 17 additions and 29 deletions

View File

@ -1181,11 +1181,9 @@ static BOOL isUsingFullAPNs = YES;
PMKJoin(promises).then(^(id results) {
completionHandler(UIBackgroundFetchResultNewData);
CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultNewData"];
}).catch(^(id error) {
completionHandler(UIBackgroundFetchResultFailed);
CurrentAppContext().wasWokenUpBySilentPushNotification = false;
[LKLogger print:@"[Loki] UIBackgroundFetchResultFailed"];
});
}

View File

@ -28,7 +28,7 @@ final class LokiPushNotificationManager : NSObject {
return print("[Loki] Device token hasn't changed; no need to re-upload.")
}
guard !isUsingFullAPNs else {
return print("[Loki] Using full APNs; no need to upload device token.")
return print("[Loki] Using full APNs; ignoring call to register(with:).")
}
let parameters = [ "token" : hexEncodedToken ]
let request = TSRequest(url: url, method: "POST", parameters: parameters)

View File

@ -780,7 +780,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa
- (void)saveFriendRequestStatus:(LKThreadFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction
{
self.friendRequestStatus = friendRequestStatus;
NSLog(@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription);
[LKLogger print:[NSString stringWithFormat:@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription]];
void (^postNotification)() = ^() {
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.threadFriendRequestStatusChanged object:self.uniqueId];
};

View File

@ -48,7 +48,7 @@ public extension LokiAPI {
]
]
])
print("[Loki] Invoking get_service_nodes on \(target).")
print("[Loki] Populating snode pool using: \(target).")
return TSNetworkManager.shared().perform(request, withCompletionQueue: DispatchQueue.global()).map(on: DispatchQueue.global()) { intermediate in
let rawResponse = intermediate.responseObject
guard let json = rawResponse as? JSON, let intermediate = json["result"] as? JSON, let rawTargets = intermediate["service_node_states"] as? [JSON] else { throw LokiAPIError.randomSnodePoolUpdatingFailed }

View File

@ -98,9 +98,6 @@ public final class LokiAPI : NSObject {
let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ])
if let headers = headers { request.allHTTPHeaderFields = headers }
request.timeoutInterval = timeout ?? defaultTimeout
let headers = request.allHTTPHeaderFields ?? [:]
let headersDescription = headers.isEmpty ? "no custom headers specified" : headers.prettifiedDescription
print("[Loki] Invoking \(method.rawValue) on \(target) with \(parameters.prettifiedDescription) (\(headersDescription)).")
return LokiSnodeProxy(for: target).perform(request, withCompletionQueue: DispatchQueue.global())
.handlingSwarmSpecificErrorsIfNeeded(for: target, associatedWith: hexEncodedPublicKey)
.recoveringNetworkErrorsIfNeeded()
@ -259,11 +256,6 @@ public final class LokiAPI : NSObject {
let newRawMessages = removeDuplicates(from: rawMessages)
let newMessages = parseProtoEnvelopes(from: newRawMessages)
let newMessageCount = newMessages.count
if newMessageCount == 1 {
print("[Loki] Retrieved 1 new message.")
} else if (newMessageCount != 0) {
print("[Loki] Retrieved \(newMessageCount) new messages.")
}
return newMessages
}

View File

@ -56,7 +56,6 @@ internal class LokiFileServerProxy : LokiHTTPClient {
serverURLEndIndex < urlAsString.endIndex else { throw Error.endpointParsingFailed }
let endpointStartIndex = urlAsString.index(after: serverURLEndIndex)
let endpoint = String(urlAsString[endpointStartIndex..<urlAsString.endIndex])
print("[Loki] Proxying file server request (\(endpoint)) through \(proxy).")
let parametersAsString: String
if let tsRequest = request as? TSRequest {
headers["Content-Type"] = "application/json"

View File

@ -60,7 +60,6 @@ public final class LokiPoller : NSObject {
// randomElement() uses the system's default random generator, which is cryptographically secure
let nextSnode = unusedSnodes.randomElement()!
usedSnodes.insert(nextSnode)
print("[Loki] Polling \(nextSnode).")
poll(nextSnode, seal: seal).done(on: DispatchQueue.global()) {
seal.fulfill(())
}.catch(on: LokiAPI.errorHandlingQueue) { [weak self] error in

View File

@ -38,7 +38,6 @@ internal class LokiSnodeProxy : LokiHTTPClient {
guard let symmetricKey = uncheckedSymmetricKey else { return seal.reject(Error.symmetricKeyGenerationFailed) }
LokiAPI.getRandomSnode().then(on: DispatchQueue.global()) { proxy -> Promise<LokiAPI.RawResponse> in
let url = "\(proxy.address):\(proxy.port)/proxy"
print("[Loki] Proxying request to \(target) through \(proxy).")
let parametersAsData = try JSONSerialization.data(withJSONObject: request.parameters, options: [])
let proxyRequestParameters: JSON = [
"method" : request.httpMethod,

View File

@ -16,7 +16,7 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol {
public func validatePreKeyForFriendRequestAcceptance(for recipientID: String, whisperMessage: CipherMessage, protocolContext: Any?) throws {
guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else {
print("[Loki] Could not verify friend request acceptance pre key because an invalid transaction was provided.")
print("[Loki] Couldn't verify friend request acceptance pre key because an invalid transaction was provided.")
return
}
guard let preKeyMessage = whisperMessage as? PreKeyWhisperMessage else { return }
@ -32,7 +32,7 @@ public class LokiSessionResetImplementation : NSObject, SessionResetProtocol {
public func getSessionResetStatus(for recipientID: String, protocolContext: Any?) -> SessionResetStatus {
guard let transaction = protocolContext as? YapDatabaseReadWriteTransaction else {
print("[Loki] Could not get session reset status for \(recipientID) because an invalid transaction was provided.")
print("[Loki] Couldn't get session reset status for \(recipientID) because an invalid transaction was provided.")
return .none
}
guard let thread = TSContactThread.getWithContactId(recipientID, transaction: transaction) else { return .none }

View File

@ -11,6 +11,7 @@
#import "YapDatabaseTransaction+OWS.h"
#import <AxolotlKit/NSData+keyVersionByte.h>
#import "NSObject+Casting.h"
#import <SignalServiceKit/SignalServiceKit-Swift.h>
@implementation OWSPrimaryStorage (Loki)
@ -58,7 +59,7 @@
@try {
return [self throws_loadPreKey:preKeyId];
} @catch (NSException *exception) {
NSLog(@"[Loki] New pre key generated for %@.", pubKey);
[LKLogger print:[NSString stringWithFormat:@"[Loki] New pre key generated for %@.", pubKey]];
return [self generateAndStorePreKeyForContact:pubKey];
}
}
@ -95,7 +96,7 @@
[signedPreKeyRecord markAsAcceptedByService];
[self storeSignedPreKey:signedPreKeyRecord.Id signedPreKeyRecord:signedPreKeyRecord];
[self setCurrentSignedPrekeyId:signedPreKeyRecord.Id];
NSLog(@"[Loki] Pre keys refreshed successfully.");
[LKLogger print:@"[Loki] Pre keys refreshed successfully."];
}
SignedPreKeyRecord *_Nullable signedPreKey = self.currentSignedPreKey;
@ -134,7 +135,7 @@
forceClean = YES;
}
}
OWSLogWarn(@"[Loki] Failed to generate a valid pre key bundle for: %@.", pubKey);
[LKLogger print:[NSString stringWithFormat:@"[Loki] Failed to generate a valid pre key bundle for: %@.", pubKey]];
return nil;
}

View File

@ -450,7 +450,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4;
- (void)saveFriendRequestStatus:(LKMessageFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction
{
self.friendRequestStatus = friendRequestStatus;
NSLog(@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription);
[LKLogger print:[NSString stringWithFormat:@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription]];
void (^postNotification)() = ^() {
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.messageFriendRequestStatusChanged object:self.uniqueId];
};

View File

@ -450,7 +450,7 @@ NS_ASSUME_NONNULL_BEGIN
// Loki: Handle pre key bundle message if needed
if (contentProto.prekeyBundleMessage != nil) {
OWSLogInfo(@"[Loki] Received a pre key bundle message from: %@.", envelope.source);
[LKLogger print:[NSString stringWithFormat:@"[Loki] Received a pre key bundle message from: %@.", envelope.source]];
PreKeyBundle *_Nullable bundle = [contentProto.prekeyBundleMessage getPreKeyBundleWithTransaction:transaction];
if (bundle == nil) {
OWSFailDebug(@"Failed to create a pre key bundle.");
@ -484,7 +484,7 @@ NS_ASSUME_NONNULL_BEGIN
NSData *masterSignature = contentProto.lokiDeviceLinkMessage.masterSignature;
NSData *slaveSignature = contentProto.lokiDeviceLinkMessage.slaveSignature;
if (masterSignature != nil) { // Authorization
OWSLogInfo(@"[Loki] Received a device linking authorization from: %@", envelope.source); // Not masterHexEncodedPublicKey
[LKLogger print:[NSString stringWithFormat:@"[Loki] Received a device linking authorization from: %@", envelope.source]]; // Not masterHexEncodedPublicKey
[LKDeviceLinkingSession.current processLinkingAuthorizationFrom:masterHexEncodedPublicKey for:slaveHexEncodedPublicKey masterSignature:masterSignature slaveSignature:slaveSignature];
// Set any profile info
if (contentProto.dataMessage) {
@ -493,7 +493,7 @@ NS_ASSUME_NONNULL_BEGIN
[self handleProfileKeyUpdateIfNeeded:dataMessage recipientId:masterHexEncodedPublicKey];
}
} else if (slaveSignature != nil) { // Request
OWSLogInfo(@"[Loki] Received a device linking request from: %@", envelope.source); // Not slaveHexEncodedPublicKey
[LKLogger print: [NSString stringWithFormat:@"[Loki] Received a device linking request from: %@", envelope.source]]; // Not slaveHexEncodedPublicKey
if (LKDeviceLinkingSession.current == nil) {
[NSNotificationCenter.defaultCenter postNotificationName:NSNotification.unexpectedDeviceLinkRequestReceived object:nil];
}
@ -1140,7 +1140,7 @@ NS_ASSUME_NONNULL_BEGIN
}
} else if (syncMessage.openGroups != nil) {
if (wasSentByMasterDevice && syncMessage.openGroups.count > 0) {
OWSLogInfo(@"[Loki] Received open group sync message.");
[LKLogger print:@"[Loki] Received open group sync message."];
for (SSKProtoSyncMessageOpenGroups* openGroup in syncMessage.openGroups) {
[LKPublicChatManager.shared addChatWithServer:openGroup.url channel:openGroup.channel];
}
@ -1191,7 +1191,7 @@ NS_ASSUME_NONNULL_BEGIN
LKEphemeralMessage *emptyMessage = [[LKEphemeralMessage alloc] initInThread:thread];
[self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction];
NSLog(@"[Loki] Session reset received from %@.", hexEncodedPublicKey);
[LKLogger print:[NSString stringWithFormat:@"[Loki] Session reset received from %@.", hexEncodedPublicKey]];
}
- (void)handleExpirationTimerUpdateMessageWithEnvelope:(SSKProtoEnvelope *)envelope
@ -1788,11 +1788,11 @@ NS_ASSUME_NONNULL_BEGIN
- (void)handleFriendRequestMessageIfNeededWithEnvelope:(SSKProtoEnvelope *)envelope data:(SSKProtoDataMessage *)data message:(TSIncomingMessage *)message thread:(TSContactThread *)thread transaction:(YapDatabaseReadWriteTransaction *)transaction {
if (envelope.isGroupChatMessage) {
return NSLog(@"[Loki] Ignoring friend request in group chat.", @"");
return [LKLogger print:@"[Loki] Ignoring friend request in group chat."];
}
// The envelope type is set during UD decryption.
if (envelope.type != SSKProtoEnvelopeTypeFriendRequest) {
return NSLog(@"[Loki] Ignoring friend request logic for non friend request type envelope.");
return [LKLogger print:@"[Loki] Ignoring friend request logic for non friend request type envelope."];
}
if ([self canFriendRequestBeAutoAcceptedForThread:thread transaction:transaction]) {
[thread saveFriendRequestStatus:LKThreadFriendRequestStatusFriends withTransaction:transaction];