Make Mikunj happy

This commit is contained in:
Niels Andriesse 2019-05-07 13:53:31 +10:00
parent f0566d2b05
commit d05b4aa2bf
4 changed files with 13 additions and 13 deletions

View File

@ -20,13 +20,13 @@ public struct LokiMessage {
self.nonce = nonce
}
public static func fromSignalMessage(_ signalMessage: SignalMessage, requiringPOW isPOWRequired: Bool) -> Promise<LokiMessage> {
public static func fromSignalMessage(_ signalMessage: SignalMessage, requiringPoW isPoWRequired: Bool) -> Promise<LokiMessage> {
return Promise<LokiMessage> { seal in
DispatchQueue.global(qos: .default).async {
let destination = signalMessage["destination"]!
let data = signalMessage["content"]!
let ttl = LokiMessagingAPI.defaultTTL
if isPOWRequired {
if isPoWRequired {
let timestamp = UInt64(Date().timeIntervalSince1970)
if let nonce = ProofOfWork.calculate(data: data, pubKey: destination, timestamp: timestamp, ttl: Int(ttl)) {
let result = LokiMessage(destination: destination, data: data, ttl: ttl, timestamp: timestamp, nonce: nonce)

View File

@ -2,8 +2,8 @@ import PromiseKit
@objc public final class LokiMessagingAPI : NSObject {
private static let baseURL = "http://13.238.53.205"
private static let port = "8080"
private static let baseURL = "http://13.238.53.205" // TODO: Temporary
private static let port = "8080" // TODO: Temporary
private static let apiVersion = "v1"
public static let defaultTTL: UInt64 = 4 * 24 * 60 * 60
@ -13,7 +13,7 @@ import PromiseKit
case sendMessage = "store"
}
public typealias RawResponse = TSNetworkManager.NetworkManagerResult
public typealias RawResponse = Any
public enum Error : LocalizedError {
case proofOfWorkCalculationFailed
@ -32,11 +32,11 @@ import PromiseKit
private static func invoke(_ method: Method, parameters: [String:String] = [:]) -> Promise<RawResponse> {
let url = URL(string: "\(baseURL):\(port)/\(apiVersion)/storage_rpc")!
let request = TSRequest(url: url, method: "POST", parameters: [ "method" : method.rawValue, "params" : parameters ])
return TSNetworkManager.shared().makePromise(request: request)
return TSNetworkManager.shared().makePromise(request: request).map { $0.responseObject }
}
public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPOW isPOWRequired: Bool) -> Promise<RawResponse> {
return LokiMessage.fromSignalMessage(signalMessage, requiringPOW: isPOWRequired).then(sendMessage)
public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPoW isPoWRequired: Bool) -> Promise<RawResponse> {
return LokiMessage.fromSignalMessage(signalMessage, requiringPoW: isPoWRequired).then(sendMessage)
}
public static func sendMessage(_ lokiMessage: LokiMessage) -> Promise<RawResponse> {
@ -52,7 +52,7 @@ import PromiseKit
}
// MARK: Obj-C API
@objc public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPOW isPOWRequired: Bool, completionHandler: ((Any?, NSError?) -> Void)? = nil) {
sendSignalMessage(signalMessage, to: destination, requiringPOW: isPOWRequired).done { completionHandler?($0.responseObject, nil) }.catch { completionHandler?(nil, $0 as NSError) }
@objc public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPoW isPoWRequired: Bool, completionHandler: ((Any?, NSError?) -> Void)? = nil) {
sendSignalMessage(signalMessage, to: destination, requiringPoW: isPoWRequired).done { completionHandler?($0, nil) }.catch { completionHandler?(nil, $0 as NSError) }
}
}

View File

@ -80,7 +80,7 @@ private extension MutableCollection where Element == UInt8, Index == Int {
while trialValue > target {
nonce = nonce.increment(by: 1)
// This is different to the bitmessage POW
// This is different to the bitmessage PoW
// resultHash = hash(nonce + hash(data)) ==> hash(nonce + initialHash)
let resultHash = (nonce + initialHash).sha512()
let trialValueArray = Array(resultHash[0..<8])

View File

@ -1099,8 +1099,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
// Convert the message to a Loki message and send it using the Loki messaging API
NSDictionary *signalMessage = deviceMessages.firstObject;
BOOL isPOWRequired = YES; // TODO: Base on message type
[LokiMessagingAPI sendSignalMessage:signalMessage to:recipient.recipientId requiringPOW:isPOWRequired completionHandler:nil];
BOOL isPoWRequired = YES; // TODO: Base on message type
[LokiMessagingAPI sendSignalMessage:signalMessage to:recipient.recipientId requiringPoW:isPoWRequired completionHandler:nil];
// Loki: Original code
/*