diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 5afd920bb..18b32fb69 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -332,13 +332,13 @@ static NSTimeInterval launchStartedAt; if ([serverURLDescription hasSuffix:@"/"]) { serverURLDescription = [serverURLDescription substringToIndex:serverURLDescription.length - 1]; } - OWSLogInfo(@"[Loki] Started server at %@.", serverURLDescription); + NSLog(@"[Loki] Started server at %@.", serverURLDescription); break; } } if (!self.lokiP2PServer.isRunning) { - OWSLogWarn(@"[Loki] Failed to start P2P server."); + NSLog(@"[Loki] Failed to start P2P server."); } return YES; @@ -1416,7 +1416,7 @@ static NSTimeInterval launchStartedAt; - (void)handleNewMessagesReceived:(NSNotification *)notification { NSArray *messages = (NSArray *)notification.userInfo[@"messages"]; - OWSLogInfo(@"[Loki] Received %lu messages through long polling.", messages.count); + NSLog(@"[Loki] Received %lu messages through long polling.", messages.count); for (SSKProtoEnvelope *envelope in messages) { NSData *envelopeData = envelope.serializedDataIgnoringErrors; diff --git a/Signal/src/Jobs/SessionResetJob.swift b/Signal/src/Jobs/SessionResetJob.swift index 7c771c464..a889d582a 100644 --- a/Signal/src/Jobs/SessionResetJob.swift +++ b/Signal/src/Jobs/SessionResetJob.swift @@ -147,7 +147,7 @@ public class SessionResetOperation: OWSOperation, DurableOperation { message.save(with: transaction) // Loki: We have initiated a session reset - Logger.debug("[Loki] Session reset initiated.") + print("[Loki] Session reset initiated.") self.contactThread.sessionResetState = .initiated self.contactThread.save(with: transaction) } diff --git a/Signal/src/Loki/LokiP2PServer.swift b/Signal/src/Loki/LokiP2PServer.swift index 90d0ddc2c..ebd2377ec 100644 --- a/Signal/src/Loki/LokiP2PServer.swift +++ b/Signal/src/Loki/LokiP2PServer.swift @@ -25,7 +25,7 @@ private extension GCDWebServerDataRequest { let object = try JSONSerialization.jsonObject(with: data, options: .allowFragments) return object as? JSON } catch let error { - Logger.debug("[Loki] Failed to serialize JSON: \(error).") + print("[Loki] Failed to serialize JSON: \(error).") } return nil diff --git a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift index 91aceac70..1bb9cf2d9 100644 --- a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift +++ b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift @@ -36,7 +36,7 @@ public class CreatePreKeysOperation: OWSOperation { self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) - Logger.debug("[Loki] Create pre keys operation done.") + print("[Loki] Create pre keys operation done.") self.reportSuccess() /* Loki: Original code diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index 9ef53c46d..75bcd7d16 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -52,7 +52,7 @@ public class RefreshPreKeysOperation: OWSOperation { TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearSignedPreKeyRecords() - Logger.debug("[Loki] Pre key refresh operation done.") + print("[Loki] Pre key refresh operation done.") self.reportSuccess() } diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index b2722dedd..e09d2f693 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -37,7 +37,7 @@ public class RotateSignedPreKeyOperation: OWSOperation { TSPreKeyManager.clearPreKeyUpdateFailureCount() TSPreKeyManager.clearSignedPreKeyRecords() - Logger.debug("[Loki] Rotate signed pre key operation done.") + print("[Loki] Rotate signed pre key operation done.") self.reportSuccess() } diff --git a/SignalServiceKit/src/Contacts/TSThread.m b/SignalServiceKit/src/Contacts/TSThread.m index 3b10a7c37..2e89ef212 100644 --- a/SignalServiceKit/src/Contacts/TSThread.m +++ b/SignalServiceKit/src/Contacts/TSThread.m @@ -768,7 +768,7 @@ ConversationColorName const kConversationColorName_Default = ConversationColorNa - (void)saveFriendRequestStatus:(LKThreadFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction { self.friendRequestStatus = friendRequestStatus; - OWSLogInfo(@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription); + NSLog(@"[Loki] Setting thread friend request status to %@.", self.friendRequestStatusDescription); void (^postNotification)() = ^() { [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.threadFriendRequestStatusChanged object:self.uniqueId]; }; diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+LongPolling.swift b/SignalServiceKit/src/Loki/API/LokiAPI+LongPolling.swift index fd62e8acd..dd0a16f64 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+LongPolling.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+LongPolling.swift @@ -15,7 +15,7 @@ public extension LokiAPI { isLongPolling = true shouldStopPolling = false - Logger.info("[Loki] Started long polling.") + print("[Loki] Started long polling.") longPoll() } @@ -27,7 +27,7 @@ public extension LokiAPI { usedSnodes.removeAll() cancelAllPromises() - Logger.info("[Loki] Stopped long polling.") + print("[Loki] Stopped long polling.") } /// The long polling loop diff --git a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift index 9c5fd13a7..528786a22 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI+SwarmAPI.swift @@ -78,7 +78,7 @@ public extension LokiAPI { // MARK: Parsing private static func parseTargets(from rawResponse: Any) -> [LokiAPITarget] { guard let json = rawResponse as? JSON, let rawSnodes = json["snodes"] as? [JSON] else { - Logger.warn("[Loki] Failed to parse targets from: \(rawResponse).") + print("[Loki] Failed to parse targets from: \(rawResponse).") return [] } return rawSnodes.flatMap { rawSnode in @@ -97,10 +97,10 @@ internal extension Promise { switch error.statusCode { case 0: // The snode is unreachable; usually a problem with LokiNet - Logger.warn("[Loki] Couldn't reach snode at: \(target.address):\(target.port).") + print("[Loki] Couldn't reach snode at: \(target.address):\(target.port).") case 421: // The snode isn't associated with the given public key anymore - Logger.warn("[Loki] Invalidating swarm for: \(hexEncodedPublicKey).") + print("[Loki] Invalidating swarm for: \(hexEncodedPublicKey).") LokiAPI.dropIfNeeded(target, hexEncodedPublicKey: hexEncodedPublicKey) default: break } diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 4e6fc3ba2..5fe214495 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -9,6 +9,7 @@ public final class LokiAPI : NSObject { // MARK: Settings private static let version = "v1" private static let maxRetryCount: UInt = 3 + private static let defaultTimeout: TimeInterval = 20 private static let longPollingTimeout: TimeInterval = 40 public static let defaultMessageTTL: UInt64 = 24 * 60 * 60 * 1000 @@ -40,7 +41,10 @@ public final class LokiAPI : NSObject { let url = URL(string: "\(target.address):\(target.port)/\(version)/storage_rpc")! let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ]) if let headers = headers { request.allHTTPHeaderFields = headers } - if let timeout = timeout { request.timeoutInterval = timeout } + if let timeout = timeout { request.timeoutInterval = timeout ?? defaultTimeout } + let headers = request.allHTTPHeaderFields ?? [:] + let headersDescription = headers.isEmpty ? "no custom headers specified" : headers.description + print("[Loki] Invoking \(method.rawValue) on \(url) with \(parameters) (\(headersDescription)).") return TSNetworkManager.shared().makePromise(request: request).map { $0.responseObject } .handlingSwarmSpecificErrorsIfNeeded(for: target, associatedWith: hexEncodedPublicKey).recoveringNetworkErrorsIfNeeded() } @@ -82,7 +86,7 @@ public final class LokiAPI : NSObject { }.recover { error -> Promise> in LokiP2PAPI.markOffline(destination) if lokiMessage.isPing { - Logger.warn("[Loki] Failed to ping \(destination); marking contact as offline.") + print("[Loki] Failed to ping \(destination); marking contact as offline.") if let error = error as? NSError { error.isRetryable = false throw error @@ -119,7 +123,7 @@ public final class LokiAPI : NSObject { if let lastMessage = rawMessages.last, let hashValue = lastMessage["hash"] as? String, let expirationDate = lastMessage["expiration"] as? Int { setLastMessageHashValue(for: target, hashValue: hashValue, expirationDate: UInt64(expirationDate)) } else if (!rawMessages.isEmpty) { - Logger.warn("[Loki] Failed to update last message hash value from: \(rawMessages).") + print("[Loki] Failed to update last message hash value from: \(rawMessages).") } } @@ -127,7 +131,7 @@ public final class LokiAPI : NSObject { var receivedMessageHashValues = getReceivedMessageHashValues() ?? [] return rawMessages.filter { rawMessage in guard let hashValue = rawMessage["hash"] as? String else { - Logger.warn("[Loki] Missing hash value for message: \(rawMessage).") + print("[Loki] Missing hash value for message: \(rawMessage).") return false } let isDuplicate = receivedMessageHashValues.contains(hashValue) @@ -140,11 +144,11 @@ public final class LokiAPI : NSObject { private static func parseProtoEnvelopes(from rawMessages: [JSON]) -> [SSKProtoEnvelope] { return rawMessages.compactMap { rawMessage in guard let base64EncodedData = rawMessage["data"] as? String, let data = Data(base64Encoded: base64EncodedData) else { - Logger.warn("[Loki] Failed to decode data for message: \(rawMessage).") + print("[Loki] Failed to decode data for message: \(rawMessage).") return nil } guard let envelope = try? LokiMessageWrapper.unwrap(data: data) else { - Logger.warn("[Loki] Failed to unwrap data for message: \(rawMessage).") + print("[Loki] Failed to unwrap data for message: \(rawMessage).") return nil } return envelope diff --git a/SignalServiceKit/src/Loki/API/LokiAPITarget.swift b/SignalServiceKit/src/Loki/API/LokiAPITarget.swift index a57bdf515..f97e8b684 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPITarget.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPITarget.swift @@ -29,4 +29,7 @@ internal final class LokiAPITarget : NSObject, NSCoding { coder.encode(address, forKey: "address") coder.encode(port, forKey: "port") } + + // MARK: Description + override var description: String { return "\(address):\(port)" } } diff --git a/SignalServiceKit/src/Loki/API/LokiMessage.swift b/SignalServiceKit/src/Loki/API/LokiMessage.swift index 23f15f30c..3ee57dbe0 100644 --- a/SignalServiceKit/src/Loki/API/LokiMessage.swift +++ b/SignalServiceKit/src/Loki/API/LokiMessage.swift @@ -39,7 +39,7 @@ public struct LokiMessage { let isPing = signalMessage.isPing return LokiMessage(destination: destination, data: data, ttl: ttl, isPing: isPing) } catch let error { - Logger.debug("[Loki] Failed to convert Signal message to Loki message: \(signalMessage).") + print("[Loki] Failed to convert Signal message to Loki message: \(signalMessage).") return nil } } diff --git a/SignalServiceKit/src/Loki/API/LokiP2PAPI.swift b/SignalServiceKit/src/Loki/API/LokiP2PAPI.swift index 8b9a251f2..922e1e751 100644 --- a/SignalServiceKit/src/Loki/API/LokiP2PAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiP2PAPI.swift @@ -48,12 +48,12 @@ public class LokiP2PAPI : NSObject { } guard let thread = contactThread else { - Logger.warn("[Loki] Failed to fetch thread when attempting to ping: \(pubKey).") + print("[Loki] Failed to fetch thread when attempting to ping: \(pubKey).") return } guard let message = createLokiAddressMessage(for: thread, isPing: true) else { - Logger.warn("[Loki] Failed to build ping message for \(pubKey).") + print("[Loki] Failed to build ping message for \(pubKey).") return } @@ -75,11 +75,11 @@ public class LokiP2PAPI : NSObject { public static func handleReceivedMessage(base64EncodedData: String) { guard let data = Data(base64Encoded: base64EncodedData) else { - Logger.warn("[Loki] Failed to decode data for P2P message.") + print("[Loki] Failed to decode data for P2P message.") return } guard let envelope = try? LokiMessageWrapper.unwrap(data: data) else { - Logger.warn("[Loki] Failed to unwrap data for P2P message.") + print("[Loki] Failed to unwrap data for P2P message.") return } // We need to set the P2P field on the envelope @@ -91,7 +91,7 @@ public class LokiP2PAPI : NSObject { let envelopeData = try newEnvelope.serializedData() messageReceiver.handleReceivedEnvelopeData(envelopeData) } catch let error { - Logger.warn("[Loki] Something went wrong during proto conversion: \(error).") + print("[Loki] Something went wrong during proto conversion: \(error).") } } @@ -198,7 +198,7 @@ public class LokiP2PAPI : NSObject { AssertIsOnMainThread() guard let message = onlineBroadcastMessage(forThread: thread) else { - Logger.warn("[Loki] P2P address not set.") + print("[Loki] P2P address not set.") return } @@ -222,7 +222,7 @@ public class LokiP2PAPI : NSObject { private static func createLokiAddressMessage(for thread: TSThread, isPing: Bool) -> LokiAddressMessage? { guard let ourAddress = ourP2PAddress else { - Logger.warn("[Loki] P2P address not set.") + print("[Loki] P2P address not set.") return nil } diff --git a/SignalServiceKit/src/Loki/Crypto/OWSPrimaryStorage+Loki.m b/SignalServiceKit/src/Loki/Crypto/OWSPrimaryStorage+Loki.m index b737ef437..8d07532d0 100644 --- a/SignalServiceKit/src/Loki/Crypto/OWSPrimaryStorage+Loki.m +++ b/SignalServiceKit/src/Loki/Crypto/OWSPrimaryStorage+Loki.m @@ -62,7 +62,7 @@ @try { return [self throws_loadPreKey:preKeyId]; } @catch (NSException *exception) { - OWSLogWarn(@"[Loki] New prekey generated for %@.", pubKey); + NSLog(@"[Loki] New prekey generated for %@.", pubKey); return [self generateAndStorePreKeyForContact:pubKey]; } } diff --git a/SignalServiceKit/src/Loki/Messaging/FriendRequestExpirationJob.swift b/SignalServiceKit/src/Loki/Messaging/FriendRequestExpirationJob.swift index 0ca56d09a..c3f2fbbe7 100644 --- a/SignalServiceKit/src/Loki/Messaging/FriendRequestExpirationJob.swift +++ b/SignalServiceKit/src/Loki/Messaging/FriendRequestExpirationJob.swift @@ -140,7 +140,7 @@ public final class FriendRequestExpirationJob : NSObject { private func timerDidFire(isMainTimer: Bool) { guard CurrentAppContext().isMainAppAndActive else { let infoString = isMainTimer ? "Main timer fired while main app is inactive." : "Ignoring fallback timer for app which is not main and active." - Logger.info("[Loki] Friend request expiration job running: \(infoString).") + print("[Loki] Friend request expiration job running: \(infoString).") return } diff --git a/SignalServiceKit/src/Loki/Messaging/LokiMessageWrapper.swift b/SignalServiceKit/src/Loki/Messaging/LokiMessageWrapper.swift index af330cf86..107c902d6 100644 --- a/SignalServiceKit/src/Loki/Messaging/LokiMessageWrapper.swift +++ b/SignalServiceKit/src/Loki/Messaging/LokiMessageWrapper.swift @@ -40,7 +40,7 @@ public enum LokiMessageWrapper { } return try builder.build() } catch let error { - Logger.warn("[Loki] Failed to wrap message in envelope: \(error).") + print("[Loki] Failed to wrap message in envelope: \(error).") throw WrappingError.failedToWrapMessageInEnvelope } } @@ -53,7 +53,7 @@ public enum LokiMessageWrapper { messageBuilder.setRequest(try requestBuilder.build()) return try messageBuilder.build() } catch let error { - Logger.warn("[Loki] Failed to wrap envelope in web socket message: \(error).") + print("[Loki] Failed to wrap envelope in web socket message: \(error).") throw WrappingError.failedToWrapEnvelopeInWebSocketMessage } } @@ -65,7 +65,7 @@ public enum LokiMessageWrapper { let envelope = webSocketMessage.request!.body! return try SSKProtoEnvelope.parseData(envelope) } catch let error { - Logger.warn("[Loki] Failed to unwrap data: \(error).") + print("[Loki] Failed to unwrap data: \(error).") throw WrappingError.failedToUnwrapData } } diff --git a/SignalServiceKit/src/Messages/Interactions/TSMessage.m b/SignalServiceKit/src/Messages/Interactions/TSMessage.m index b059da306..440e64b58 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSMessage.m @@ -445,7 +445,7 @@ static const NSUInteger OWSMessageSchemaVersion = 4; - (void)saveFriendRequestStatus:(LKMessageFriendRequestStatus)friendRequestStatus withTransaction:(YapDatabaseReadWriteTransaction *_Nullable)transaction { self.friendRequestStatus = friendRequestStatus; - OWSLogInfo(@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription); + NSLog(@"[Loki] Setting message friend request status to %@.", self.friendRequestStatusDescription); void (^postNotification)() = ^() { [NSNotificationCenter.defaultCenter postNotificationName:NSNotification.messageFriendRequestStatusChanged object:self.uniqueId]; }; diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index 1cdf677c4..f559d97a3 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1032,7 +1032,7 @@ NS_ASSUME_NONNULL_BEGIN LKEphemeralMessage *emptyMessage = [[LKEphemeralMessage alloc] initInThread:thread]; [self.messageSenderJobQueue addMessage:emptyMessage transaction:transaction]; - OWSLogDebug(@"[Loki] Session reset received from %@.", envelope.source); + NSLog(@"[Loki] Session reset received from %@.", envelope.source); /* Loki: Original code * ================ @@ -1737,7 +1737,7 @@ NS_ASSUME_NONNULL_BEGIN TSContactThread *_Nullable thread = [TSContactThread getThreadWithContactId:pubKey transaction:transaction]; if (!thread) { - OWSLogDebug(@"[Loki] A new session was adopted but we failed to get the thread for %@.", pubKey); + NSLog(@"[Loki] A new session was adopted but we failed to get the thread for %@.", pubKey); return; } diff --git a/SignalServiceKit/src/TSConstants.h b/SignalServiceKit/src/TSConstants.h index e2a5b10c5..478eb3326 100644 --- a/SignalServiceKit/src/TSConstants.h +++ b/SignalServiceKit/src/TSConstants.h @@ -27,7 +27,7 @@ typedef NS_ENUM(NSInteger, TSWhisperMessageType) { // Production #define textSecureWebSocketAPI @"wss://textsecure-service.whispersystems.org/v1/websocket/" -#define textSecureServerURL @"http://13.236.173.190" // TODO: Temporary +#define textSecureServerURL @"https://textsecure-service.whispersystems.org/" #define textSecureCDNServerURL @"https://cdn.signal.org" // Use same reflector for service and CDN #define textSecureServiceReflectorHost @"europe-west1-signal-cdn-reflector.cloudfunctions.net"