-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathProxyConfigurationTester.swift
45 lines (40 loc) · 1.35 KB
/
ProxyConfigurationTester.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// ProxyConfigurationTester.swift
// MullvadVPN
//
// Created by pronebird on 28/11/2023.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//
import Combine
import Foundation
import MullvadREST
import MullvadSettings
import MullvadTypes
/// A concrete implementation of an access method proxy configuration.
class ProxyConfigurationTester: ProxyConfigurationTesterProtocol {
private var cancellable: (any MullvadTypes.Cancellable)?
private let transportProvider: ProxyConfigurationTransportProvider
private var headRequest: REST.APIAvailabilityTestRequest?
init(transportProvider: ProxyConfigurationTransportProvider) {
self.transportProvider = transportProvider
}
func start(configuration: PersistentProxyConfiguration, completion: @escaping ((any Error)?) -> Void) {
do {
let transport = try transportProvider.makeTransport(with: configuration)
let request = REST.APIAvailabilityTestRequest(transport: transport)
headRequest = request
cancellable = request.makeRequest { error in
DispatchQueue.main.async {
completion(error)
}
}
} catch {
completion(error)
}
}
func cancel() {
cancellable?.cancel()
cancellable = nil
headRequest = nil
}
}