diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 42944860a..531e1760e 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -777,7 +777,7 @@ static NSTimeInterval launchStartedAt; [self startLongPollerIfNeeded]; // Loki: Get device links - [LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; + [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) { OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet."); @@ -1448,7 +1448,7 @@ static NSTimeInterval launchStartedAt; [self startLongPollerIfNeeded]; // Loki: Get device links - [LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; + [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; } } diff --git a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift index d18aa4a6c..9ce16ef95 100644 --- a/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift +++ b/Signal/src/Loki/View Controllers/DeviceLinkingModal.swift @@ -175,7 +175,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate { dismiss(animated: true, completion: nil) let master = DeviceLink.Device(hexEncodedPublicKey: deviceLink.master.hexEncodedPublicKey, signature: linkingAuthorizationMessage.masterSignature) let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave) - LokiStorageAPI.addDeviceLink(signedDeviceLink).done { + LokiFileServerAPI.addDeviceLink(signedDeviceLink).done { self.delegate?.handleDeviceLinkAuthorized(signedDeviceLink) // Intentionally capture self strongly }.catch { error in print("[Loki] Failed to add device link due to error: \(error).") @@ -191,7 +191,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate { subtitleLabel.text = NSLocalizedString("Your device has been linked successfully", comment: "") mnemonicLabel.isHidden = true buttonStackView.isHidden = true - LokiStorageAPI.addDeviceLink(deviceLink).catch { error in + LokiFileServerAPI.addDeviceLink(deviceLink).catch { error in print("[Loki] Failed to add device link due to error: \(error).") } Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in diff --git a/Signal/src/Loki/View Controllers/DeviceLinksVC.swift b/Signal/src/Loki/View Controllers/DeviceLinksVC.swift index c99cd79f8..3b54c62bc 100644 --- a/Signal/src/Loki/View Controllers/DeviceLinksVC.swift +++ b/Signal/src/Loki/View Controllers/DeviceLinksVC.swift @@ -152,7 +152,7 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView } private func removeDeviceLink(_ deviceLink: DeviceLink) { - LokiStorageAPI.removeDeviceLink(deviceLink).done { [weak self] in + LokiFileServerAPI.removeDeviceLink(deviceLink).done { [weak self] in let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return } let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)! diff --git a/Signal/src/Loki/View Controllers/LandingVC.swift b/Signal/src/Loki/View Controllers/LandingVC.swift index 04b772263..3369edc3c 100644 --- a/Signal/src/Loki/View Controllers/LandingVC.swift +++ b/Signal/src/Loki/View Controllers/LandingVC.swift @@ -157,7 +157,7 @@ final class LandingVC : UIViewController, LinkDeviceVCDelegate, DeviceLinkingMod TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey TSAccountManager.sharedInstance().didRegister() setUserInteractionEnabled(false) - let _ = LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in + let _ = LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in guard let self = self else { return } defer { self.setUserInteractionEnabled(true) } guard deviceLinks.count < 2 else { diff --git a/SignalMessaging/profiles/OWSProfileManager.m b/SignalMessaging/profiles/OWSProfileManager.m index fb944741f..386247089 100644 --- a/SignalMessaging/profiles/OWSProfileManager.m +++ b/SignalMessaging/profiles/OWSProfileManager.m @@ -411,7 +411,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error); NSData *encryptedAvatarData = [self encryptProfileData:avatarData profileKey:newProfileKey]; OWSAssertDebug(encryptedAvatarData.length > 0); - [[LKStorageAPI setProfilePicture:encryptedAvatarData] + [[LKFileServerAPI setProfilePicture:encryptedAvatarData] .thenOn(dispatch_get_main_queue(), ^(NSString *url) { [self.localUserProfile updateWithProfileKey:newProfileKey dbConnection:self.dbConnection completion:^{ successBlock(url); diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 1a98fdc76..42533db9f 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -132,7 +132,7 @@ public final class LokiAPI : NSObject { if timeSinceLastUpdate > deviceLinkUpdateInterval { storage.dbReadConnection.read { transaction in let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey - LokiStorageAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in + LokiFileServerAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in getDestinations() lastDeviceLinkUpdate[hexEncodedPublicKey] = Date() }.catch(on: DispatchQueue.global()) { error in diff --git a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift index 4dd5a968f..c2846a275 100644 --- a/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiDotNetAPI.swift @@ -1,6 +1,6 @@ import PromiseKit -/// Base class for `LokiStorageAPI` and `LokiPublicChatAPI`. +/// Base class for `LokiFileServerAPI` and `LokiPublicChatAPI`. public class LokiDotNetAPI : NSObject { // MARK: Convenience @@ -39,7 +39,7 @@ public class LokiDotNetAPI : NSObject { // MARK: Attachments (Public API) public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise { - let isEncryptionRequired = (server == LokiStorageAPI.server) + let isEncryptionRequired = (server == LokiFileServerAPI.server) return Promise() { seal in func proceed(with token: String) { // Get the attachment @@ -88,7 +88,7 @@ public class LokiDotNetAPI : NSObject { attachment.save() seal.fulfill(()) } - let isProxyingRequired = (server == LokiStorageAPI.server) // Don't proxy open group requests for now + let isProxyingRequired = (server == LokiFileServerAPI.server) // Don't proxy open group requests for now if isProxyingRequired { let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in parseResponse(responseObject) @@ -119,7 +119,7 @@ public class LokiDotNetAPI : NSObject { task.resume() } } - if server == LokiStorageAPI.server { + if server == LokiFileServerAPI.server { proceed(with: "loki") // Uploads to the Loki File Server shouldn't include any personally identifiable information so use a dummy auth token } else { getAuthToken(for: server).done(on: DispatchQueue.global()) { token in diff --git a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift similarity index 99% rename from SignalServiceKit/src/Loki/API/LokiStorageAPI.swift rename to SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift index cd6bc20aa..e19e880db 100644 --- a/SignalServiceKit/src/Loki/API/LokiStorageAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerAPI.swift @@ -1,7 +1,7 @@ import PromiseKit -@objc(LKStorageAPI) -public final class LokiStorageAPI : LokiDotNetAPI { +@objc(LKFileServerAPI) +public final class LokiFileServerAPI : LokiDotNetAPI { // MARK: Settings #if DEBUG diff --git a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift index a705d6fb5..a4ce4c848 100644 --- a/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiFileServerProxy.swift @@ -37,7 +37,7 @@ internal class LokiFileServerProxy : LokiHTTPClient { // MARK: Proxying override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise { - let isLokiFileServer = (server == LokiStorageAPI.server) + let isLokiFileServer = (server == LokiFileServerAPI.server) guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue) } diff --git a/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift b/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift index 78df64c27..3ff398758 100644 --- a/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift +++ b/SignalServiceKit/src/Loki/API/LokiRSSFeedProxy.swift @@ -13,7 +13,7 @@ public enum LokiRSSFeedProxy { } public static func fetchContent(for url: String) -> Promise { - let server = LokiStorageAPI.server + let server = LokiFileServerAPI.server let endpoints = [ "messenger-updates/feed" : "loki/v1/rss/messenger", "loki.network/feed" : "loki/v1/rss/loki" ] let endpoint = endpoints.first { url.lowercased().contains($0.key) }!.value let url = URL(string: server + "/" + endpoint)! diff --git a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift index c2054c4e7..466558199 100644 --- a/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift +++ b/SignalServiceKit/src/Loki/API/Public Chat/LokiPublicChatPoller.swift @@ -192,7 +192,7 @@ public final class LokiPublicChatPoller : NSObject { if !hexEncodedPublicKeysToUpdate.isEmpty { let storage = OWSPrimaryStorage.shared() storage.dbReadConnection.read { transaction in - LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in + LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in proceed() hexEncodedPublicKeysToUpdate.forEach { LokiAPI.lastDeviceLinkUpdate[$0] = Date() diff --git a/SignalServiceKit/src/Messages/OWSMessageManager.m b/SignalServiceKit/src/Messages/OWSMessageManager.m index a6da66994..4af814e77 100644 --- a/SignalServiceKit/src/Messages/OWSMessageManager.m +++ b/SignalServiceKit/src/Messages/OWSMessageManager.m @@ -1249,7 +1249,7 @@ NS_ASSUME_NONNULL_BEGIN }]) { return; } - [LKStorageAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet *deviceLinks) { + [LKFileServerAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet *deviceLinks) { if ([deviceLinks contains:^BOOL(LKDeviceLink *deviceLink) { return [deviceLink.master.hexEncodedPublicKey isEqual:senderHexEncodedPublicKey] && [deviceLink.slave.hexEncodedPublicKey isEqual:userHexEncodedPublicKey]; }]) { diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index e170eee2d..2be40dd06 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -484,9 +484,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }); } failure:^(NSError *error) { - OWSLogError(@"Could not obtain UD sender certificate: %@", error); - - // Proceed using non-UD message sends. dispatch_async([OWSDispatch sendingQueue], ^{ [self sendMessageToService:message senderCertificate:nil success:success failure:failure]; }); diff --git a/SignalServiceKit/src/Network/API/OWSUploadOperation.m b/SignalServiceKit/src/Network/API/OWSUploadOperation.m index 4db81cfe8..0077f00fc 100644 --- a/SignalServiceKit/src/Network/API/OWSUploadOperation.m +++ b/SignalServiceKit/src/Network/API/OWSUploadOperation.m @@ -65,14 +65,13 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f; - (void)run { __block TSAttachmentStream *attachmentStream; - [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { attachmentStream = [TSAttachmentStream fetchObjectWithUniqueID:self.attachmentId transaction:transaction]; }]; if (!attachmentStream) { - OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotLoadAttachment]); NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); - // Not finding local attachment is a terminal failure. + // Not finding a local attachment is a terminal failure error.isRetryable = NO; [self reportError:error]; return; @@ -90,9 +89,9 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f; [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.threadID transaction:transaction]; }]; - NSString *server = (publicChat != nil) ? publicChat.server : LKStorageAPI.server; + NSString *server = (publicChat != nil) ? publicChat.server : LKFileServerAPI.server; - [[LKStorageAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server] + [[LKFileServerAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server] .thenOn(dispatch_get_main_queue(), ^() { [self reportSuccess]; })