diff --git a/SignalServiceKit/src/Loki/API/LokiAPI.swift b/SignalServiceKit/src/Loki/API/LokiAPI.swift index 59a511965..86f30afb6 100644 --- a/SignalServiceKit/src/Loki/API/LokiAPI.swift +++ b/SignalServiceKit/src/Loki/API/LokiAPI.swift @@ -65,18 +65,15 @@ import PromiseKit } } - // By default our p2p throws and we recover by sending to storage server - var p2pPromise: Promise>> = Promise(error: Error.internalError) + // If we have the p2p details then send message to that + // If that failes then fallback to storage server // TODO: probably only send to p2p if user is online or we are pinging them // p2pDetails && (isPing || peerIsOnline) - if let p2pDetails = contactP2PDetails[destination] { - p2pPromise = sendMessage(message, targets: [p2pDetails]) + return sendMessage(message, targets: [p2pDetails]).recover { _ in return sendThroughStorageServer() } } - // If we have the p2p details then send message to that - // If that failes then fallback to storage server - return p2pPromise.recover { _ in return sendThroughStorageServer() } + return sendThroughStorageServer() } internal static func sendMessage(_ lokiMessage: Message, targets: [Target]) -> Promise>> { diff --git a/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift b/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift index 7d2afd2a2..87b331e05 100644 --- a/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift +++ b/SignalServiceKit/src/Loki/Crypto/ProofOfWork.swift @@ -103,7 +103,8 @@ public enum ProofOfWork { // Do all the calculations let totalLength = UInt64(payloadLength + nonceLength) - let ttlMult = ttl * totalLength + let ttlSeconds = ttl / 1000 + let ttlMult = ttlSeconds * totalLength // UInt64 values let innerFrac = ttlMult / two16