From ac0a20c8a781f4b61a1f6e3b6e7612f2d9817547 Mon Sep 17 00:00:00 2001 From: gmbnt Date: Tue, 7 Apr 2020 10:52:41 +1000 Subject: [PATCH] Improve threading --- .../API/Onion Requests/OnionRequestAPI+Encryption.swift | 8 ++------ .../src/Loki/API/Onion Requests/OnionRequestAPI.swift | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift index 091eb1cef..8b626b0ad 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI+Encryption.swift @@ -7,10 +7,6 @@ extension OnionRequestAPI { internal typealias EncryptionResult = (ciphertext: Data, symmetricKey: Data, ephemeralPublicKey: Data) - private static func getQueue() -> DispatchQueue { - return DispatchQueue(label: UUID().uuidString, qos: .userInitiated) - } - /// Returns `size` bytes of random data generated using the default secure random number generator. See /// [SecRandomCopyBytes](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes) for more information. private static func getSecureRandomData(ofSize size: UInt) throws -> Data { @@ -46,7 +42,7 @@ extension OnionRequestAPI { /// Encrypts `payload` for `snode` and returns the result. Use this to build the core of an onion request. internal static func encrypt(_ payload: JSON, forTargetSnode snode: LokiAPITarget) -> Promise { let (promise, seal) = Promise.pending() - getQueue().async { + DispatchQueue.global().async { do { guard JSONSerialization.isValidJSONObject(payload) else { return seal.reject(HTTP.Error.invalidJSON) } let payloadAsData = try JSONSerialization.data(withJSONObject: payload, options: []) @@ -66,7 +62,7 @@ extension OnionRequestAPI { /// Encrypts the previous encryption result (i.e. that of the hop after this one) for this hop. Use this to build the layers of an onion request. internal static func encryptHop(from lhs: LokiAPITarget, to rhs: LokiAPITarget, using previousEncryptionResult: EncryptionResult) -> Promise { let (promise, seal) = Promise.pending() - getQueue().async { + DispatchQueue.global().async { let parameters: JSON = [ "ciphertext" : previousEncryptionResult.ciphertext.base64EncodedString(), "ephemeral_key" : previousEncryptionResult.ephemeralPublicKey.toHexString(), diff --git a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift index f364f1822..a4ea0e4df 100644 --- a/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift +++ b/SignalServiceKit/src/Loki/API/Onion Requests/OnionRequestAPI.swift @@ -53,7 +53,7 @@ internal enum OnionRequestAPI { /// Tests the given snode. The returned promise errors out if the snode is faulty; the promise is fulfilled otherwise. private static func testSnode(_ snode: LokiAPITarget) -> Promise { let (promise, seal) = Promise.pending() - let queue = DispatchQueue(label: UUID().uuidString, qos: .userInitiated) // No need to block the work queue for this + let queue = DispatchQueue.global() // No need to block the work queue for this queue.async { let url = "\(snode.address):\(snode.port)/get_stats/v1" let timeout: TimeInterval = 6 // Use a shorter timeout for testing