diff options
| author | mojganii <mojgan.jelodar@codic.se> | 2023-12-07 10:42:04 +0100 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2023-12-11 11:44:56 +0100 |
| commit | fef5f92b867126342192901c6abc7ec8514a4ea9 (patch) | |
| tree | a318784b80038850595a2f49def292930d770051 /ios/RelayCache | |
| parent | 6873304ac722cd1c96020a8d4dda4942beebc886 (diff) | |
| download | mullvadvpn-fef5f92b867126342192901c6abc7ec8514a4ea9.tar.xz mullvadvpn-fef5f92b867126342192901c6abc7ec8514a4ea9.zip | |
Moving RelayCache into MullvadREST
Diffstat (limited to 'ios/RelayCache')
| -rw-r--r-- | ios/RelayCache/Assets/.gitkeep | 0 | ||||
| -rw-r--r-- | ios/RelayCache/CachedRelays.swift | 28 | ||||
| -rw-r--r-- | ios/RelayCache/RelayCache.h | 19 | ||||
| -rw-r--r-- | ios/RelayCache/RelayCache.swift | 63 |
4 files changed, 0 insertions, 110 deletions
diff --git a/ios/RelayCache/Assets/.gitkeep b/ios/RelayCache/Assets/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 --- a/ios/RelayCache/Assets/.gitkeep +++ /dev/null diff --git a/ios/RelayCache/CachedRelays.swift b/ios/RelayCache/CachedRelays.swift deleted file mode 100644 index 499eb9cde3..0000000000 --- a/ios/RelayCache/CachedRelays.swift +++ /dev/null @@ -1,28 +0,0 @@ -// -// CachedRelays.swift -// CachedRelays -// -// Created by pronebird on 27/07/2021. -// Copyright © 2021 Mullvad VPN AB. All rights reserved. -// - -import Foundation -import MullvadREST - -/// A struct that represents the relay cache on disk -public struct CachedRelays: Codable, Equatable { - /// E-tag returned by server - public let etag: String? - - /// The relay list stored within the cache entry - public let relays: REST.ServerRelaysResponse - - /// The date when this cache was last updated - public let updatedAt: Date - - public init(etag: String? = nil, relays: REST.ServerRelaysResponse, updatedAt: Date) { - self.etag = etag - self.relays = relays - self.updatedAt = updatedAt - } -} diff --git a/ios/RelayCache/RelayCache.h b/ios/RelayCache/RelayCache.h deleted file mode 100644 index abe3d1b983..0000000000 --- a/ios/RelayCache/RelayCache.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// RelayCache.h -// RelayCache -// -// Created by Sajad Vishkai on 2022-10-21. -// Copyright © 2022 Mullvad VPN AB. All rights reserved. -// - -#import <Foundation/Foundation.h> - -//! Project version number for RelayCache. -FOUNDATION_EXPORT double RelayCacheVersionNumber; - -//! Project version string for RelayCache. -FOUNDATION_EXPORT const unsigned char RelayCacheVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import <RelayCache/PublicHeader.h> - - diff --git a/ios/RelayCache/RelayCache.swift b/ios/RelayCache/RelayCache.swift deleted file mode 100644 index ba7ed31cf1..0000000000 --- a/ios/RelayCache/RelayCache.swift +++ /dev/null @@ -1,63 +0,0 @@ -// -// RelayCache.swift -// RelayCache -// -// Created by pronebird on 06/09/2021. -// Copyright © 2021 Mullvad VPN AB. All rights reserved. -// - -import Foundation -import MullvadREST -import MullvadTypes - -public protocol RelayCacheProtocol { - func read() throws -> CachedRelays - func write(record: CachedRelays) throws -} - -public final class RelayCache: RelayCacheProtocol { - private let fileCache: any FileCacheProtocol<CachedRelays> - - /// Designated initializer - public init(cacheDirectory: URL) { - fileCache = FileCache(fileURL: cacheDirectory.appendingPathComponent("relays.json", isDirectory: false)) - } - - /// Initializer that accepts a custom FileCache implementation. Used in tests. - init(fileCache: some FileCacheProtocol<CachedRelays>) { - self.fileCache = fileCache - } - - /// Safely read the cache file from disk using file coordinator and fallback to prebundled - /// relays in case if the relay cache file is missing. - public func read() throws -> CachedRelays { - do { - return try fileCache.read() - } catch { - if error is DecodingError || (error as? CocoaError)?.code == .fileReadNoSuchFile { - return try readPrebundledRelays() - } else { - throw error - } - } - } - - /// Safely write the cache file on disk using file coordinator. - public func write(record: CachedRelays) throws { - try fileCache.write(record) - } - - /// Read pre-bundled relays file from disk. - private func readPrebundledRelays() throws -> CachedRelays { - guard let prebundledRelaysFileURL = Bundle(for: Self.self).url(forResource: "relays", withExtension: "json") - else { throw CocoaError(.fileNoSuchFile) } - - let data = try Data(contentsOf: prebundledRelaysFileURL) - let relays = try REST.Coding.makeJSONDecoder().decode(REST.ServerRelaysResponse.self, from: data) - - return CachedRelays( - relays: relays, - updatedAt: Date(timeIntervalSince1970: 0) - ) - } -} |
