mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Fix thread safety issues
This commit is contained in:
parent
1b61330669
commit
d0a3758ff4
4 changed files with 81 additions and 6 deletions
|
@ -1,13 +1,58 @@
|
|||
import PromiseKit
|
||||
|
||||
public extension LokiAPI {
|
||||
private static var snodeVersion: [LokiAPITarget:String] = [:]
|
||||
|
||||
fileprivate static let seedNodePool: Set<String> = [ "https://storage.seed1.loki.network", "https://storage.seed3.loki.network", "https://public.loki.foundation" ]
|
||||
|
||||
internal static var snodeFailureCount: [LokiAPITarget:UInt] = [:]
|
||||
internal static var snodePool: Set<LokiAPITarget> = []
|
||||
internal static var swarmCache: [String:[LokiAPITarget]] = [:] // TODO: Make this set based?
|
||||
internal static var _snodeFailureCount: [LokiAPITarget:UInt] = [:]
|
||||
internal static var snodeFailureCount: [LokiAPITarget:UInt] {
|
||||
get {
|
||||
let (promise, seal) = Promise<[LokiAPITarget:UInt]>.pending()
|
||||
stateQueue.async {
|
||||
seal.fulfill(_snodeFailureCount)
|
||||
}
|
||||
return try! promise.wait()
|
||||
}
|
||||
set {
|
||||
LokiAPI.stateQueue.async {
|
||||
_snodeFailureCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Read/write this directly from/to the database
|
||||
internal static var _snodePool: Set<LokiAPITarget> = []
|
||||
internal static var snodePool: Set<LokiAPITarget> {
|
||||
get {
|
||||
let (promise, seal) = Promise<Set<LokiAPITarget>>.pending()
|
||||
stateQueue.async {
|
||||
seal.fulfill(_snodePool)
|
||||
}
|
||||
return try! promise.wait()
|
||||
}
|
||||
set {
|
||||
LokiAPI.stateQueue.async {
|
||||
_snodePool = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Read/write this directly from/to the database
|
||||
internal static var _swarmCache: [String:[LokiAPITarget]] = [:]
|
||||
internal static var swarmCache: [String:[LokiAPITarget]] {
|
||||
get {
|
||||
let (promise, seal) = Promise<[String:[LokiAPITarget]]>.pending()
|
||||
stateQueue.async {
|
||||
seal.fulfill(_swarmCache)
|
||||
}
|
||||
return try! promise.wait()
|
||||
}
|
||||
set {
|
||||
LokiAPI.stateQueue.async {
|
||||
_swarmCache = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Settings
|
||||
private static let minimumSnodePoolCount = 32
|
||||
|
|
|
@ -2,6 +2,7 @@ import PromiseKit
|
|||
|
||||
@objc(LKAPI)
|
||||
public final class LokiAPI : NSObject {
|
||||
internal static let stateQueue = DispatchQueue(label: "LokiAPI.stateQueue", qos: .userInitiated)
|
||||
|
||||
internal static var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
|
||||
|
||||
|
|
|
@ -1,9 +1,24 @@
|
|||
import PromiseKit
|
||||
|
||||
@objc(LKMentionsManager)
|
||||
public final class MentionsManager : NSObject {
|
||||
|
||||
@objc public static var _userPublicKeyCache: [String:Set<String>] = [:]
|
||||
/// A mapping from thread ID to set of user hex encoded public keys.
|
||||
@objc public static var userPublicKeyCache: [String:Set<String>] = [:]
|
||||
@objc public static var userPublicKeyCache: [String:Set<String>] {
|
||||
get {
|
||||
let (promise, seal) = Promise<[String:Set<String>]>.pending()
|
||||
LokiAPI.stateQueue.async {
|
||||
seal.fulfill(_userPublicKeyCache)
|
||||
}
|
||||
return try! promise.wait()
|
||||
}
|
||||
set {
|
||||
LokiAPI.stateQueue.async {
|
||||
_userPublicKeyCache = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
|
||||
|
||||
|
|
|
@ -15,8 +15,22 @@ import PromiseKit
|
|||
@objc(LKMultiDeviceProtocol)
|
||||
public final class MultiDeviceProtocol : NSObject {
|
||||
|
||||
public static var _lastDeviceLinkUpdate: [String:Date] = [:]
|
||||
/// A mapping from hex encoded public key to date updated.
|
||||
public static var lastDeviceLinkUpdate: [String:Date] = [:]
|
||||
public static var lastDeviceLinkUpdate: [String:Date] {
|
||||
get {
|
||||
let (promise, seal) = Promise<[String:Date]>.pending()
|
||||
LokiAPI.stateQueue.async {
|
||||
seal.fulfill(_lastDeviceLinkUpdate)
|
||||
}
|
||||
return try! promise.wait()
|
||||
}
|
||||
set {
|
||||
LokiAPI.stateQueue.async {
|
||||
_lastDeviceLinkUpdate = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
|
||||
|
||||
|
|
Loading…
Reference in a new issue