Don't retry proof of work calculation

pull/35/head
Niels Andriesse 6 years ago
parent 353186919e
commit 99ab556bf8

@ -73,22 +73,22 @@ public final class LokiAPI : NSObject {
return invoke(.sendMessage, on: target, associatedWith: destination, parameters: parameters) return invoke(.sendMessage, on: target, associatedWith: destination, parameters: parameters)
} }
func sendLokiMessageUsingSwarmAPI() -> Promise<Set<RawResponsePromise>> { func sendLokiMessageUsingSwarmAPI() -> Promise<Set<RawResponsePromise>> {
let powPromise = lokiMessage.calculatePoW() return lokiMessage.calculatePoW().then { lokiMessageWithPoW in
let swarmPromise = getTargetSnodes(for: destination) return getTargetSnodes(for: destination).map { swarm in
return when(fulfilled: powPromise, swarmPromise).map { lokiMessageWithPoW, swarm in return Set(swarm.map { target in
return Set(swarm.map { sendLokiMessage(lokiMessageWithPoW, to: target).map { rawResponse in
sendLokiMessage(lokiMessageWithPoW, to: $0).map { rawResponse in if let json = rawResponse as? JSON, let powDifficulty = json["difficulty"] as? Int {
if let json = rawResponse as? JSON, let powDifficulty = json["difficulty"] as? Int { guard powDifficulty != LokiAPI.powDifficulty else { return rawResponse }
guard powDifficulty != LokiAPI.powDifficulty else { return rawResponse } print("[Loki] Setting proof of work difficulty to \(powDifficulty).")
print("[Loki] Setting proof of work difficulty to \(powDifficulty).") LokiAPI.powDifficulty = UInt(powDifficulty)
LokiAPI.powDifficulty = UInt(powDifficulty) } else {
} else { print("[Loki] Failed to update proof of work difficulty from: \(rawResponse).")
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) { if let peer = LokiP2PAPI.getInfo(for: destination), (lokiMessage.isPing || peer.isOnline) {
let target = LokiAPITarget(address: peer.address, port: peer.port) let target = LokiAPITarget(address: peer.address, port: peer.port)

Loading…
Cancel
Save