Handle rude seed node behavior

This commit is contained in:
Niels Andriesse 2019-06-18 16:01:53 +10:00
parent 09aea1b2f0
commit 517b1b62e6
2 changed files with 5 additions and 5 deletions

View File

@ -9,7 +9,7 @@ public extension LokiAPI {
// MARK: Settings
private static let minimumSnodeCount = 2
private static let targetSnodeCount = 3
fileprivate static let failureThreshold = 3
fileprivate static let failureThreshold = 2
// MARK: Caching
private static let swarmCacheKey = "swarmCacheKey"
@ -51,7 +51,7 @@ public extension LokiAPI {
let rawResponse = intermediate.responseObject
guard let json = rawResponse as? JSON, let intermediate = json["result"] as? JSON, let rawTargets = intermediate["service_node_states"] as? [JSON] else { throw "Failed to update random snode pool from: \(rawResponse)." }
randomSnodePool = try Set(rawTargets.flatMap { rawTarget in
guard let address = rawTarget["public_ip"] as? String, let port = rawTarget["storage_port"] as? Int else {
guard let address = rawTarget["public_ip"] as? String, let port = rawTarget["storage_port"] as? Int, address != "0.0.0.0" else {
print("Failed to update random snode pool from: \(rawTarget).")
return nil
}
@ -88,7 +88,7 @@ public extension LokiAPI {
return []
}
return rawSnodes.flatMap { rawSnode in
guard let address = rawSnode["ip"] as? String, let portAsString = rawSnode["port"] as? String, let port = UInt16(portAsString) else {
guard let address = rawSnode["ip"] as? String, let portAsString = rawSnode["port"] as? String, let port = UInt16(portAsString), address != "0.0.0.0" else {
print("[Loki] Failed to parse target from: \(rawSnode).")
return nil
}

View File

@ -8,8 +8,8 @@ public final class LokiAPI : NSObject {
// MARK: Settings
private static let version = "v1"
private static let maxRetryCount: UInt = 3
private static let defaultTimeout: TimeInterval = 40
private static let maxRetryCount: UInt = 2
private static let defaultTimeout: TimeInterval = 20
private static let longPollingTimeout: TimeInterval = 40
public static let defaultMessageTTL: UInt64 = 24 * 60 * 60 * 1000
internal static var powDifficulty: UInt = 100