diff --git a/Pods b/Pods index 986d4fdce..31f649e59 160000 --- a/Pods +++ b/Pods @@ -1 +1 @@ -Subproject commit 986d4fdcea0e72cfaab54b08918234a61c9824fd +Subproject commit 31f649e593f0d868b514b7aec865f31e7027c364 diff --git a/SignalServiceKit/src/Account/AccountManager.swift b/SignalServiceKit/src/Account/AccountServiceClient.swift similarity index 56% rename from SignalServiceKit/src/Account/AccountManager.swift rename to SignalServiceKit/src/Account/AccountServiceClient.swift index e4cd34e35..da9c5ee06 100644 --- a/SignalServiceKit/src/Account/AccountManager.swift +++ b/SignalServiceKit/src/Account/AccountServiceClient.swift @@ -8,26 +8,27 @@ import PromiseKit // TODO define actual type, and validate length public typealias IdentityKey = Data -@objc(SSKAccountManager) -public class AccountManager: NSObject { +/// based on libsignal-service-java's AccountManager class +@objc(SSKAccountServiceClient) +public class AccountServiceClient: NSObject { - static var shared = AccountManager() + static var shared = AccountServiceClient() - private let serviceSocket: ServiceSocket + private let serviceClient: SignalServiceClient override init() { - self.serviceSocket = ServiceRestSocket() + self.serviceClient = SignalServiceRestClient() } public func getPreKeysCount() -> Promise { - return serviceSocket.getAvailablePreKeys() + return serviceClient.getAvailablePreKeys() } public func setPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise { - return serviceSocket.registerPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) + return serviceClient.registerPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) } public func setSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise { - return serviceSocket.setCurrentSignedPreKey(signedPreKey) + return serviceClient.setCurrentSignedPreKey(signedPreKey) } } diff --git a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift index 020613a5a..b645533d8 100644 --- a/SignalServiceKit/src/Account/CreatePreKeysOperation.swift +++ b/SignalServiceKit/src/Account/CreatePreKeysOperation.swift @@ -7,9 +7,11 @@ import PromiseKit @objc(SSKCreatePreKeysOperation) public class CreatePreKeysOperation: OWSOperation { - private var accountManager: AccountManager { - return AccountManager.shared + + private var accountServiceClient: AccountServiceClient { + return AccountServiceClient.shared } + private var primaryStorage: OWSPrimaryStorage { return OWSPrimaryStorage.shared() } @@ -32,7 +34,7 @@ public class CreatePreKeysOperation: OWSOperation { self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storePreKeyRecords(preKeyRecords) - return self.accountManager.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) + return self.accountServiceClient.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords) }.then { () -> Void in signedPreKeyRecord.markAsAcceptedByService() self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) diff --git a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift index 3129df4b9..935ad3295 100644 --- a/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift +++ b/SignalServiceKit/src/Account/PreKeyRefreshOperation.swift @@ -16,8 +16,8 @@ public class RefreshPreKeysOperation: OWSOperation { return TSAccountManager.sharedInstance() } - private var accountManager: AccountManager { - return AccountManager.shared + private var accountServiceClient: AccountServiceClient { + return AccountServiceClient.shared } private var primaryStorage: OWSPrimaryStorage { @@ -37,7 +37,7 @@ public class RefreshPreKeysOperation: OWSOperation { } firstly { - self.accountManager.getPreKeysCount() + self.accountServiceClient.getPreKeysCount() }.then(on: DispatchQueue.global()) { preKeysCount -> Promise in Logger.debug("preKeysCount: \(preKeysCount)") guard preKeysCount < kEphemeralPreKeysMinimumCount || self.primaryStorage.currentSignedPrekeyId() == nil else { @@ -52,7 +52,7 @@ public class RefreshPreKeysOperation: OWSOperation { self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) self.primaryStorage.storePreKeyRecords(preKeyRecords) - return self.accountManager.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords).then { () -> Void in + return self.accountServiceClient.setPreKeys(identityKey: identityKey, signedPreKeyRecord: signedPreKeyRecord, preKeyRecords: preKeyRecords).then { () -> Void in signedPreKeyRecord.markAsAcceptedByService() self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) diff --git a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift index 1dc893258..a7ba585b6 100644 --- a/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift +++ b/SignalServiceKit/src/Account/RotateSignedKeyOperation.swift @@ -11,8 +11,8 @@ public class RotateSignedPreKeyOperation: OWSOperation { return TSAccountManager.sharedInstance() } - private var accountManager: AccountManager { - return AccountManager.shared + private var accountServiceClient: AccountServiceClient { + return AccountServiceClient.shared } private var primaryStorage: OWSPrimaryStorage { @@ -31,20 +31,20 @@ public class RotateSignedPreKeyOperation: OWSOperation { firstly { self.primaryStorage.storeSignedPreKey(signedPreKeyRecord.id, signedPreKeyRecord: signedPreKeyRecord) - return self.accountManager.setSignedPreKey(signedPreKeyRecord) - }.then(on: DispatchQueue.global()) { () -> Void in - Logger.info("Successfully uploaded signed PreKey") - signedPreKeyRecord.markAsAcceptedByService() - self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) + return self.accountServiceClient.setSignedPreKey(signedPreKeyRecord) + }.then(on: DispatchQueue.global()) { () -> Void in + Logger.info("Successfully uploaded signed PreKey") + signedPreKeyRecord.markAsAcceptedByService() + self.primaryStorage.setCurrentSignedPrekeyId(signedPreKeyRecord.id) - TSPreKeyManager.clearPreKeyUpdateFailureCount() - TSPreKeyManager.clearSignedPreKeyRecords() - }.then { () -> Void in - Logger.debug("done") - self.reportSuccess() - }.catch { error in - self.reportError(error) - }.retainUntilComplete() + TSPreKeyManager.clearPreKeyUpdateFailureCount() + TSPreKeyManager.clearSignedPreKeyRecords() + }.then { () -> Void in + Logger.debug("done") + self.reportSuccess() + }.catch { error in + self.reportError(error) + }.retainUntilComplete() } override public func didFail(error: Error) { diff --git a/SignalServiceKit/src/Network/ServiceSocket.swift b/SignalServiceKit/src/Network/SignalServiceClient.swift similarity index 92% rename from SignalServiceKit/src/Network/ServiceSocket.swift rename to SignalServiceKit/src/Network/SignalServiceClient.swift index f885ffb8e..978e72435 100644 --- a/SignalServiceKit/src/Network/ServiceSocket.swift +++ b/SignalServiceKit/src/Network/SignalServiceClient.swift @@ -5,13 +5,14 @@ import Foundation import PromiseKit -protocol ServiceSocket { +protocol SignalServiceClient { func getAvailablePreKeys() -> Promise func registerPreKeys(identityKey: IdentityKey, signedPreKeyRecord: SignedPreKeyRecord, preKeyRecords: [PreKeyRecord]) -> Promise func setCurrentSignedPreKey(_ signedPreKey: SignedPreKeyRecord) -> Promise } -class ServiceRestSocket: ServiceSocket { +/// Based on libsignal-service-java's PushServiceSocket class +class SignalServiceRestClient: SignalServiceClient { var networkManager: TSNetworkManager { return TSNetworkManager.shared()