Merge pull request #259 from loki-project/error-handling

Fix Missed Error Handling Case
pull/260/head
Niels Andriesse 5 years ago committed by GitHub
commit 21f8f42517
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -339,7 +339,13 @@ public enum OnionRequestAPI {
} }
} }
promise.catch2 { error in // Must be invoked on LokiAPI.workQueue promise.catch2 { error in // Must be invoked on LokiAPI.workQueue
guard case HTTP.Error.httpRequestFailed(_, _) = error else { return } guard case HTTP.Error.httpRequestFailed(let statusCode, let json) = error else { return }
// Marking all the snodes in the path as unreliable here is aggressive, but otherwise users
// can get stuck with a failing path that just refreshes to the same path.
let path = paths.first { $0.contains(guardSnode) }
path?.forEach { snode in
SnodeAPI.handleError(withStatusCode: statusCode, json: json, forSnode: snode) // Intentionally don't throw
}
dropAllPaths() // A snode in the path is bad; retry with a different path dropAllPaths() // A snode in the path is bad; retry with a different path
dropGuardSnode(guardSnode) dropGuardSnode(guardSnode)
} }

@ -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 {

Loading…
Cancel
Save