summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2023-11-02 10:47:15 +0100
committerJon Petersson <jon.petersson@kvadrat.se>2023-12-13 15:42:20 +0100
commit8188c51e1b0a5705db7e94053c6d8d45faf615fe (patch)
tree79b38d2b0ff8d8d2fd5b7ab06adde476c3c523e5 /ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
parentc1e2a227931e8e6011353ff9fce56fe733e4ac63 (diff)
downloadmullvadvpn-8188c51e1b0a5705db7e94053c6d8d45faf615fe.tar.xz
mullvadvpn-8188c51e1b0a5705db7e94053c6d8d45faf615fe.zip
Add API access methods UI/part of backend
Diffstat (limited to 'ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift')
-rw-r--r--ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift124
1 files changed, 124 insertions, 0 deletions
diff --git a/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift b/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
new file mode 100644
index 0000000000..b5d5ef2947
--- /dev/null
+++ b/ios/MullvadVPN/AccessMethodRepository/PersistentAccessMethod.swift
@@ -0,0 +1,124 @@
+//
+// PersistentAccessMethod.swift
+// MullvadVPN
+//
+// Created by pronebird on 15/11/2023.
+// Copyright © 2023 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import MullvadTypes
+import Network
+
+/// Persistent access method model.
+struct PersistentAccessMethod: Identifiable, Codable {
+ /// The unique identifier used for referencing the access method entry in a persistent store.
+ var id: UUID
+
+ /// The user-defined name for access method.
+ var name: String
+
+ /// The flag indicating whether configuration is enabled.
+ var isEnabled: Bool
+
+ /// Proxy configuration.
+ var proxyConfiguration: PersistentProxyConfiguration
+}
+
+/// Persistent proxy configuration.
+enum PersistentProxyConfiguration: Codable {
+ /// Direct communication without proxy.
+ case direct
+
+ /// Communication over bridges.
+ case bridges
+
+ /// Communication over shadowsocks.
+ case shadowsocks(ShadowsocksConfiguration)
+
+ /// Communication over socks5 proxy.
+ case socks5(SocksConfiguration)
+}
+
+extension PersistentProxyConfiguration {
+ /// Socks autentication method.
+ enum SocksAuthentication: Codable {
+ case noAuthentication
+ case usernamePassword(username: String, password: String)
+ }
+
+ /// Socks v5 proxy configuration.
+ struct SocksConfiguration: Codable {
+ /// Proxy server address.
+ var server: AnyIPAddress
+
+ /// Proxy server port.
+ var port: UInt16
+
+ /// Authentication method.
+ var authentication: SocksAuthentication
+ }
+
+ /// Shadowsocks configuration.
+ struct ShadowsocksConfiguration: Codable {
+ /// Server address.
+ var server: AnyIPAddress
+
+ /// Server port.
+ var port: UInt16
+
+ /// Server password.
+ var password: String
+
+ /// Server cipher.
+ var cipher: ShadowsocksCipher
+ }
+}
+
+extension PersistentAccessMethod {
+ /// A kind of access method.
+ var kind: AccessMethodKind {
+ switch proxyConfiguration {
+ case .direct:
+ .direct
+ case .bridges:
+ .bridges
+ case .shadowsocks:
+ .shadowsocks
+ case .socks5:
+ .socks5
+ }
+ }
+}
+
+/// A kind of API access method.
+enum AccessMethodKind: Equatable, Hashable, CaseIterable {
+ /// Direct communication.
+ case direct
+
+ /// Communication over bridges.
+ case bridges
+
+ /// Communication over shadowsocks.
+ case shadowsocks
+
+ /// Communication over socks v5 proxy.
+ case socks5
+}
+
+extension AccessMethodKind {
+ /// Returns `true` if the method is permanent and cannot be deleted.
+ var isPermanent: Bool {
+ switch self {
+ case .direct, .bridges:
+ true
+ case .shadowsocks, .socks5:
+ false
+ }
+ }
+
+ /// Returns all access method kinds that can be added by user.
+ static var allUserDefinedKinds: [AccessMethodKind] {
+ allCases.filter { !$0.isPermanent }
+ }
+}