Skip to content

Commit

Permalink
Fix building for Xcode 15 and 16
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Oct 24, 2024
1 parent eba4129 commit 8d3ad1b
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 114 deletions.
8 changes: 4 additions & 4 deletions ios/MullvadVPN/AddressCacheTracker/AddressCacheTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class AddressCacheTracker {

/// Logger.
private let logger = Logger(label: "AddressCache.Tracker")
private let application: UIApplication
private let backgroundTaskProvider: BackgroundTaskProviding

/// REST API proxy.
private let apiProxy: APIQuerying
Expand All @@ -45,8 +45,8 @@ final class AddressCacheTracker {
private let nslock = NSLock()

/// Designated initializer
init(application: UIApplication, apiProxy: APIQuerying, store: REST.AddressCache) {
self.application = application
init(backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying, store: REST.AddressCache) {
self.backgroundTaskProvider = backgroundTaskProvider
self.apiProxy = apiProxy
self.store = store
}
Expand Down Expand Up @@ -103,7 +103,7 @@ final class AddressCacheTracker {

operation.addObserver(
BackgroundObserver(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
name: "Update endpoints",
cancelUponExpiration: true
)
Expand Down
26 changes: 19 additions & 7 deletions ios/MullvadVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
let tunnelSettingsListener = TunnelSettingsListener()
let tunnelSettingsUpdater = SettingsUpdater(listener: tunnelSettingsListener)

let backgroundTaskProvider = BackgroundTaskProvider(
backgroundTimeRemaining: application.backgroundTimeRemaining,
application: application
)

relayCacheTracker = RelayCacheTracker(
relayCache: ipOverrideWrapper,
application: application,
backgroundTaskProvider: backgroundTaskProvider,
apiProxy: apiProxy
)

addressCacheTracker = AddressCacheTracker(application: application, apiProxy: apiProxy, store: addressCache)
addressCacheTracker = AddressCacheTracker(
backgroundTaskProvider: backgroundTaskProvider,
apiProxy: apiProxy,
store: addressCache
)

tunnelStore = TunnelStore(application: application)
tunnelStore = TunnelStore(application: backgroundTaskProvider)

let relaySelector = RelaySelectorWrapper(
relayCache: ipOverrideWrapper
)
tunnelManager = createTunnelManager(application: application, relaySelector: relaySelector)
tunnelManager = createTunnelManager(
backgroundTaskProvider: backgroundTaskProvider,
relaySelector: relaySelector
)

settingsObserver = TunnelBlockObserver(didUpdateTunnelSettings: { _, settings in
tunnelSettingsListener.onNewSettings?(settings)
})
tunnelManager.addObserver(settingsObserver)

storePaymentManager = StorePaymentManager(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
queue: .default(),
apiProxy: apiProxy,
accountsProxy: accountsProxy,
Expand Down Expand Up @@ -155,11 +167,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

private func createTunnelManager(
application: UIApplication,
backgroundTaskProvider: BackgroundTaskProviding,
relaySelector: RelaySelectorProtocol
) -> TunnelManager {
return TunnelManager(
application: application,
backgroundTaskProvider: backgroundTaskProvider,
tunnelStore: tunnelStore,
relayCacheTracker: relayCacheTracker,
accountsProxy: accountsProxy,
Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
/// Relay cache.
private let cache: RelayCacheProtocol

private let application: UIApplication
private let backgroundTaskProvider: BackgroundTaskProviding

/// Lock used for synchronization.
private let relayCacheLock = NSLock()
Expand All @@ -57,8 +57,8 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {
/// Memory cache.
private var cachedRelays: CachedRelays?

init(relayCache: RelayCacheProtocol, application: UIApplication, apiProxy: APIQuerying) {
self.application = application
init(relayCache: RelayCacheProtocol, backgroundTaskProvider: BackgroundTaskProviding, apiProxy: APIQuerying) {
self.backgroundTaskProvider = backgroundTaskProvider
self.apiProxy = apiProxy
cache = relayCache

Expand Down Expand Up @@ -180,7 +180,7 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol {

operation.addObserver(
BackgroundObserver(
backgroundTaskProvider: application,
backgroundTaskProvider: backgroundTaskProvider,
name: "Update relays",
cancelUponExpiration: true
)
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadVPN/StorePaymentManager/StorePaymentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
return queue
}()

private let backgroundTaskProvider: BackgroundTaskProvider
private let backgroundTaskProvider: BackgroundTaskProviding
private let paymentQueue: SKPaymentQueue
private let apiProxy: APIQuerying
private let accountsProxy: RESTAccountHandling
Expand All @@ -57,7 +57,7 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
/// - accountsProxy: the object implementing `RESTAccountHandling`.
/// - transactionLog: an instance of transaction log. Typically ``StoreTransactionLog/default``.
init(
backgroundTaskProvider: BackgroundTaskProvider,
backgroundTaskProvider: BackgroundTaskProviding,
queue: SKPaymentQueue,
apiProxy: APIQuerying,
accountsProxy: RESTAccountHandling,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private let defaultTimeout: Duration = .seconds(5)
final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output> {
typealias DecoderHandler = (Data?) throws -> Output

private let backgroundTaskProvider: BackgroundTaskProvider
private let backgroundTaskProvider: BackgroundTaskProviding
private let tunnel: any TunnelProtocol
private let message: TunnelProviderMessage
private let timeout: Duration
Expand All @@ -38,7 +38,7 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>

init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
backgroundTaskProvider: BackgroundTaskProviding,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
Expand Down Expand Up @@ -215,54 +215,6 @@ final class SendTunnelProviderMessageOperation<Output>: ResultOperation<Output>
}
}

extension SendTunnelProviderMessageOperation where Output: Codable {
convenience init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
completionHandler: @escaping CompletionHandler
) {
self.init(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: tunnel,
message: message,
timeout: timeout,
decoderHandler: { data in
if let data {
return try TunnelProviderReply(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
},
completionHandler: completionHandler
)
}
}

extension SendTunnelProviderMessageOperation where Output == Void {
convenience init(
dispatchQueue: DispatchQueue,
backgroundTaskProvider: BackgroundTaskProvider,
tunnel: any TunnelProtocol,
message: TunnelProviderMessage,
timeout: Duration? = nil,
completionHandler: CompletionHandler?
) {
self.init(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: tunnel,
message: message,
timeout: timeout,
decoderHandler: { _ in () },
completionHandler: completionHandler
)
}
}

enum SendTunnelProviderMessageError: LocalizedError, WrappingError {
/// Tunnel process is either down or about to go down.
case tunnelDown(NEVPNStatus)
Expand Down
22 changes: 21 additions & 1 deletion ios/MullvadVPN/TunnelManager/Tunnel+Messaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .reconnectTunnel(nextRelays),
decoderHandler: { _ in () },
completionHandler: completionHandler
)

Expand All @@ -44,16 +45,24 @@ extension TunnelProtocol {
func getTunnelStatus(
completionHandler: @escaping (Result<ObservedState, Error>) -> Void
) -> Cancellable {
let decoderHandler: (Data?) throws -> ObservedState = { data in
if let data {
return try TunnelProviderReply<ObservedState>(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
}

let operation = SendTunnelProviderMessageOperation(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .getTunnelStatus,
decoderHandler: decoderHandler,
completionHandler: completionHandler
)

operationQueue.addOperation(operation)

return operation
}

Expand All @@ -62,12 +71,21 @@ extension TunnelProtocol {
_ proxyRequest: ProxyURLRequest,
completionHandler: @escaping (Result<ProxyURLResponse, Error>) -> Void
) -> Cancellable {
let decoderHandler: (Data?) throws -> ProxyURLResponse = { data in
if let data {
return try TunnelProviderReply<ProxyURLResponse>(messageData: data).value
} else {
throw EmptyTunnelProviderResponseError()
}
}

let operation = SendTunnelProviderMessageOperation(
dispatchQueue: dispatchQueue,
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .sendURLRequest(proxyRequest),
timeout: proxyRequestTimeout,
decoderHandler: decoderHandler,
completionHandler: completionHandler
)

Expand All @@ -79,6 +97,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .cancelURLRequest(proxyRequest.id),
decoderHandler: decoderHandler,
completionHandler: nil
)

Expand All @@ -99,6 +118,7 @@ extension TunnelProtocol {
backgroundTaskProvider: backgroundTaskProvider,
tunnel: self,
message: .privateKeyRotation,
decoderHandler: { _ in () },
completionHandler: completionHandler
)

Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadVPN/TunnelManager/Tunnel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ protocol TunnelProtocol: AnyObject {
var status: NEVPNStatus { get }
var isOnDemandEnabled: Bool { get set }
var startDate: Date? { get }
var backgroundTaskProvider: BackgroundTaskProvider { get }
var backgroundTaskProvider: BackgroundTaskProviding { get }

init(tunnelProvider: TunnelManagerProtocol, backgroundTaskProvider: BackgroundTaskProvider)
init(tunnelProvider: TunnelManagerProtocol, backgroundTaskProvider: BackgroundTaskProviding)

func addObserver(_ observer: any TunnelStatusObserver)
func removeObserver(_ observer: any TunnelStatusObserver)
Expand All @@ -53,7 +53,7 @@ final class Tunnel: TunnelProtocol, Equatable {
/// Unique identifier assigned to instance at the time of creation.
let identifier = UUID()

var backgroundTaskProvider: any BackgroundTaskProvider
var backgroundTaskProvider: BackgroundTaskProviding

#if DEBUG
/// System VPN configuration identifier.
Expand Down Expand Up @@ -117,7 +117,7 @@ final class Tunnel: TunnelProtocol, Equatable {
private var _startDate: Date?
internal let tunnelProvider: TunnelProviderManagerType

init(tunnelProvider: TunnelProviderManagerType, backgroundTaskProvider: BackgroundTaskProvider) {
init(tunnelProvider: TunnelProviderManagerType, backgroundTaskProvider: BackgroundTaskProviding) {
self.tunnelProvider = tunnelProvider
self.backgroundTaskProvider = backgroundTaskProvider

Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/TunnelManager/TunnelInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protocol TunnelInteractor {
// MARK: - Tunnel manipulation

var tunnel: (any TunnelProtocol)? { get }
var backgroundTaskProvider: any BackgroundTaskProvider { get }
var backgroundTaskProvider: BackgroundTaskProviding { get }

func getPersistentTunnels() -> [any TunnelProtocol]
func createNewTunnel() -> any TunnelProtocol
Expand Down
Loading

0 comments on commit 8d3ad1b

Please sign in to comment.