pull/214/head
nielsandriesse 5 years ago
parent 4506dc55de
commit 8843e8c495

@ -12,7 +12,7 @@ public extension LokiAPI {
// MARK: Settings // MARK: Settings
private static let minimumSnodePoolCount = 32 private static let minimumSnodePoolCount = 32
private static let minimumSwarmSnodeCount = 2 private static let minimumSwarmSnodeCount = 2
private static let targetSwarmSnodeCount = 3 private static let targetSwarmSnodeCount = 2
internal static let snodeFailureThreshold = 2 internal static let snodeFailureThreshold = 2

@ -70,8 +70,8 @@ public final class LokiPoller : NSObject {
} }
private func pollNextSnode(seal: Resolver<Void>) { private func pollNextSnode(seal: Resolver<Void>) {
let userHexEncodedPublicKey = getUserHexEncodedPublicKey() let userPublicKey = getUserHexEncodedPublicKey()
let swarm = LokiAPI.swarmCache[userHexEncodedPublicKey] ?? [] let swarm = LokiAPI.swarmCache[userPublicKey] ?? []
let unusedSnodes = Set(swarm).subtracting(usedSnodes) let unusedSnodes = Set(swarm).subtracting(usedSnodes)
if !unusedSnodes.isEmpty { if !unusedSnodes.isEmpty {
// randomElement() uses the system's default random generator, which is cryptographically secure // randomElement() uses the system's default random generator, which is cryptographically secure
@ -84,7 +84,7 @@ public final class LokiPoller : NSObject {
self?.pollCount = 0 self?.pollCount = 0
} else { } else {
print("[Loki] Polling \(nextSnode) failed; dropping it and switching to next snode.") print("[Loki] Polling \(nextSnode) failed; dropping it and switching to next snode.")
LokiAPI.dropSnodeFromSwarmIfNeeded(nextSnode, hexEncodedPublicKey: userHexEncodedPublicKey) LokiAPI.dropSnodeFromSwarmIfNeeded(nextSnode, hexEncodedPublicKey: userPublicKey)
} }
self?.pollNextSnode(seal: seal) self?.pollNextSnode(seal: seal)
} }

@ -70,7 +70,7 @@ public final class MultiDeviceProtocol : NSObject {
threadPromiseSeal.fulfill(thread) threadPromiseSeal.fulfill(thread)
} }
} }
return threadPromise.then(on: DispatchQueue.main) { thread -> Promise<Void> in // Intentionally the main queue return threadPromise.then2 { thread -> Promise<Void> in
let message = messageSend.message let message = messageSend.message
let messageSender = SSKEnvironment.shared.messageSender let messageSender = SSKEnvironment.shared.messageSender
let (promise, seal) = Promise<Void>.pending() let (promise, seal) = Promise<Void>.pending()
@ -108,7 +108,7 @@ public final class MultiDeviceProtocol : NSObject {
} }
print("[Loki] Sending \(type(of: message)) message using multi device routing.") print("[Loki] Sending \(type(of: message)) message using multi device routing.")
let recipientID = messageSend.recipient.recipientId() let recipientID = messageSend.recipient.recipientId()
getMultiDeviceDestinations(for: recipientID, in: transaction).done(on: OWSDispatch.sendingQueue()) { destinations in getMultiDeviceDestinations(for: recipientID, in: transaction).done2 { destinations in
var promises: [Promise<Void>] = [] var promises: [Promise<Void>] = []
let masterDestination = destinations.first { $0.isMaster } let masterDestination = destinations.first { $0.isMaster }
if let masterDestination = masterDestination { if let masterDestination = masterDestination {
@ -136,7 +136,7 @@ public final class MultiDeviceProtocol : NSObject {
messageSend.failure(errors.first!) messageSend.failure(errors.first!)
} }
} }
}.catch(on: DispatchQueue.main) { error in // Intentionally the main queue }.catch2 { error in
// Proceed even if updating the recipient's device links failed, so that message sending // Proceed even if updating the recipient's device links failed, so that message sending
// is independent of whether the file server is online // is independent of whether the file server is online
let udManager = SSKEnvironment.shared.udManager let udManager = SSKEnvironment.shared.udManager

@ -73,6 +73,9 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
return return
} }
self.add(jobRecord: jobRecord, transaction: transaction) self.add(jobRecord: jobRecord, transaction: transaction)
transaction.addCompletionQueue(DispatchQueue.global()) {
self.workStep() // Loki: Hack to make message sending faster until we have decentralized multi device and no more proof of work
}
} }
// MARK: JobQueue // MARK: JobQueue

@ -126,21 +126,21 @@ public extension JobQueue {
jobRecord.save(with: transaction) jobRecord.save(with: transaction)
transaction.addCompletionQueue(DispatchQueue.global(qos: .userInitiated)) { transaction.addCompletionQueue(DispatchQueue.global()) {
self.startWorkWhenAppIsReady() self.startWorkWhenAppIsReady()
} }
} }
func startWorkWhenAppIsReady() { func startWorkWhenAppIsReady() {
guard !CurrentAppContext().isRunningTests else { guard !CurrentAppContext().isRunningTests else {
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global().async {
self.workStep() self.workStep()
} }
return return
} }
AppReadiness.runNowOrWhenAppDidBecomeReady { AppReadiness.runNowOrWhenAppDidBecomeReady {
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global().async {
self.workStep() self.workStep()
} }
} }
@ -190,7 +190,7 @@ public extension JobQueue {
owsFailDebug("unexpected error") owsFailDebug("unexpected error")
} }
DispatchQueue.global(qos: .userInitiated).async { DispatchQueue.global().async {
self.workStep() self.workStep()
} }
} }

Loading…
Cancel
Save