Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address report decryption failure #239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion OpenHaystack/OpenHaystack/FindMy/FindMyController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class FindMyController: ObservableObject {

let accessQueue = DispatchQueue(label: "threadSafeAccess", qos: .userInitiated, attributes: .concurrent, autoreleaseFrequency: .workItem, target: nil)
var decryptedReports = [FindMyLocationReport](repeating: FindMyLocationReport(lat: 0, lng: 0, acc: 0, dP: Date(), t: Date(), c: 0), count: reports.count)
var failedDecryptIndexes = [Int]()
DispatchQueue.concurrentPerform(iterations: reports.count) { (reportIdx) in
let report = reports[reportIdx]
guard let key = keyMap[report.id] else { return }
Expand All @@ -215,11 +216,16 @@ class FindMyController: ObservableObject {
decryptedReports[reportIdx] = locationReport
}
} catch {
return
accessQueue.async(flags: .barrier) {
failedDecryptIndexes.append(reportIdx)
}
}
}

accessQueue.sync {
for index in failedDecryptIndexes.sorted(by: { $0 > $1 }) {
decryptedReports.remove(at: index)
}
devices[deviceIdx].decryptedReports = decryptedReports
}
}
Expand Down