diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-09-17 12:45:16 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-09-21 10:43:58 +0200 |
| commit | a08f6044aa99aab2b4b3fcc14ae35f872feda999 (patch) | |
| tree | d7b5a9b96d7885986b3e8ea7e4ece7c20697ffd9 | |
| parent | 2f7805037f2f9cef5d39e3b13f1dd84585a18561 (diff) | |
| download | mullvadvpn-a08f6044aa99aab2b4b3fcc14ae35f872feda999.tar.xz mullvadvpn-a08f6044aa99aab2b4b3fcc14ae35f872feda999.zip | |
TunnelManager: add PacketTunnelOptions
| -rw-r--r-- | ios/MullvadVPN.xcodeproj/project.pbxproj | 13 | ||||
| -rw-r--r-- | ios/MullvadVPN/TunnelManager/PacketTunnelOptions.swift | 62 |
2 files changed, 75 insertions, 0 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index d42b3f17ec..f8e3a2e0f2 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -142,6 +142,8 @@ 587B753D2666468F00DEF7E9 /* NotificationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B753C2666468F00DEF7E9 /* NotificationController.swift */; }; 587B753F2668E5A700DEF7E9 /* NotificationContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B753E2668E5A700DEF7E9 /* NotificationContainerView.swift */; }; 587B75412668FD7800DEF7E9 /* AccountExpiryNotificationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587B75402668FD7700DEF7E9 /* AccountExpiryNotificationProvider.swift */; }; + 587C575326D2615F005EF767 /* PacketTunnelOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587C575226D2615F005EF767 /* PacketTunnelOptions.swift */; }; + 587C575426D2615F005EF767 /* PacketTunnelOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587C575226D2615F005EF767 /* PacketTunnelOptions.swift */; }; 587CBFE322807F530028DED3 /* UIColor+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587CBFE222807F530028DED3 /* UIColor+Helpers.swift */; }; 5883A09E266A5AF7003EFFCB /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 587B7543266922BF00DEF7E9 /* Localizable.strings */; }; 588534BF246193D90018B744 /* AutomaticKeyRotationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 588534BD246193C00018B744 /* AutomaticKeyRotationManager.swift */; }; @@ -432,6 +434,7 @@ 587B753E2668E5A700DEF7E9 /* NotificationContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationContainerView.swift; sourceTree = "<group>"; }; 587B75402668FD7700DEF7E9 /* AccountExpiryNotificationProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountExpiryNotificationProvider.swift; sourceTree = "<group>"; }; 587B7544266922BF00DEF7E9 /* en */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; }; + 587C575226D2615F005EF767 /* PacketTunnelOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PacketTunnelOptions.swift; sourceTree = "<group>"; }; 587CBFE222807F530028DED3 /* UIColor+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helpers.swift"; sourceTree = "<group>"; }; 588534BD246193C00018B744 /* AutomaticKeyRotationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomaticKeyRotationManager.swift; sourceTree = "<group>"; }; 5888AD82227B11080051EB06 /* SelectLocationCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectLocationCell.swift; sourceTree = "<group>"; }; @@ -614,6 +617,14 @@ path = Logging; sourceTree = "<group>"; }; + 5823FA5726CE4A4100283BF8 /* TunnelManager */ = { + isa = PBXGroup; + children = ( + 587C575226D2615F005EF767 /* PacketTunnelOptions.swift */, + ); + path = TunnelManager; + sourceTree = "<group>"; + }; 582CFEE1269448160072883A /* Localizations */ = { isa = PBXGroup; children = ( @@ -1238,6 +1249,7 @@ 5820675B26E6576800655B05 /* RelayCache.swift in Sources */, 585DA87D26B0254000B8C587 /* RelayCacheIO.swift in Sources */, 58BA693123EADA6A009DC256 /* SimulatorTunnelProvider.swift in Sources */, + 587C575326D2615F005EF767 /* PacketTunnelOptions.swift in Sources */, 58E1336D26D2BE7500CC316B /* AnyResult.swift in Sources */, 587B753B2666467500DEF7E9 /* NotificationBannerView.swift in Sources */, 58B993B12608A34500BA7811 /* LoginContentView.swift in Sources */, @@ -1389,6 +1401,7 @@ 58FAEE0224533ABB00CB0F5B /* KeychainMatchLimit.swift in Sources */, 58FB865F26EA2E6D00F188BC /* LogFormatting.swift in Sources */, 585DA89726B0328000B8C587 /* TunnelIPCResponse.swift in Sources */, + 587C575426D2615F005EF767 /* PacketTunnelOptions.swift in Sources */, 58FAEE0324533ABE00CB0F5B /* KeychainReturn.swift in Sources */, 58BFA5CD22A7CE1F00A6173D /* ApplicationConfiguration.swift in Sources */, 5850368D25A49E2200A43E93 /* PrivateKeyWithMetadata.swift in Sources */, diff --git a/ios/MullvadVPN/TunnelManager/PacketTunnelOptions.swift b/ios/MullvadVPN/TunnelManager/PacketTunnelOptions.swift new file mode 100644 index 0000000000..ca8b0ecb50 --- /dev/null +++ b/ios/MullvadVPN/TunnelManager/PacketTunnelOptions.swift @@ -0,0 +1,62 @@ +// +// PacketTunnelOptions.swift +// PacketTunnelOptions +// +// Created by pronebird on 22/08/2021. +// Copyright © 2021 Mullvad VPN AB. All rights reserved. +// + +import Foundation + +struct PacketTunnelOptions { + + /// Keys for options dictionary + private enum Keys: String { + /// Option key that holds the `NSData` value with `RelaySelectorResult` encoded using `JSONEncoder`. + /// Used for passing the pre-selected relay in the GUI proocess to the Packet tunnel process. + case relaySelectorResult = "relay-selector-result" + + /// Option key that holds the `NSNumber` value, which is when set to `1` indicates that the tunnel was started by + /// the system. + /// System automatically provides that flag to the tunnel. + case isOnDemand = "is-on-demand" + } + + private var _rawOptions: [String: NSObject] + + func rawOptions() -> [String: NSObject] { + return _rawOptions + } + + init() { + _rawOptions = [:] + } + + init(rawOptions: [String: NSObject]) { + _rawOptions = rawOptions + } + + func getSelectorResult() throws -> RelaySelectorResult? { + guard let data = _rawOptions[Keys.relaySelectorResult.rawValue] as? Data else { return nil } + + return try Self.decode(RelaySelectorResult.self, data) + } + + mutating func setSelectorResult(_ value: RelaySelectorResult) throws { + _rawOptions[Keys.relaySelectorResult.rawValue] = try Self.encode(value) as NSData + } + + func isOnDemand() -> Bool { + return _rawOptions[Keys.isOnDemand.rawValue] as? Int == .some(1) + } + + /// Encode custom parameter value + private static func encode<T: Codable>(_ value: T) throws -> Data { + return try JSONEncoder().encode(value) + } + + /// Decode custom parameter value + private static func decode<T: Codable>(_ type: T.Type, _ data: Data) throws -> T { + return try JSONDecoder().decode(T.self, from: data) + } +} |
