diff options
| author | Bug Magnet <marco.nikic@mullvad.net> | 2025-06-04 11:39:14 +0200 |
|---|---|---|
| committer | Bug Magnet <marco.nikic@mullvad.net> | 2025-06-04 11:39:14 +0200 |
| commit | 1e42ad237f5fbb68027f0c3aefcf3b35c5b87500 (patch) | |
| tree | cc871d6c0e360d910ebda7c6f05b1d71ad5d1216 /ios/MullvadRustRuntime | |
| parent | 64862490c2781e4be3b8e77d5c297198fcb63d54 (diff) | |
| parent | e3ccff9b8313e5a13ce526c5b9cb531bd82f623c (diff) | |
| download | mullvadvpn-1e42ad237f5fbb68027f0c3aefcf3b35c5b87500.tar.xz mullvadvpn-1e42ad237f5fbb68027f0c3aefcf3b35c5b87500.zip | |
Merge branch 'move-api-access-method-test-call-to-mullvad-api-ios-1195'
Diffstat (limited to 'ios/MullvadRustRuntime')
| -rw-r--r-- | ios/MullvadRustRuntime/MullvadConnectionModeProvider.swift | 123 | ||||
| -rw-r--r-- | ios/MullvadRustRuntime/include/mullvad_rust_runtime.h | 26 |
2 files changed, 88 insertions, 61 deletions
diff --git a/ios/MullvadRustRuntime/MullvadConnectionModeProvider.swift b/ios/MullvadRustRuntime/MullvadConnectionModeProvider.swift index f7d2e0238f..0504fb06c8 100644 --- a/ios/MullvadRustRuntime/MullvadConnectionModeProvider.swift +++ b/ios/MullvadRustRuntime/MullvadConnectionModeProvider.swift @@ -8,7 +8,6 @@ import MullvadTypes -// swiftlint:disable:next function_body_length public func initAccessMethodSettingsWrapper(methods: [PersistentAccessMethod]) -> SwiftAccessMethodSettingsWrapper { // 1. Get all the built in access methods, it is expected that they are always available @@ -21,67 +20,15 @@ public func initAccessMethodSettingsWrapper(methods: [PersistentAccessMethod]) let customMethods = methods.filter { defaultMethods.contains($0.proxyConfiguration) == false } // 3. Convert the builtin access methods - let directMethodRaw = convert_builtin_access_method_setting( - directMethod.id.uuidString, - directMethod.name, - directMethod.isEnabled, - UInt8(KindDirect.rawValue), - nil - ) - let bridgesMethodRaw = convert_builtin_access_method_setting( - bridgesMethod.id.uuidString, - bridgesMethod.name, - bridgesMethod.isEnabled, - UInt8(KindBridge.rawValue), - nil - ) - let encryptedDNSMethodRaw = convert_builtin_access_method_setting( - encryptedDNSMethod.id.uuidString, - encryptedDNSMethod.name, - encryptedDNSMethod.isEnabled, - UInt8(KindEncryptedDnsProxy.rawValue), - nil - ) + let directMethodRaw = convertAccessMethod(accessMethod: directMethod) + let bridgesMethodRaw = convertAccessMethod(accessMethod: bridgesMethod) + let encryptedDNSMethodRaw = convertAccessMethod(accessMethod: encryptedDNSMethod) var rawCustomMethods = ContiguousArray<UnsafeRawPointer?>([]) // 4. Convert the custom access methods (all takes different parameters) for method in customMethods { - if case let .shadowsocks(config) = method.proxyConfiguration { - let serverAddress = config.server.rawValue.map { $0 } - let shadowsocksConfiguration = new_shadowsocks_access_method_setting( - serverAddress, - UInt(serverAddress.count), - config.port, - config.password, - config.cipher.rawValue.rawValue - ) - let shadowsocksMethodRaw = convert_builtin_access_method_setting( - method.id.uuidString, - method.name, - method.isEnabled, - UInt8(KindShadowsocks.rawValue), - shadowsocksConfiguration - ) - rawCustomMethods.append(shadowsocksMethodRaw) - } - if case let .socks5(config) = method.proxyConfiguration { - let serverAddress = config.server.rawValue.map { $0 } - let socks5Configuration = new_socks5_access_method_setting( - serverAddress, - UInt(serverAddress.count), - config.port, - config.credential?.username, - config.credential?.password - ) - let socks5MethodRaw = convert_builtin_access_method_setting( - method.id.uuidString, - method.name, - method.isEnabled, - UInt8(KindSocks5Local.rawValue), - socks5Configuration - ) - rawCustomMethods.append(socks5MethodRaw) - } + let rawMethod = convertAccessMethod(accessMethod: method) + rawCustomMethods.append(rawMethod) } // 5. Reunite them all in one, and pass it to rust @@ -97,3 +44,63 @@ public func initAccessMethodSettingsWrapper(methods: [PersistentAccessMethod]) } ) } + +public func convertAccessMethod(accessMethod: PersistentAccessMethod) -> UnsafeMutableRawPointer? { + switch accessMethod.proxyConfiguration { + case .direct, .bridges, .encryptedDNS: + return convert_builtin_access_method_setting( + accessMethod.id.uuidString, + accessMethod.name, + accessMethod.isEnabled, + accessMethod.kind(), + nil + ) + case let .shadowsocks(configuration): + let serverAddress = configuration.server.rawValue.map { $0 } + let shadowsocksConfiguration = new_shadowsocks_access_method_setting( + serverAddress, + UInt(serverAddress.count), + configuration.port, + configuration.password, + configuration.cipher.rawValue.rawValue + ) + let shadowsocksMethodRaw = convert_builtin_access_method_setting( + accessMethod.id.uuidString, + accessMethod.name, + accessMethod.isEnabled, + accessMethod.kind(), + shadowsocksConfiguration + ) + return shadowsocksMethodRaw + case let .socks5(configuration): + let serverAddress = configuration.server.rawValue.map { $0 } + let socks5Configuration = new_socks5_access_method_setting( + serverAddress, + UInt(serverAddress.count), + configuration.port, + configuration.credential?.username, + configuration.credential?.password + ) + let socks5MethodRaw = convert_builtin_access_method_setting( + accessMethod.id.uuidString, + accessMethod.name, + accessMethod.isEnabled, + accessMethod.kind(), + socks5Configuration + ) + return socks5MethodRaw + } +} + +fileprivate +extension PersistentAccessMethod { + func kind() -> UInt8 { + switch kind { + case .direct: UInt8(KindDirect.rawValue) + case .bridges: UInt8(KindBridge.rawValue) + case .encryptedDNS: UInt8(KindEncryptedDnsProxy.rawValue) + case .shadowsocks: UInt8(KindShadowsocks.rawValue) + case .socks5: UInt8(KindSocks5Local.rawValue) + } + } +} diff --git a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h index 08bb177116..d4c0bf334f 100644 --- a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h +++ b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h @@ -89,10 +89,10 @@ typedef struct LateStringDeallocator { typedef struct SwiftMullvadApiResponse { uint8_t *body; uintptr_t body_size; - uint8_t *etag; + char *etag; uint16_t status_code; - uint8_t *error_description; - uint8_t *server_response_code; + char *error_description; + char *server_response_code; bool success; } SwiftMullvadApiResponse; @@ -366,6 +366,26 @@ struct SwiftCancelHandle mullvad_ios_get_addresses(struct SwiftApiContext api_co * object `MullvadApiCompletion`. The pointer will be freed by calling `mullvad_api_completion_finish` * when completion finishes (in completion.finish). * + * `retry_strategy` must have been created by a call to either of the following functions + * `mullvad_api_retry_strategy_never`, `mullvad_api_retry_strategy_constant` or `mullvad_api_retry_strategy_exponential` + * + * This function is not safe to call multiple times with the same `CompletionCookie`. + */ +struct SwiftCancelHandle mullvad_ios_api_addrs_available(struct SwiftApiContext api_context, + void *completion_cookie, + struct SwiftRetryStrategy retry_strategy, + const void *access_method_setting); + +/** + * # Safety + * + * `api_context` must be pointing to a valid instance of `SwiftApiContext`. A `SwiftApiContext` is created + * by calling `mullvad_api_init_new`. + * + * This function takes ownership of `completion_cookie`, which must be pointing to a valid instance of Swift + * object `MullvadApiCompletion`. The pointer will be freed by calling `mullvad_api_completion_finish` + * when completion finishes (in completion.finish). + * * `etag` must be a pointer to a null terminated string. * * `retry_strategy` must have been created by a call to either of the following functions |
