From 99ab556bf8e1456c2ecea428f7eefe654c331cea Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Fri, 2 Aug 2019 09:28:04 +1000 Subject: [PATCH] Don't retry proof of work calculation --- SignalServiceKit/src/Loki/API/LokiAPI.swift | 30 ++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index e9391e498..a79a45eac 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -73,22 +73,22 @@ public final class LokiAPI : NSObject { return invoke(.sendMessage, on: target, associatedWith: destination, parameters: parameters) } func sendLokiMessageUsingSwarmAPI() -> Promise> { - let powPromise = lokiMessage.calculatePoW() - let swarmPromise = getTargetSnodes(for: destination) - return when(fulfilled: powPromise, swarmPromise).map { lokiMessageWithPoW, swarm in - return Set(swarm.map { - sendLokiMessage(lokiMessageWithPoW, to: $0).map { rawResponse in - if let json = rawResponse as? JSON, let powDifficulty = json["difficulty"] as? Int { - guard powDifficulty != LokiAPI.powDifficulty else { return rawResponse } - print("[Loki] Setting proof of work difficulty to \(powDifficulty).") - LokiAPI.powDifficulty = UInt(powDifficulty) - } else { - print("[Loki] Failed to update proof of work difficulty from: \(rawResponse).") + return lokiMessage.calculatePoW().then { lokiMessageWithPoW in + return getTargetSnodes(for: destination).map { swarm in + return Set(swarm.map { target in + sendLokiMessage(lokiMessageWithPoW, to: target).map { rawResponse in + if let json = rawResponse as? JSON, let powDifficulty = json["difficulty"] as? Int { + guard powDifficulty != LokiAPI.powDifficulty else { return rawResponse } + print("[Loki] Setting proof of work difficulty to \(powDifficulty).") + LokiAPI.powDifficulty = UInt(powDifficulty) + } else { + print("[Loki] Failed to update proof of work difficulty from: \(rawResponse).") + } + return rawResponse } - return rawResponse - } - }) - }.retryingIfNeeded(maxRetryCount: maxRetryCount) + }) + }.retryingIfNeeded(maxRetryCount: maxRetryCount) + } } if let peer = LokiP2PAPI.getInfo(for: destination), (lokiMessage.isPing || peer.isOnline) { let target = LokiAPITarget(address: peer.address, port: peer.port)