Rename LokiStorageAPI → LokiFileServerAPI

pull/92/head
Niels Andriesse 5 years ago
parent d502aeaa80
commit cc40862740

@ -777,7 +777,7 @@ static NSTimeInterval launchStartedAt;
[self startLongPollerIfNeeded]; [self startLongPollerIfNeeded];
// Loki: Get device links // Loki: Get device links
[LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) { if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) {
OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet."); OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet.");
@ -1448,7 +1448,7 @@ static NSTimeInterval launchStartedAt;
[self startLongPollerIfNeeded]; [self startLongPollerIfNeeded];
// Loki: Get device links // Loki: Get device links
[LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber]; [LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
} }
} }

@ -175,7 +175,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
let master = DeviceLink.Device(hexEncodedPublicKey: deviceLink.master.hexEncodedPublicKey, signature: linkingAuthorizationMessage.masterSignature) let master = DeviceLink.Device(hexEncodedPublicKey: deviceLink.master.hexEncodedPublicKey, signature: linkingAuthorizationMessage.masterSignature)
let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave) let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave)
LokiStorageAPI.addDeviceLink(signedDeviceLink).done { LokiFileServerAPI.addDeviceLink(signedDeviceLink).done {
self.delegate?.handleDeviceLinkAuthorized(signedDeviceLink) // Intentionally capture self strongly self.delegate?.handleDeviceLinkAuthorized(signedDeviceLink) // Intentionally capture self strongly
}.catch { error in }.catch { error in
print("[Loki] Failed to add device link due to error: \(error).") 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: "") subtitleLabel.text = NSLocalizedString("Your device has been linked successfully", comment: "")
mnemonicLabel.isHidden = true mnemonicLabel.isHidden = true
buttonStackView.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).") print("[Loki] Failed to add device link due to error: \(error).")
} }
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in

@ -152,7 +152,7 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
} }
private func removeDeviceLink(_ deviceLink: DeviceLink) { private func removeDeviceLink(_ deviceLink: DeviceLink) {
LokiStorageAPI.removeDeviceLink(deviceLink).done { [weak self] in LokiFileServerAPI.removeDeviceLink(deviceLink).done { [weak self] in
let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey
guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return } guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return }
let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)! let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)!

