From 2ea088e00a029604fb45a94c8b20840a6a9fb70c Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Tue, 27 Oct 2020 15:21:26 +1100 Subject: [PATCH] Add missing retry --- SignalServiceKit/src/Loki/API/DotNetAPI.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/SignalServiceKit/src/Loki/API/DotNetAPI.swift b/SignalServiceKit/src/Loki/API/DotNetAPI.swift index 6f574985c..ec59ced68 100644 --- a/SignalServiceKit/src/Loki/API/DotNetAPI.swift +++ b/SignalServiceKit/src/Loki/API/DotNetAPI.swift @@ -8,6 +8,7 @@ public class DotNetAPI : NSObject { // MARK: Settings private static let attachmentType = "network.loki" + private static let maxRetryCount: UInt = 4 // MARK: Error @objc(LKDotNetAPIError) @@ -123,13 +124,15 @@ public class DotNetAPI : NSObject { } let serverPublicKeyPromise = FileServerAPI.server.contains(host) ? Promise.value(FileServerAPI.fileServerPublicKey) : PublicChatAPI.getOpenGroupServerPublicKey(for: host) - return serverPublicKeyPromise.then2 { serverPublicKey in - return OnionRequestAPI.sendOnionRequest(request, to: host, using: serverPublicKey, isJSONRequired: false).map2 { json in - guard let body = json["body"] as? JSON, let data = body["data"] as? [UInt8] else { - print("[Loki] Couldn't parse attachment from: \(json).") - throw DotNetAPIError.parsingFailed + return attempt(maxRetryCount: maxRetryCount, recoveringOn: SnodeAPI.workQueue) { + serverPublicKeyPromise.then2 { serverPublicKey in + return OnionRequestAPI.sendOnionRequest(request, to: host, using: serverPublicKey, isJSONRequired: false).map2 { json in + guard let body = json["body"] as? JSON, let data = body["data"] as? [UInt8] else { + print("[Loki] Couldn't parse attachment from: \(json).") + throw DotNetAPIError.parsingFailed + } + return Data(data) } - return Data(data) } } }