summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/SimulatorTunnelProvider/SimulatorTunnelInfo.swift
blob: 4e3207e840d6a401293583d87f4f4f3349a6ef29 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
//
//  SimulatorTunnelInfo.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2023-09-07.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

#if targetEnvironment(simulator)

    import Foundation
    import NetworkExtension

    final class SimulatorTunnelProviderSession: SimulatorVPNConnection, VPNTunnelProviderSessionProtocol,
        @unchecked Sendable
    {
        func sendProviderMessage(_ messageData: Data, responseHandler: ((Data?) -> Void)?) throws {
            SimulatorTunnelProvider.shared.handleAppMessage(
                messageData,
                completionHandler: responseHandler
            )
        }
    }

    /// A mock struct for tunnel configuration and connection
    struct SimulatorTunnelInfo {
        /// A unique identifier for the configuration
        var identifier = UUID().uuidString

        /// An associated VPN connection.
        /// Intentionally initialized with a `SimulatorTunnelProviderSession` subclass which
        /// implements the necessary protocol
        var connection: SimulatorVPNConnection = SimulatorTunnelProviderSession()

        /// Whether configuration is enabled
        var isEnabled = false

        /// Whether on-demand VPN is enabled
        var isOnDemandEnabled = false

        /// On-demand VPN rules
        var onDemandRules = [NEOnDemandRule]()

        /// Protocol configuration
        var protocolConfiguration: NEVPNProtocol? {
            didSet {
                connection.protocolConfiguration = protocolConfiguration ?? NEVPNProtocol()
            }
        }

        /// Tunnel description
        var localizedDescription: String?

        /// Designated initializer
        init() {}
    }

#endif