|
|
@ -296,7 +296,7 @@ public final class SnodeAPI : NSObject {
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: Error Handling
|
|
|
|
// MARK: Error Handling
|
|
|
|
/// - Note: Should only be invoked from `LokiAPI.workQueue` to avoid race conditions.
|
|
|
|
/// - Note: Should only be invoked from `LokiAPI.workQueue` to avoid race conditions.
|
|
|
|
internal static func handleError(withStatusCode statusCode: UInt, json: JSON?, forSnode snode: Snode, associatedWith publicKey: String) -> Error? {
|
|
|
|
internal static func handleError(withStatusCode statusCode: UInt, json: JSON?, forSnode snode: Snode, associatedWith publicKey: String? = nil) -> Error? {
|
|
|
|
#if DEBUG
|
|
|
|
#if DEBUG
|
|
|
|
assertOnQueue(SnodeAPI.workQueue)
|
|
|
|
assertOnQueue(SnodeAPI.workQueue)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -307,7 +307,9 @@ public final class SnodeAPI : NSObject {
|
|
|
|
print("[Loki] Couldn't reach snode at: \(snode); setting failure count to \(newFailureCount).")
|
|
|
|
print("[Loki] Couldn't reach snode at: \(snode); setting failure count to \(newFailureCount).")
|
|
|
|
if newFailureCount >= SnodeAPI.snodeFailureThreshold {
|
|
|
|
if newFailureCount >= SnodeAPI.snodeFailureThreshold {
|
|
|
|
print("[Loki] Failure threshold reached for: \(snode); dropping it.")
|
|
|
|
print("[Loki] Failure threshold reached for: \(snode); dropping it.")
|
|
|
|
SnodeAPI.dropSnodeFromSwarmIfNeeded(snode, publicKey: publicKey)
|
|
|
|
if let publicKey = publicKey {
|
|
|
|
|
|
|
|
SnodeAPI.dropSnodeFromSwarmIfNeeded(snode, publicKey: publicKey)
|
|
|
|
|
|
|
|
}
|
|
|
|
SnodeAPI.dropSnodeFromSnodePool(snode)
|
|
|
|
SnodeAPI.dropSnodeFromSnodePool(snode)
|
|
|
|
SnodeAPI.snodeFailureCount[snode] = 0
|
|
|
|
SnodeAPI.snodeFailureCount[snode] = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -321,8 +323,12 @@ public final class SnodeAPI : NSObject {
|
|
|
|
return SnodeAPI.SnodeAPIError.clockOutOfSync
|
|
|
|
return SnodeAPI.SnodeAPIError.clockOutOfSync
|
|
|
|
case 421:
|
|
|
|
case 421:
|
|
|
|
// The snode isn't associated with the given public key anymore
|
|
|
|
// The snode isn't associated with the given public key anymore
|
|
|
|
print("[Loki] Invalidating swarm for: \(publicKey).")
|
|
|
|
if let publicKey = publicKey {
|
|
|
|
SnodeAPI.dropSnodeFromSwarmIfNeeded(snode, publicKey: publicKey)
|
|
|
|
print("[Loki] Invalidating swarm for: \(publicKey).")
|
|
|
|
|
|
|
|
SnodeAPI.dropSnodeFromSwarmIfNeeded(snode, publicKey: publicKey)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
print("[Loki] Got a 421 without an associated public key.")
|
|
|
|
|
|
|
|
}
|
|
|
|
case 432:
|
|
|
|
case 432:
|
|
|
|
// The proof of work difficulty is too low
|
|
|
|
// The proof of work difficulty is too low
|
|
|
|
if let powDifficulty = json?["difficulty"] as? UInt {
|
|
|
|
if let powDifficulty = json?["difficulty"] as? UInt {
|
|
|
|