Skip to content

Commit

Permalink
Enable compilation with Swift 6 for most targets
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Dec 11, 2024
1 parent 06b9a75 commit a24fed8
Show file tree
Hide file tree
Showing 294 changed files with 1,117 additions and 850 deletions.
2 changes: 1 addition & 1 deletion ios/MullvadLogging/LogFileOutputStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MullvadTypes
/// the first place, or when writing to it.
private let reopenFileLogInterval: Duration = .seconds(5)

class LogFileOutputStream: TextOutputStream {
class LogFileOutputStream: TextOutputStream, @unchecked Sendable {
private let queue = DispatchQueue(label: "LogFileOutputStreamQueue", qos: .utility)

private let baseFileURL: URL
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadLogging/OSLogHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public struct OSLogHandler: LogHandler {
let category: String
}

private static var osLogRegistry: [RegistryKey: OSLog] = [:]
nonisolated(unsafe) private static var osLogRegistry: [RegistryKey: OSLog] = [:]
private static let registryLock = NSLock()

private static func getOSLog(subsystem: String, category: String) -> OSLog {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Combine
import MullvadSettings

public struct AccessMethodRepositoryStub: AccessMethodRepositoryDataSource {
public struct AccessMethodRepositoryStub: AccessMethodRepositoryDataSource, @unchecked Sendable {
public var directAccess: PersistentAccessMethod

public var accessMethodsPublisher: AnyPublisher<[PersistentAccessMethod], Never> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import MullvadREST
import MullvadTypes

struct RESTRequestExecutorStub<Success>: RESTRequestExecutor {
struct RESTRequestExecutorStub<Success: Sendable>: RESTRequestExecutor {
var success: (() -> Success)?

func execute(completionHandler: @escaping (Result<Success, Error>) -> Void) -> Cancellable {
Expand Down
4 changes: 2 additions & 2 deletions ios/MullvadREST/ApiHandlers/APIAvailabilityTestRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import MullvadTypes

extension REST {
public struct APIAvailabilityTestRequest {
public struct APIAvailabilityTestRequest: Sendable {
let transport: RESTTransport

public init(transport: RESTTransport) {
Expand All @@ -21,7 +21,7 @@ extension REST {
///
/// - Parameter completion: Completes with `nil` if the request was successful, and `Error` otherwise.
/// - Returns: A cancellable token to cancel the request inflight.
public func makeRequest(completion: @escaping (Swift.Error?) -> Void) -> Cancellable {
public func makeRequest(completion: @escaping @Sendable (Swift.Error?) -> Void) -> Cancellable {
do {
let factory = RequestFactory(
hostname: defaultAPIHostname,
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadREST/ApiHandlers/AddressCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MullvadLogging
import MullvadTypes

extension REST {
public final class AddressCache {
public final class AddressCache: @unchecked Sendable {
/// Logger.
private let logger = Logger(label: "AddressCache")

Expand Down
32 changes: 16 additions & 16 deletions ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Foundation
import MullvadTypes
import WireGuardKitTypes

public protocol APIQuerying {
public protocol APIQuerying: Sendable {
func getAddressList(
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<[AnyIPEndpoint]>
completionHandler: @escaping @Sendable ProxyCompletionHandler<[AnyIPEndpoint]>
) -> Cancellable

func getRelays(
etag: String?,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<REST.ServerRelaysCacheResponse>
completionHandler: @escaping @Sendable ProxyCompletionHandler<REST.ServerRelaysCacheResponse>
) -> Cancellable

func createApplePayment(
Expand All @@ -30,19 +30,19 @@ public protocol APIQuerying {
func sendProblemReport(
_ body: REST.ProblemReportRequest,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<Void>
completionHandler: @escaping @Sendable ProxyCompletionHandler<Void>
) -> Cancellable

func submitVoucher(
voucherCode: String,
accountNumber: String,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<REST.SubmitVoucherResponse>
completionHandler: @escaping @Sendable ProxyCompletionHandler<REST.SubmitVoucherResponse>
) -> Cancellable
}

extension REST {
public final class APIProxy: Proxy<AuthProxyConfiguration>, APIQuerying {
public final class APIProxy: Proxy<AuthProxyConfiguration>, APIQuerying, @unchecked Sendable {
public init(configuration: AuthProxyConfiguration) {
super.init(
name: "APIProxy",
Expand All @@ -57,7 +57,7 @@ extension REST {

public func getAddressList(
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<[AnyIPEndpoint]>
completionHandler: @escaping @Sendable ProxyCompletionHandler<[AnyIPEndpoint]>
) -> Cancellable {
let requestHandler = AnyRequestHandler { endpoint in
try self.requestFactory.createRequest(
Expand All @@ -84,7 +84,7 @@ extension REST {
public func getRelays(
etag: String?,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<ServerRelaysCacheResponse>
completionHandler: @escaping @Sendable ProxyCompletionHandler<ServerRelaysCacheResponse>
) -> Cancellable {
let requestHandler = AnyRequestHandler { endpoint in
var requestBuilder = try self.requestFactory.createRequestBuilder(
Expand Down Expand Up @@ -240,7 +240,7 @@ extension REST {
voucherCode: String,
accountNumber: String,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<SubmitVoucherResponse>
completionHandler: @escaping @Sendable ProxyCompletionHandler<SubmitVoucherResponse>
) -> Cancellable {
let requestHandler = AnyRequestHandler(
createURLRequest: { endpoint, authorization in
Expand Down Expand Up @@ -283,16 +283,16 @@ extension REST {

// MARK: - Response types

public enum ServerRelaysCacheResponse {
public enum ServerRelaysCacheResponse: Sendable {
case notModified
case newContent(_ etag: String?, _ rawData: Data)
}

private struct CreateApplePaymentRequest: Encodable {
private struct CreateApplePaymentRequest: Encodable, Sendable {
let receiptString: Data
}

public enum CreateApplePaymentResponse {
public enum CreateApplePaymentResponse: Sendable {
case noTimeAdded(_ expiry: Date)
case timeAdded(_ timeAdded: Int, _ newExpiry: Date)

Expand Down Expand Up @@ -322,12 +322,12 @@ extension REST {
}
}

private struct CreateApplePaymentRawResponse: Decodable {
private struct CreateApplePaymentRawResponse: Decodable, Sendable {
let timeAdded: Int
let newExpiry: Date
}

public struct ProblemReportRequest: Encodable {
public struct ProblemReportRequest: Encodable, Sendable {
public let address: String
public let message: String
public let log: String
Expand All @@ -341,11 +341,11 @@ extension REST {
}
}

private struct SubmitVoucherRequest: Encodable {
private struct SubmitVoucherRequest: Encodable, Sendable {
let voucherCode: String
}

public struct SubmitVoucherResponse: Decodable {
public struct SubmitVoucherResponse: Decodable, Sendable {
public let timeAdded: Int
public let newExpiry: Date

Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadREST/ApiHandlers/RESTAccessTokenManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import MullvadLogging
import MullvadTypes
import Operations

public protocol RESTAccessTokenManagement {
public protocol RESTAccessTokenManagement: Sendable {
func getAccessToken(
accountNumber: String,
completionHandler: @escaping ProxyCompletionHandler<REST.AccessTokenData>
completionHandler: @escaping @Sendable ProxyCompletionHandler<REST.AccessTokenData>
) -> Cancellable

func invalidateAllTokens()
}

extension REST {
public final class AccessTokenManager: RESTAccessTokenManagement {
public final class AccessTokenManager: RESTAccessTokenManagement, @unchecked Sendable {
private let logger = Logger(label: "REST.AccessTokenManager")
private let operationQueue = AsyncOperationQueue.makeSerial()
private let dispatchQueue = DispatchQueue(label: "REST.AccessTokenManager.dispatchQueue")
Expand All @@ -34,7 +34,7 @@ extension REST {

public func getAccessToken(
accountNumber: String,
completionHandler: @escaping ProxyCompletionHandler<REST.AccessTokenData>
completionHandler: @escaping @Sendable ProxyCompletionHandler<REST.AccessTokenData>
) -> Cancellable {
let operation =
ResultBlockOperation<REST.AccessTokenData>(dispatchQueue: dispatchQueue) { finish -> Cancellable in
Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadREST/ApiHandlers/RESTAccountsProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import Foundation
import MullvadTypes

public protocol RESTAccountHandling {
public protocol RESTAccountHandling: Sendable {
func createAccount(
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<REST.NewAccountData>
completion: @escaping @Sendable ProxyCompletionHandler<REST.NewAccountData>
) -> Cancellable

func getAccountData(accountNumber: String) -> any RESTRequestExecutor<Account>
Expand All @@ -25,7 +25,7 @@ public protocol RESTAccountHandling {
}

extension REST {
public final class AccountsProxy: Proxy<AuthProxyConfiguration>, RESTAccountHandling {
public final class AccountsProxy: Proxy<AuthProxyConfiguration>, RESTAccountHandling, @unchecked Sendable {
public init(configuration: AuthProxyConfiguration) {
super.init(
name: "AccountsProxy",
Expand Down Expand Up @@ -135,7 +135,7 @@ extension REST {
}
}

public struct NewAccountData: Decodable {
public struct NewAccountData: Decodable, Sendable {
public let id: String
public let expiry: Date
public let maxPorts: Int
Expand Down
6 changes: 3 additions & 3 deletions ios/MullvadREST/ApiHandlers/RESTAuthenticationProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import MullvadTypes

extension REST {
public final class AuthenticationProxy: Proxy<ProxyConfiguration> {
public final class AuthenticationProxy: Proxy<ProxyConfiguration>, @unchecked Sendable {
public init(configuration: ProxyConfiguration) {
super.init(
name: "AuthenticationProxy",
Expand Down Expand Up @@ -57,12 +57,12 @@ extension REST {
}
}

public struct AccessTokenData: Decodable {
public struct AccessTokenData: Decodable, Sendable {
let accessToken: String
let expiry: Date
}

private struct AccessTokenRequest: Encodable {
private struct AccessTokenRequest: Encodable, Sendable {
let accountNumber: String
}
}
4 changes: 2 additions & 2 deletions ios/MullvadREST/ApiHandlers/RESTAuthorization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import MullvadTypes
import Operations

protocol RESTAuthorizationProvider {
func getAuthorization(completion: @escaping (Result<REST.Authorization, Swift.Error>) -> Void)
func getAuthorization(completion: @escaping @Sendable (Result<REST.Authorization, Swift.Error>) -> Void)
-> Cancellable
}

Expand All @@ -28,7 +28,7 @@ extension REST {
}

func getAuthorization(
completion: @escaping (Result<REST.Authorization, Swift.Error>)
completion: @escaping @Sendable (Result<REST.Authorization, Swift.Error>)
-> Void
) -> Cancellable {
accessTokenManager.getAccessToken(accountNumber: accountNumber) { result in
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadREST/ApiHandlers/RESTDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import MullvadTypes
extension REST {
/// The API hostname and endpoint are defined in the Info.plist of the MullvadREST framework bundle
/// This is due to not being able to target `Bundle.main` from a Unit Test environment as it gets its own bundle that would not contain the above variables.
private static let infoDictionary = Bundle(for: AddressCache.self).infoDictionary!
nonisolated(unsafe) private static let infoDictionary = Bundle(for: AddressCache.self).infoDictionary!

/// Default API hostname.
public static let defaultAPIHostname = infoDictionary["ApiHostName"] as! String
Expand Down
24 changes: 12 additions & 12 deletions ios/MullvadREST/ApiHandlers/RESTDevicesProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@

import Foundation
import MullvadTypes
import WireGuardKitTypes
@preconcurrency import WireGuardKitTypes

public protocol DeviceHandling {
public protocol DeviceHandling: Sendable {
func getDevice(
accountNumber: String,
identifier: String,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Device>
completion: @escaping @Sendable ProxyCompletionHandler<Device>
) -> Cancellable

func getDevices(
accountNumber: String,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<[Device]>
completion: @escaping @Sendable ProxyCompletionHandler<[Device]>
) -> Cancellable

func createDevice(
accountNumber: String,
request: REST.CreateDeviceRequest,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Device>
completion: @escaping @Sendable ProxyCompletionHandler<Device>
) -> Cancellable

func deleteDevice(
accountNumber: String,
identifier: String,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Bool>
completion: @escaping @Sendable ProxyCompletionHandler<Bool>
) -> Cancellable

func rotateDeviceKey(
accountNumber: String,
identifier: String,
publicKey: PublicKey,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Device>
completion: @escaping @Sendable ProxyCompletionHandler<Device>
) -> Cancellable
}

extension REST {
public final class DevicesProxy: Proxy<AuthProxyConfiguration>, DeviceHandling {
public final class DevicesProxy: Proxy<AuthProxyConfiguration>, DeviceHandling, @unchecked Sendable {
public init(configuration: AuthProxyConfiguration) {
super.init(
name: "DevicesProxy",
Expand Down Expand Up @@ -161,7 +161,7 @@ extension REST {
accountNumber: String,
request: CreateDeviceRequest,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Device>
completion: @escaping @Sendable ProxyCompletionHandler<Device>
) -> Cancellable {
let requestHandler = AnyRequestHandler(
createURLRequest: { endpoint, authorization in
Expand Down Expand Up @@ -262,7 +262,7 @@ extension REST {
identifier: String,
publicKey: PublicKey,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Device>
completion: @escaping @Sendable ProxyCompletionHandler<Device>
) -> Cancellable {
let requestHandler = AnyRequestHandler(
createURLRequest: { endpoint, authorization in
Expand Down Expand Up @@ -310,7 +310,7 @@ extension REST {
}
}

public struct CreateDeviceRequest: Encodable {
public struct CreateDeviceRequest: Encodable, Sendable {
let publicKey: PublicKey
let hijackDNS: Bool

Expand All @@ -332,7 +332,7 @@ extension REST {
}
}

private struct RotateDeviceKeyRequest: Encodable {
private struct RotateDeviceKeyRequest: Encodable, Sendable {
let publicKey: PublicKey

private enum CodingKeys: String, CodingKey {
Expand Down
Loading

0 comments on commit a24fed8

Please sign in to comment.