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

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

@ -70,8 +70,8 @@ public final class LokiPoller : NSObject {
}
private func pollNextSnode(seal: Resolver<Void>) {
let userHexEncodedPublicKey = getUserHexEncodedPublicKey()
let swarm = LokiAPI.swarmCache[userHexEncodedPublicKey] ?? []
let userPublicKey = getUserHexEncodedPublicKey()
let swarm = LokiAPI.swarmCache[userPublicKey] ?? []
let unusedSnodes = Set(swarm).subtracting(usedSnodes)
if !unusedSnodes.isEmpty {
// randomElement() uses the system's default random generator, which is cryptographically secure
@ -84,7 +84,7 @@ public final class LokiPoller : NSObject {
self?.pollCount = 0
} else {
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)
}

@ -70,7 +70,7 @@ public final class MultiDeviceProtocol : NSObject {
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 messageSender = SSKEnvironment.shared.messageSender
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.")
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>] = []
let masterDestination = destinations.first { $0.isMaster }
if let masterDestination = masterDestination {
@ -136,7 +136,7 @@ public final class MultiDeviceProtocol : NSObject {
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
// is independent of whether the file server is online
let udManager = SSKEnvironment.shared.udManager

@ -73,6 +73,9 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
return
}
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

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

Loading…
Cancel
Save