@ -157,7 +157,7 @@ final class LandingVC : UIViewController, LinkDeviceVCDelegate, DeviceLinkingMod
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey
TSAccountManager.sharedInstance().didRegister() TSAccountManager.sharedInstance().didRegister()
setUserInteractionEnabled(false) 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 } guard let self = self else { return }
defer { self.setUserInteractionEnabled(true) } defer { self.setUserInteractionEnabled(true) }
guard deviceLinks.count < 2 else { guard deviceLinks.count < 2 else {

@ -411,7 +411,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
NSData *encryptedAvatarData = [self encryptProfileData:avatarData profileKey:newProfileKey]; NSData *encryptedAvatarData = [self encryptProfileData:avatarData profileKey:newProfileKey];
OWSAssertDebug(encryptedAvatarData.length > 0); OWSAssertDebug(encryptedAvatarData.length > 0);
[[LKStorageAPI setProfilePicture:encryptedAvatarData] [[LKFileServerAPI setProfilePicture:encryptedAvatarData]
.thenOn(dispatch_get_main_queue(), ^(NSString *url) { .thenOn(dispatch_get_main_queue(), ^(NSString *url) {
[self.localUserProfile updateWithProfileKey:newProfileKey dbConnection:self.dbConnection completion:^{ [self.localUserProfile updateWithProfileKey:newProfileKey dbConnection:self.dbConnection completion:^{
successBlock(url); successBlock(url);

@ -132,7 +132,7 @@ public final class LokiAPI : NSObject {
if timeSinceLastUpdate > deviceLinkUpdateInterval { if timeSinceLastUpdate > deviceLinkUpdateInterval {
storage.dbReadConnection.read { transaction in storage.dbReadConnection.read { transaction in
let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey 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() getDestinations()
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date() lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()
}.catch(on: DispatchQueue.global()) { error in }.catch(on: DispatchQueue.global()) { error in

@ -1,6 +1,6 @@
import PromiseKit import PromiseKit
/// Base class for `LokiStorageAPI` and `LokiPublicChatAPI`. /// Base class for `LokiFileServerAPI` and `LokiPublicChatAPI`.
public class LokiDotNetAPI : NSObject { public class LokiDotNetAPI : NSObject {
// MARK: Convenience // MARK: Convenience
@ -39,7 +39,7 @@ public class LokiDotNetAPI : NSObject {
// MARK: Attachments (Public API) // MARK: Attachments (Public API)
public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise<Void> { public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise<Void> {
let isEncryptionRequired = (server == LokiStorageAPI.server) let isEncryptionRequired = (server == LokiFileServerAPI.server)
return Promise<Void>() { seal in return Promise<Void>() { seal in
func proceed(with token: String) { func proceed(with token: String) {
// Get the attachment // Get the attachment
@ -88,7 +88,7 @@ public class LokiDotNetAPI : NSObject {
attachment.save() attachment.save()
seal.fulfill(()) 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 { if isProxyingRequired {
let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in
parseResponse(responseObject) parseResponse(responseObject)
@ -119,7 +119,7 @@ public class LokiDotNetAPI : NSObject {
task.resume() 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 proceed(with: "loki") // Uploads to the Loki File Server shouldn't include any personally identifiable information so use a dummy auth token
} else { } else {
getAuthToken(for: server).done(on: DispatchQueue.global()) { token in getAuthToken(for: server).done(on: DispatchQueue.global()) { token in

@ -1,7 +1,7 @@
import PromiseKit import PromiseKit
@objc(LKStorageAPI) @objc(LKFileServerAPI)
public final class LokiStorageAPI : LokiDotNetAPI { public final class LokiFileServerAPI : LokiDotNetAPI {
// MARK: Settings // MARK: Settings
#if DEBUG #if DEBUG

@ -37,7 +37,7 @@ internal class LokiFileServerProxy : LokiHTTPClient {
// MARK: Proxying // MARK: Proxying
override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise { 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 guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now
return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue) return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue)
} }

@ -13,7 +13,7 @@ public enum LokiRSSFeedProxy {
} }
public static func fetchContent(for url: String) -> Promise<String> { public static func fetchContent(for url: String) -> Promise<String> {
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 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 endpoint = endpoints.first { url.lowercased().contains($0.key) }!.value
let url = URL(string: server + "/" + endpoint)! let url = URL(string: server + "/" + endpoint)!

@ -192,7 +192,7 @@ public final class LokiPublicChatPoller : NSObject {
if !hexEncodedPublicKeysToUpdate.isEmpty { if !hexEncodedPublicKeysToUpdate.isEmpty {
let storage = OWSPrimaryStorage.shared() let storage = OWSPrimaryStorage.shared()
storage.dbReadConnection.read { transaction in storage.dbReadConnection.read { transaction in
LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in
proceed() proceed()
hexEncodedPublicKeysToUpdate.forEach { hexEncodedPublicKeysToUpdate.forEach {
LokiAPI.lastDeviceLinkUpdate[$0] = Date() LokiAPI.lastDeviceLinkUpdate[$0] = Date()

@ -1249,7 +1249,7 @@ NS_ASSUME_NONNULL_BEGIN
}]) { }]) {
return; return;
} }
[LKStorageAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet<LKDeviceLink *> *deviceLinks) { [LKFileServerAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet<LKDeviceLink *> *deviceLinks) {
if ([deviceLinks contains:^BOOL(LKDeviceLink *deviceLink) { if ([deviceLinks contains:^BOOL(LKDeviceLink *deviceLink) {
return [deviceLink.master.hexEncodedPublicKey isEqual:senderHexEncodedPublicKey] && [deviceLink.slave.hexEncodedPublicKey isEqual:userHexEncodedPublicKey]; return [deviceLink.master.hexEncodedPublicKey isEqual:senderHexEncodedPublicKey] && [deviceLink.slave.hexEncodedPublicKey isEqual:userHexEncodedPublicKey];
}]) { }]) {

@ -484,9 +484,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}); });
} }
failure:^(NSError *error) { failure:^(NSError *error) {
OWSLogError(@"Could not obtain UD sender certificate: %@", error);
// Proceed using non-UD message sends.
dispatch_async([OWSDispatch sendingQueue], ^{ dispatch_async([OWSDispatch sendingQueue], ^{
[self sendMessageToService:message senderCertificate:nil success:success failure:failure]; [self sendMessageToService:message senderCertificate:nil success:success failure:failure];
}); });

@ -65,14 +65,13 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
- (void)run - (void)run
{ {
__block TSAttachmentStream *attachmentStream; __block TSAttachmentStream *attachmentStream;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
attachmentStream = [TSAttachmentStream fetchObjectWithUniqueID:self.attachmentId transaction:transaction]; attachmentStream = [TSAttachmentStream fetchObjectWithUniqueID:self.attachmentId transaction:transaction];
}]; }];
if (!attachmentStream) { if (!attachmentStream) {
OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotLoadAttachment]);
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError(); NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
// Not finding local attachment is a terminal failure. // Not finding a local attachment is a terminal failure
error.isRetryable = NO; error.isRetryable = NO;
[self reportError:error]; [self reportError:error];
return; return;
@ -90,9 +89,9 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.threadID transaction: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(), ^() { .thenOn(dispatch_get_main_queue(), ^() {
[self reportSuccess]; [self reportSuccess];
}) })

Loading…
Cancel
Save