mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.4 KiB
Swift
67 lines
2.4 KiB
Swift
3 years ago
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
||
|
|
||
|
import Foundation
|
||
|
|
||
3 years ago
|
public enum SSKLegacy {
|
||
3 years ago
|
// MARK: - Collections and Keys
|
||
|
|
||
|
internal static let swarmCollectionPrefix = "LokiSwarmCollection-"
|
||
3 years ago
|
internal static let lastSnodePoolRefreshDateKey = "lastSnodePoolRefreshDate"
|
||
3 years ago
|
internal static let snodePoolCollection = "LokiSnodePoolCollection"
|
||
|
internal static let onionRequestPathCollection = "LokiOnionRequestPathCollection"
|
||
|
internal static let lastSnodePoolRefreshDateCollection = "LokiLastSnodePoolRefreshDateCollection"
|
||
3 years ago
|
internal static let lastMessageHashCollection = "LokiLastMessageHashCollection"
|
||
3 years ago
|
internal static let receivedMessagesCollection = "LokiReceivedMessagesCollection"
|
||
|
|
||
|
// MARK: - Types
|
||
|
|
||
|
public typealias LegacyOnionRequestAPIPath = [Snode]
|
||
|
|
||
|
@objc(Snode)
|
||
3 years ago
|
public final class Snode: NSObject, NSCoding {
|
||
3 years ago
|
public let address: String
|
||
|
public let port: UInt16
|
||
|
public let publicKeySet: KeySet
|
||
|
|
||
3 years ago
|
// MARK: - Nested Types
|
||
3 years ago
|
|
||
|
public struct KeySet {
|
||
|
public let ed25519Key: String
|
||
|
public let x25519Key: String
|
||
|
}
|
||
3 years ago
|
|
||
|
// MARK: - NSCoding
|
||
|
|
||
3 years ago
|
public init?(coder: NSCoder) {
|
||
|
address = coder.decodeObject(forKey: "address") as! String
|
||
|
port = coder.decodeObject(forKey: "port") as! UInt16
|
||
3 years ago
|
|
||
|
guard
|
||
|
let idKey = coder.decodeObject(forKey: "idKey") as? String,
|
||
|
let encryptionKey = coder.decodeObject(forKey: "encryptionKey") as? String
|
||
|
else { return nil }
|
||
|
|
||
3 years ago
|
publicKeySet = KeySet(ed25519Key: idKey, x25519Key: encryptionKey)
|
||
3 years ago
|
|
||
3 years ago
|
super.init()
|
||
|
}
|
||
|
|
||
|
public func encode(with coder: NSCoder) {
|
||
3 years ago
|
fatalError("encode(with:) should never be called for legacy types")
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
// Note: The 'isEqual' and 'hash' overrides are both needed to ensure the migration
|
||
|
// doesn't try to insert duplicate SNode entries into the new database (which would
|
||
|
// result in unique key constraint violations)
|
||
3 years ago
|
override public func isEqual(_ other: Any?) -> Bool {
|
||
|
guard let other = other as? Snode else { return false }
|
||
3 years ago
|
|
||
3 years ago
|
return address == other.address && port == other.port
|
||
|
}
|
||
|
|
||
3 years ago
|
override public var hash: Int {
|
||
3 years ago
|
return address.hashValue ^ port.hashValue
|
||
|
}
|
||
|
}
|
||
|
}
|