From 9057933661879d093aa542dcea2b6e0d1026f041 Mon Sep 17 00:00:00 2001 From: mojganii Date: Fri, 8 Dec 2023 14:00:52 +0100 Subject: [PATCH] Categorize files based on functionalities --- Cargo.toml | 2 +- .../{ => ApiHandlers}/AddressCache.swift | 0 ios/MullvadREST/{ => ApiHandlers}/HTTP.swift | 0 .../{ => ApiHandlers}/RESTAPIProxy.swift | 0 .../RESTAccessTokenManager.swift | 0 .../{ => ApiHandlers}/RESTAccountsProxy.swift | 0 .../RESTAuthenticationProxy.swift | 0 .../{ => ApiHandlers}/RESTAuthorization.swift | 0 .../{ => ApiHandlers}/RESTCoding.swift | 0 .../{ => ApiHandlers}/RESTDefaults.swift | 0 .../{ => ApiHandlers}/RESTDevicesProxy.swift | 0 .../{ => ApiHandlers}/RESTError.swift | 0 .../RESTNetworkOperation.swift | 0 .../{ => ApiHandlers}/RESTProxy.swift | 0 .../{ => ApiHandlers}/RESTProxyFactory.swift | 0 .../RESTRequestExecutor.swift | 0 .../RESTRequestFactory.swift | 0 .../RESTRequestHandler.swift | 0 .../RESTResponseHandler.swift | 0 .../RESTTaskIdentifier.swift | 0 .../{ => ApiHandlers}/RESTURLSession.swift | 0 .../SSLPinningURLSessionDelegate.swift | 0 .../ServerRelaysResponse.swift | 0 .../{ => Relay}/CachedRelays.swift | 0 ios/MullvadREST/{ => Relay}/Haversine.swift | 0 ios/MullvadREST/{ => Relay}/Midpoint.swift | 0 ios/MullvadREST/{ => Relay}/RelayCache.swift | 0 .../{ => Relay}/RelaySelector.swift | 0 .../ExponentialBackoff.swift | 19 -- ios/MullvadREST/RetryStrategy/Jittered.swift | 29 ++++ .../RetryStrategy.swift} | 2 +- .../Direct/URLSessionTransport.swift | 33 ++++ .../{ => Transport}/RESTTransport.swift | 0 .../RESTTransportProvider.swift | 0 .../Shadowsocks}/ShadowSocksProxy.swift | 0 .../ShadowsocksConfiguration.swift | 0 .../ShadowsocksConfigurationCache.swift | 2 +- .../Shadowsocks/ShadowsocksTransport.swift} | 13 +- .../Shadowsocks}/module.private.modulemap | 0 .../Shadowsocks}/shadowsocks-proxy/.gitignore | 0 .../Shadowsocks}/shadowsocks-proxy/Cargo.toml | 0 .../Shadowsocks}/shadowsocks-proxy/build.rs | 0 .../shadowsocks-proxy/include/shadowsocks.h | 0 .../shadowsocks-proxy/src/bin/run.rs | 0 .../shadowsocks-proxy/src/bin/run_unsafe.rs | 0 .../Shadowsocks}/shadowsocks-proxy/src/ffi.rs | 0 .../Shadowsocks}/shadowsocks-proxy/src/lib.rs | 0 .../Transport/Shadowsocks/shadowsocks.h | 36 ++++ .../{ => Transport}/TransportProvider.swift | 9 +- .../TransportStrategy.swift} | 2 +- ios/MullvadREST/URLSessionTransport.swift | 89 ---------- ios/MullvadVPN.xcodeproj/project.pbxproj | 162 ++++++++++++------ ios/MullvadVPN/AppDelegate.swift | 2 +- .../Coordinators/RelayFilterCoordinator.swift | 2 +- .../SelectLocationCoordinator.swift | 2 +- .../TunnelManager/StartTunnelOperation.swift | 2 +- .../Preferences/PreferencesInteractor.swift | 2 +- .../RelayFilterViewController.swift | 2 +- .../SelectLocationViewController.swift | 2 +- .../RelayCacheTracker+Stubs.swift | 2 +- .../PacketTunnelProvider.swift | 2 +- .../RelaySelectorWrapper.swift | 2 +- .../PacketTunnelActorTests.swift | 2 +- 63 files changed, 229 insertions(+), 191 deletions(-) rename ios/MullvadREST/{ => ApiHandlers}/AddressCache.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/HTTP.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTAPIProxy.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTAccessTokenManager.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTAccountsProxy.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTAuthenticationProxy.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTAuthorization.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTCoding.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTDefaults.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTDevicesProxy.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTError.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTNetworkOperation.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTProxy.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTProxyFactory.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTRequestExecutor.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTRequestFactory.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTRequestHandler.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTResponseHandler.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTTaskIdentifier.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/RESTURLSession.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/SSLPinningURLSessionDelegate.swift (100%) rename ios/MullvadREST/{ => ApiHandlers}/ServerRelaysResponse.swift (100%) rename ios/MullvadREST/{ => Relay}/CachedRelays.swift (100%) rename ios/MullvadREST/{ => Relay}/Haversine.swift (100%) rename ios/MullvadREST/{ => Relay}/Midpoint.swift (100%) rename ios/MullvadREST/{ => Relay}/RelayCache.swift (100%) rename ios/MullvadREST/{ => Relay}/RelaySelector.swift (100%) rename ios/MullvadREST/{ => RetryStrategy}/ExponentialBackoff.swift (56%) create mode 100644 ios/MullvadREST/RetryStrategy/Jittered.swift rename ios/MullvadREST/{RESTRetryStrategy.swift => RetryStrategy/RetryStrategy.swift} (98%) create mode 100644 ios/MullvadREST/Transport/Direct/URLSessionTransport.swift rename ios/MullvadREST/{ => Transport}/RESTTransport.swift (100%) rename ios/MullvadREST/{ => Transport}/RESTTransportProvider.swift (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/ShadowSocksProxy.swift (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/ShadowsocksConfiguration.swift (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/ShadowsocksConfigurationCache.swift (92%) rename ios/MullvadREST/{URLSessionShadowsocksTransport.swift => Transport/Shadowsocks/ShadowsocksTransport.swift} (82%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/module.private.modulemap (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/.gitignore (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/Cargo.toml (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/build.rs (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/include/shadowsocks.h (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/src/bin/run.rs (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/src/bin/run_unsafe.rs (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/src/ffi.rs (100%) rename ios/MullvadREST/{ => Transport/Shadowsocks}/shadowsocks-proxy/src/lib.rs (100%) create mode 100644 ios/MullvadREST/Transport/Shadowsocks/shadowsocks.h rename ios/MullvadREST/{ => Transport}/TransportProvider.swift (96%) rename ios/MullvadREST/{RESTTransportStrategy.swift => Transport/TransportStrategy.swift} (98%) delete mode 100644 ios/MullvadREST/URLSessionTransport.swift diff --git a/Cargo.toml b/Cargo.toml index 805e3f0c723d..00a797d3c264 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ publish = false resolver = "2" members = [ "android/translations-converter", - "ios/MullvadREST/shadowsocks-proxy", + "ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy", "ios/TunnelObfuscation/tunnel-obfuscator-proxy", "mullvad-daemon", "mullvad-cli", diff --git a/ios/MullvadREST/AddressCache.swift b/ios/MullvadREST/ApiHandlers/AddressCache.swift similarity index 100% rename from ios/MullvadREST/AddressCache.swift rename to ios/MullvadREST/ApiHandlers/AddressCache.swift diff --git a/ios/MullvadREST/HTTP.swift b/ios/MullvadREST/ApiHandlers/HTTP.swift similarity index 100% rename from ios/MullvadREST/HTTP.swift rename to ios/MullvadREST/ApiHandlers/HTTP.swift diff --git a/ios/MullvadREST/RESTAPIProxy.swift b/ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift similarity index 100% rename from ios/MullvadREST/RESTAPIProxy.swift rename to ios/MullvadREST/ApiHandlers/RESTAPIProxy.swift diff --git a/ios/MullvadREST/RESTAccessTokenManager.swift b/ios/MullvadREST/ApiHandlers/RESTAccessTokenManager.swift similarity index 100% rename from ios/MullvadREST/RESTAccessTokenManager.swift rename to ios/MullvadREST/ApiHandlers/RESTAccessTokenManager.swift diff --git a/ios/MullvadREST/RESTAccountsProxy.swift b/ios/MullvadREST/ApiHandlers/RESTAccountsProxy.swift similarity index 100% rename from ios/MullvadREST/RESTAccountsProxy.swift rename to ios/MullvadREST/ApiHandlers/RESTAccountsProxy.swift diff --git a/ios/MullvadREST/RESTAuthenticationProxy.swift b/ios/MullvadREST/ApiHandlers/RESTAuthenticationProxy.swift similarity index 100% rename from ios/MullvadREST/RESTAuthenticationProxy.swift rename to ios/MullvadREST/ApiHandlers/RESTAuthenticationProxy.swift diff --git a/ios/MullvadREST/RESTAuthorization.swift b/ios/MullvadREST/ApiHandlers/RESTAuthorization.swift similarity index 100% rename from ios/MullvadREST/RESTAuthorization.swift rename to ios/MullvadREST/ApiHandlers/RESTAuthorization.swift diff --git a/ios/MullvadREST/RESTCoding.swift b/ios/MullvadREST/ApiHandlers/RESTCoding.swift similarity index 100% rename from ios/MullvadREST/RESTCoding.swift rename to ios/MullvadREST/ApiHandlers/RESTCoding.swift diff --git a/ios/MullvadREST/RESTDefaults.swift b/ios/MullvadREST/ApiHandlers/RESTDefaults.swift similarity index 100% rename from ios/MullvadREST/RESTDefaults.swift rename to ios/MullvadREST/ApiHandlers/RESTDefaults.swift diff --git a/ios/MullvadREST/RESTDevicesProxy.swift b/ios/MullvadREST/ApiHandlers/RESTDevicesProxy.swift similarity index 100% rename from ios/MullvadREST/RESTDevicesProxy.swift rename to ios/MullvadREST/ApiHandlers/RESTDevicesProxy.swift diff --git a/ios/MullvadREST/RESTError.swift b/ios/MullvadREST/ApiHandlers/RESTError.swift similarity index 100% rename from ios/MullvadREST/RESTError.swift rename to ios/MullvadREST/ApiHandlers/RESTError.swift diff --git a/ios/MullvadREST/RESTNetworkOperation.swift b/ios/MullvadREST/ApiHandlers/RESTNetworkOperation.swift similarity index 100% rename from ios/MullvadREST/RESTNetworkOperation.swift rename to ios/MullvadREST/ApiHandlers/RESTNetworkOperation.swift diff --git a/ios/MullvadREST/RESTProxy.swift b/ios/MullvadREST/ApiHandlers/RESTProxy.swift similarity index 100% rename from ios/MullvadREST/RESTProxy.swift rename to ios/MullvadREST/ApiHandlers/RESTProxy.swift diff --git a/ios/MullvadREST/RESTProxyFactory.swift b/ios/MullvadREST/ApiHandlers/RESTProxyFactory.swift similarity index 100% rename from ios/MullvadREST/RESTProxyFactory.swift rename to ios/MullvadREST/ApiHandlers/RESTProxyFactory.swift diff --git a/ios/MullvadREST/RESTRequestExecutor.swift b/ios/MullvadREST/ApiHandlers/RESTRequestExecutor.swift similarity index 100% rename from ios/MullvadREST/RESTRequestExecutor.swift rename to ios/MullvadREST/ApiHandlers/RESTRequestExecutor.swift diff --git a/ios/MullvadREST/RESTRequestFactory.swift b/ios/MullvadREST/ApiHandlers/RESTRequestFactory.swift similarity index 100% rename from ios/MullvadREST/RESTRequestFactory.swift rename to ios/MullvadREST/ApiHandlers/RESTRequestFactory.swift diff --git a/ios/MullvadREST/RESTRequestHandler.swift b/ios/MullvadREST/ApiHandlers/RESTRequestHandler.swift similarity index 100% rename from ios/MullvadREST/RESTRequestHandler.swift rename to ios/MullvadREST/ApiHandlers/RESTRequestHandler.swift diff --git a/ios/MullvadREST/RESTResponseHandler.swift b/ios/MullvadREST/ApiHandlers/RESTResponseHandler.swift similarity index 100% rename from ios/MullvadREST/RESTResponseHandler.swift rename to ios/MullvadREST/ApiHandlers/RESTResponseHandler.swift diff --git a/ios/MullvadREST/RESTTaskIdentifier.swift b/ios/MullvadREST/ApiHandlers/RESTTaskIdentifier.swift similarity index 100% rename from ios/MullvadREST/RESTTaskIdentifier.swift rename to ios/MullvadREST/ApiHandlers/RESTTaskIdentifier.swift diff --git a/ios/MullvadREST/RESTURLSession.swift b/ios/MullvadREST/ApiHandlers/RESTURLSession.swift similarity index 100% rename from ios/MullvadREST/RESTURLSession.swift rename to ios/MullvadREST/ApiHandlers/RESTURLSession.swift diff --git a/ios/MullvadREST/SSLPinningURLSessionDelegate.swift b/ios/MullvadREST/ApiHandlers/SSLPinningURLSessionDelegate.swift similarity index 100% rename from ios/MullvadREST/SSLPinningURLSessionDelegate.swift rename to ios/MullvadREST/ApiHandlers/SSLPinningURLSessionDelegate.swift diff --git a/ios/MullvadREST/ServerRelaysResponse.swift b/ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift similarity index 100% rename from ios/MullvadREST/ServerRelaysResponse.swift rename to ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift diff --git a/ios/MullvadREST/CachedRelays.swift b/ios/MullvadREST/Relay/CachedRelays.swift similarity index 100% rename from ios/MullvadREST/CachedRelays.swift rename to ios/MullvadREST/Relay/CachedRelays.swift diff --git a/ios/MullvadREST/Haversine.swift b/ios/MullvadREST/Relay/Haversine.swift similarity index 100% rename from ios/MullvadREST/Haversine.swift rename to ios/MullvadREST/Relay/Haversine.swift diff --git a/ios/MullvadREST/Midpoint.swift b/ios/MullvadREST/Relay/Midpoint.swift similarity index 100% rename from ios/MullvadREST/Midpoint.swift rename to ios/MullvadREST/Relay/Midpoint.swift diff --git a/ios/MullvadREST/RelayCache.swift b/ios/MullvadREST/Relay/RelayCache.swift similarity index 100% rename from ios/MullvadREST/RelayCache.swift rename to ios/MullvadREST/Relay/RelayCache.swift diff --git a/ios/MullvadREST/RelaySelector.swift b/ios/MullvadREST/Relay/RelaySelector.swift similarity index 100% rename from ios/MullvadREST/RelaySelector.swift rename to ios/MullvadREST/Relay/RelaySelector.swift diff --git a/ios/MullvadREST/ExponentialBackoff.swift b/ios/MullvadREST/RetryStrategy/ExponentialBackoff.swift similarity index 56% rename from ios/MullvadREST/ExponentialBackoff.swift rename to ios/MullvadREST/RetryStrategy/ExponentialBackoff.swift index 5c94735eaa56..57a54e07a905 100644 --- a/ios/MullvadREST/ExponentialBackoff.swift +++ b/ios/MullvadREST/RetryStrategy/ExponentialBackoff.swift @@ -32,22 +32,3 @@ struct ExponentialBackoff: IteratorProtocol { return next } } - -struct Jittered: IteratorProtocol - where InnerIterator.Element == Duration { - private var inner: InnerIterator - - init(_ inner: InnerIterator) { - self.inner = inner - } - - mutating func next() -> Duration? { - guard let interval = inner.next() else { return nil } - - let jitter = Double.random(in: 0.0 ... 1.0) - let millis = interval.milliseconds - let millisWithJitter = millis.saturatingAddition(Int(Double(millis) * jitter)) - - return .milliseconds(millisWithJitter) - } -} diff --git a/ios/MullvadREST/RetryStrategy/Jittered.swift b/ios/MullvadREST/RetryStrategy/Jittered.swift new file mode 100644 index 000000000000..271e088bbedf --- /dev/null +++ b/ios/MullvadREST/RetryStrategy/Jittered.swift @@ -0,0 +1,29 @@ +// +// Jittered.swift +// MullvadREST +// +// Created by Mojgan on 2023-12-08. +// Copyright © 2023 Mullvad VPN AB. All rights reserved. +// + +import Foundation +import MullvadTypes + +struct Jittered: IteratorProtocol + where InnerIterator.Element == Duration { + private var inner: InnerIterator + + init(_ inner: InnerIterator) { + self.inner = inner + } + + mutating func next() -> Duration? { + guard let interval = inner.next() else { return nil } + + let jitter = Double.random(in: 0.0 ... 1.0) + let millis = interval.milliseconds + let millisWithJitter = millis.saturatingAddition(Int(Double(millis) * jitter)) + + return .milliseconds(millisWithJitter) + } +} diff --git a/ios/MullvadREST/RESTRetryStrategy.swift b/ios/MullvadREST/RetryStrategy/RetryStrategy.swift similarity index 98% rename from ios/MullvadREST/RESTRetryStrategy.swift rename to ios/MullvadREST/RetryStrategy/RetryStrategy.swift index 2cd72ea53bb4..d7cd047b26eb 100644 --- a/ios/MullvadREST/RESTRetryStrategy.swift +++ b/ios/MullvadREST/RetryStrategy/RetryStrategy.swift @@ -1,5 +1,5 @@ // -// RESTRetryStrategy.swift +// RetryStrategy.swift // MullvadREST // // Created by pronebird on 09/12/2021. diff --git a/ios/MullvadREST/Transport/Direct/URLSessionTransport.swift b/ios/MullvadREST/Transport/Direct/URLSessionTransport.swift new file mode 100644 index 000000000000..fc5aee683b18 --- /dev/null +++ b/ios/MullvadREST/Transport/Direct/URLSessionTransport.swift @@ -0,0 +1,33 @@ +// +// URLSessionTransport.swift +// MullvadREST +// +// Created by Mojgan on 2023-12-08. +// Copyright © 2023 Mullvad VPN AB. All rights reserved. +// + +import Foundation +import MullvadTypes + +extension URLSessionTask: Cancellable {} + +public final class URLSessionTransport: RESTTransport { + public var name: String { + "url-session" + } + + public let urlSession: URLSession + + public init(urlSession: URLSession) { + self.urlSession = urlSession + } + + public func sendRequest( + _ request: URLRequest, + completion: @escaping (Data?, URLResponse?, Swift.Error?) -> Void + ) -> Cancellable { + let dataTask = urlSession.dataTask(with: request, completionHandler: completion) + dataTask.resume() + return dataTask + } +} diff --git a/ios/MullvadREST/RESTTransport.swift b/ios/MullvadREST/Transport/RESTTransport.swift similarity index 100% rename from ios/MullvadREST/RESTTransport.swift rename to ios/MullvadREST/Transport/RESTTransport.swift diff --git a/ios/MullvadREST/RESTTransportProvider.swift b/ios/MullvadREST/Transport/RESTTransportProvider.swift similarity index 100% rename from ios/MullvadREST/RESTTransportProvider.swift rename to ios/MullvadREST/Transport/RESTTransportProvider.swift diff --git a/ios/MullvadREST/ShadowSocksProxy.swift b/ios/MullvadREST/Transport/Shadowsocks/ShadowSocksProxy.swift similarity index 100% rename from ios/MullvadREST/ShadowSocksProxy.swift rename to ios/MullvadREST/Transport/Shadowsocks/ShadowSocksProxy.swift diff --git a/ios/MullvadREST/ShadowsocksConfiguration.swift b/ios/MullvadREST/Transport/Shadowsocks/ShadowsocksConfiguration.swift similarity index 100% rename from ios/MullvadREST/ShadowsocksConfiguration.swift rename to ios/MullvadREST/Transport/Shadowsocks/ShadowsocksConfiguration.swift diff --git a/ios/MullvadREST/ShadowsocksConfigurationCache.swift b/ios/MullvadREST/Transport/Shadowsocks/ShadowsocksConfigurationCache.swift similarity index 92% rename from ios/MullvadREST/ShadowsocksConfigurationCache.swift rename to ios/MullvadREST/Transport/Shadowsocks/ShadowsocksConfigurationCache.swift index 111215138e63..b09f4afdf66e 100644 --- a/ios/MullvadREST/ShadowsocksConfigurationCache.swift +++ b/ios/MullvadREST/Transport/Shadowsocks/ShadowsocksConfigurationCache.swift @@ -21,7 +21,7 @@ public final class ShadowsocksConfigurationCache { ) } - /// Returns configration from memory cache if available, otherwise attempts to load it from disk cache before + /// Returns configuration from memory cache if available, otherwise attempts to load it from disk cache before /// returning. public func read() throws -> ShadowsocksConfiguration { configurationLock.lock() diff --git a/ios/MullvadREST/URLSessionShadowsocksTransport.swift b/ios/MullvadREST/Transport/Shadowsocks/ShadowsocksTransport.swift similarity index 82% rename from ios/MullvadREST/URLSessionShadowsocksTransport.swift rename to ios/MullvadREST/Transport/Shadowsocks/ShadowsocksTransport.swift index ad587ba27c3b..c800a937badc 100644 --- a/ios/MullvadREST/URLSessionShadowsocksTransport.swift +++ b/ios/MullvadREST/Transport/Shadowsocks/ShadowsocksTransport.swift @@ -7,10 +7,9 @@ // import Foundation -import MullvadREST import MullvadTypes -public final class URLSessionShadowsocksTransport: RESTTransport { +public final class ShadowsocksTransport: RESTTransport { /// The Shadowsocks proxy instance that proxies all the traffic it receives private let shadowsocksProxy: ShadowsocksProxy @@ -26,7 +25,7 @@ public final class URLSessionShadowsocksTransport: RESTTransport { public init( urlSession: URLSession, - shadowsocksConfiguration: ShadowsocksConfiguration, + configuration: ShadowsocksConfiguration, addressCache: REST.AddressCache ) { self.urlSession = urlSession @@ -35,10 +34,10 @@ public final class URLSessionShadowsocksTransport: RESTTransport { shadowsocksProxy = ShadowsocksProxy( forwardAddress: apiAddress.ip, forwardPort: apiAddress.port, - bridgeAddress: shadowsocksConfiguration.bridgeAddress, - bridgePort: shadowsocksConfiguration.bridgePort, - password: shadowsocksConfiguration.password, - cipher: shadowsocksConfiguration.cipher + bridgeAddress: configuration.bridgeAddress, + bridgePort: configuration.bridgePort, + password: configuration.password, + cipher: configuration.cipher ) } diff --git a/ios/MullvadREST/module.private.modulemap b/ios/MullvadREST/Transport/Shadowsocks/module.private.modulemap similarity index 100% rename from ios/MullvadREST/module.private.modulemap rename to ios/MullvadREST/Transport/Shadowsocks/module.private.modulemap diff --git a/ios/MullvadREST/shadowsocks-proxy/.gitignore b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/.gitignore similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/.gitignore rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/.gitignore diff --git a/ios/MullvadREST/shadowsocks-proxy/Cargo.toml b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/Cargo.toml similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/Cargo.toml rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/Cargo.toml diff --git a/ios/MullvadREST/shadowsocks-proxy/build.rs b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/build.rs similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/build.rs rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/build.rs diff --git a/ios/MullvadREST/shadowsocks-proxy/include/shadowsocks.h b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/include/shadowsocks.h similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/include/shadowsocks.h rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/include/shadowsocks.h diff --git a/ios/MullvadREST/shadowsocks-proxy/src/bin/run.rs b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/bin/run.rs similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/src/bin/run.rs rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/bin/run.rs diff --git a/ios/MullvadREST/shadowsocks-proxy/src/bin/run_unsafe.rs b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/bin/run_unsafe.rs similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/src/bin/run_unsafe.rs rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/bin/run_unsafe.rs diff --git a/ios/MullvadREST/shadowsocks-proxy/src/ffi.rs b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/ffi.rs similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/src/ffi.rs rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/ffi.rs diff --git a/ios/MullvadREST/shadowsocks-proxy/src/lib.rs b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/lib.rs similarity index 100% rename from ios/MullvadREST/shadowsocks-proxy/src/lib.rs rename to ios/MullvadREST/Transport/Shadowsocks/shadowsocks-proxy/src/lib.rs diff --git a/ios/MullvadREST/Transport/Shadowsocks/shadowsocks.h b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks.h new file mode 100644 index 000000000000..1a0a856d8dc7 --- /dev/null +++ b/ios/MullvadREST/Transport/Shadowsocks/shadowsocks.h @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +typedef struct ProxyHandle { + void *context; + uint16_t port; +} ProxyHandle; + +/** + * # Safety + * `addr`, `password`, `cipher` must be valid for the lifetime of this function call and they must + * be backed by the amount of bytes as stored in the respective `*_len` parameters. + * + * `proxy_config` must be pointing to a valid memory region for the size of a `ProxyHandle` + * instance. + */ +int32_t start_shadowsocks_proxy(const uint8_t *forward_address, + uintptr_t forward_address_len, + uint16_t forward_port, + const uint8_t *addr, + uintptr_t addr_len, + uint16_t port, + const uint8_t *password, + uintptr_t password_len, + const uint8_t *cipher, + uintptr_t cipher_len, + struct ProxyHandle *proxy_config); + +/** + * # Safety + * `proxy_config` must be pointing to a valid instance of a `ProxyInstance`, as instantiated by + * `start_shadowsocks_proxy`. + */ +int32_t stop_shadowsocks_proxy(struct ProxyHandle *proxy_config); diff --git a/ios/MullvadREST/TransportProvider.swift b/ios/MullvadREST/Transport/TransportProvider.swift similarity index 96% rename from ios/MullvadREST/TransportProvider.swift rename to ios/MullvadREST/Transport/TransportProvider.swift index c2e11b7d82e3..65ff2b32096b 100644 --- a/ios/MullvadREST/TransportProvider.swift +++ b/ios/MullvadREST/Transport/TransportProvider.swift @@ -11,7 +11,7 @@ import Logging import MullvadTypes public final class TransportProvider: RESTTransportProvider { - private let urlSessionTransport: REST.URLSessionTransport + private let urlSessionTransport: URLSessionTransport private let relayCache: RelayCacheProtocol private let logger = Logger(label: "TransportProvider") private let addressCache: REST.AddressCache @@ -24,7 +24,7 @@ public final class TransportProvider: RESTTransportProvider { private let constraintsUpdater: RelayConstraintsUpdater public init( - urlSessionTransport: REST.URLSessionTransport, + urlSessionTransport: URLSessionTransport, relayCache: RelayCacheProtocol, addressCache: REST.AddressCache, shadowsocksCache: ShadowsocksConfigurationCache, @@ -66,12 +66,11 @@ public final class TransportProvider: RESTTransportProvider { let shadowsocksConfiguration = try shadowsocksConfiguration() let shadowsocksURLSession = urlSessionTransport.urlSession - let shadowsocksTransport = URLSessionShadowsocksTransport( + let shadowsocksTransport = ShadowsocksTransport( urlSession: shadowsocksURLSession, - shadowsocksConfiguration: shadowsocksConfiguration, + configuration: shadowsocksConfiguration, addressCache: addressCache ) - return shadowsocksTransport } catch { logger.error(error: error, message: "Failed to produce shadowsocks configuration.") diff --git a/ios/MullvadREST/RESTTransportStrategy.swift b/ios/MullvadREST/Transport/TransportStrategy.swift similarity index 98% rename from ios/MullvadREST/RESTTransportStrategy.swift rename to ios/MullvadREST/Transport/TransportStrategy.swift index d63b8c8833a6..d857a3406bde 100644 --- a/ios/MullvadREST/RESTTransportStrategy.swift +++ b/ios/MullvadREST/Transport/TransportStrategy.swift @@ -1,5 +1,5 @@ // -// RESTTransportStrategy.swift +// TransportStrategy.swift // MullvadREST // // Created by Marco Nikic on 2023-04-27. diff --git a/ios/MullvadREST/URLSessionTransport.swift b/ios/MullvadREST/URLSessionTransport.swift deleted file mode 100644 index c5b4cf6a6779..000000000000 --- a/ios/MullvadREST/URLSessionTransport.swift +++ /dev/null @@ -1,89 +0,0 @@ -// -// URLSessionTransport.swift -// MullvadREST -// -// Created by Sajad Vishkai on 2022-10-03. -// Copyright © 2022 Mullvad VPN AB. All rights reserved. -// - -import Foundation -import MullvadTypes - -extension URLSessionTask: Cancellable {} - -extension REST { - public final class URLSessionTransport: RESTTransport { - public var name: String { - "url-session" - } - - public let urlSession: URLSession - - public init(urlSession: URLSession) { - self.urlSession = urlSession - } - - public func sendRequest( - _ request: URLRequest, - completion: @escaping (Data?, URLResponse?, Swift.Error?) -> Void - ) -> Cancellable { - let dataTask = urlSession.dataTask(with: request, completionHandler: completion) - dataTask.resume() - return dataTask - } - } - - public final class URLSessionShadowSocksTransport: RESTTransport { - /// The Shadowsocks proxy instance that proxies all the traffic it receives - private let shadowSocksProxy: ShadowsocksProxy - /// The IPv4 representation of the loopback address used by `shadowSocksProxy` - private let localhost = "127.0.0.1" - - /// The `URLSession` used to send requests via `shadowSocksProxy` - public let urlSession: URLSession - - public var name: String { - "shadow-socks-url-session" - } - - public init( - urlSession: URLSession, - shadowSocksConfiguration: ServerShadowsocks, - shadowSocksBridgeRelay: BridgeRelay, - addressCache: REST.AddressCache - ) { - self.urlSession = urlSession - let apiAddress = addressCache.getCurrentEndpoint() - - shadowSocksProxy = ShadowsocksProxy( - forwardAddress: apiAddress.ip, - forwardPort: apiAddress.port, - bridgeAddress: shadowSocksBridgeRelay.ipv4AddrIn, - bridgePort: shadowSocksConfiguration.port, - password: shadowSocksConfiguration.password, - cipher: shadowSocksConfiguration.cipher - ) - } - - public func sendRequest( - _ request: URLRequest, - completion: @escaping (Data?, URLResponse?, Swift.Error?) -> Void - ) -> Cancellable { - // Start the Shadowsocks proxy in order to get a local port - shadowSocksProxy.start() - - // Copy the URL request and rewrite the host and port to point to the Shadowsocks proxy instance - var urlRequestCopy = request - urlRequestCopy.url = request.url.flatMap { url in - var components = URLComponents(url: url, resolvingAgainstBaseURL: false) - components?.host = localhost - components?.port = Int(shadowSocksProxy.localPort()) - return components?.url - } - - let dataTask = urlSession.dataTask(with: urlRequestCopy, completionHandler: completion) - dataTask.resume() - return dataTask - } - } -} diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 7463ca2102e6..6eed2f7b9306 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -29,7 +29,7 @@ 06799AE728F98E4800ACD94E /* RESTURLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE66528F83CA30033DD93 /* RESTURLSession.swift */; }; 06799AEA28F98E4800ACD94E /* RESTProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE66E28F83CA40033DD93 /* RESTProxy.swift */; }; 06799AEC28F98E4800ACD94E /* RESTTaskIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67528F83CA40033DD93 /* RESTTaskIdentifier.swift */; }; - 06799AEF28F98E4800ACD94E /* RESTRetryStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67628F83CA40033DD93 /* RESTRetryStrategy.swift */; }; + 06799AEF28F98E4800ACD94E /* RetryStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67628F83CA40033DD93 /* RetryStrategy.swift */; }; 06799AF028F98E4800ACD94E /* REST.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67B28F83CA50033DD93 /* REST.swift */; }; 06799AF128F98E4800ACD94E /* RESTAPIProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67328F83CA40033DD93 /* RESTAPIProxy.swift */; }; 06799AF228F98E4800ACD94E /* RESTAccessTokenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06FAE67228F83CA40033DD93 /* RESTAccessTokenManager.swift */; }; @@ -504,10 +504,9 @@ A97D30172AE6B5E90045C0E4 /* StoredWgKeyData.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97D30162AE6B5E90045C0E4 /* StoredWgKeyData.swift */; }; A97FF5502A0D2FFC00900996 /* NSFileCoordinator+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A97FF54F2A0D2FFC00900996 /* NSFileCoordinator+Extensions.swift */; }; A988A3E22AFE54AC0008D2C7 /* AccountExpiry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A6F2FA62AFBB9AE006D0856 /* AccountExpiry.swift */; }; - A988DF212ADD293D00D807EF /* RESTTransportStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A1DE782AD5708E0073F689 /* RESTTransportStrategy.swift */; }; A988DF272ADE86ED00D807EF /* WireGuardObfuscationSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = A988DF252ADE86ED00D807EF /* WireGuardObfuscationSettings.swift */; }; A988DF2A2ADE880300D807EF /* TunnelSettingsV3.swift in Sources */ = {isa = PBXBuildFile; fileRef = A988DF282ADE880300D807EF /* TunnelSettingsV3.swift */; }; - A9A1DE792AD5708E0073F689 /* RESTTransportStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A1DE782AD5708E0073F689 /* RESTTransportStrategy.swift */; }; + A9A1DE792AD5708E0073F689 /* TransportStrategy.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A1DE782AD5708E0073F689 /* TransportStrategy.swift */; }; A9A5F9E12ACB05160083449F /* AddressCacheTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06AC114028F841390037AF9A /* AddressCacheTracker.swift */; }; A9A5F9E22ACB05160083449F /* BackgroundTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58C76A0A2A338E4300100D75 /* BackgroundTask.swift */; }; A9A5F9E32ACB05160083449F /* AccountDataThrottling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 587988C628A2A01F00E3DF54 /* AccountDataThrottling.swift */; }; @@ -631,6 +630,9 @@ F05F39942B21C6C6006E60A7 /* relays.json in Resources */ = {isa = PBXBuildFile; fileRef = 58F3C0A524A50155003E76BE /* relays.json */; }; F05F39972B21C735006E60A7 /* RelayCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5820675A26E6576800655B05 /* RelayCache.swift */; }; F05F39982B21C73C006E60A7 /* CachedRelays.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585DA87626B024A600B8C587 /* CachedRelays.swift */; }; + F06045E62B231EB700B2D37A /* URLSessionTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F06045E52B231EB700B2D37A /* URLSessionTransport.swift */; }; + F06045EA2B23217E00B2D37A /* ShadowsocksTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F06045E92B23217E00B2D37A /* ShadowsocksTransport.swift */; }; + F06045EC2B2322A500B2D37A /* Jittered.swift in Sources */ = {isa = PBXBuildFile; fileRef = F06045EB2B2322A500B2D37A /* Jittered.swift */; }; F07BF2622A26279100042943 /* RedeemVoucherOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = F07BF2612A26279100042943 /* RedeemVoucherOperation.swift */; }; F07C9D952B220C77006F1C5E /* libshadowsocks_proxy.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 01F1FF1D29F0627D007083C3 /* libshadowsocks_proxy.a */; }; F07CFF2029F2720E008C0343 /* RegisteredDeviceInAppNotificationProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F07CFF1F29F2720E008C0343 /* RegisteredDeviceInAppNotificationProvider.swift */; }; @@ -658,9 +660,7 @@ F0DDE4142B220458006B57A7 /* ShadowSocksProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE40F2B220458006B57A7 /* ShadowSocksProxy.swift */; }; F0DDE4152B220458006B57A7 /* ShadowsocksConfigurationCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4102B220458006B57A7 /* ShadowsocksConfigurationCache.swift */; }; F0DDE4162B220458006B57A7 /* TransportProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4112B220458006B57A7 /* TransportProvider.swift */; }; - F0DDE4172B220458006B57A7 /* URLSessionShadowsocksTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4122B220458006B57A7 /* URLSessionShadowsocksTransport.swift */; }; F0DDE4182B220458006B57A7 /* ShadowsocksConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4132B220458006B57A7 /* ShadowsocksConfiguration.swift */; }; - F0DDE41A2B220531006B57A7 /* URLSessionTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4192B220531006B57A7 /* URLSessionTransport.swift */; }; F0DDE42A2B220A15006B57A7 /* Haversine.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4272B220A15006B57A7 /* Haversine.swift */; }; F0DDE42B2B220A15006B57A7 /* RelaySelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4282B220A15006B57A7 /* RelaySelector.swift */; }; F0DDE42C2B220A15006B57A7 /* Midpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = F0DDE4292B220A15006B57A7 /* Midpoint.swift */; }; @@ -1085,7 +1085,7 @@ 06FAE67328F83CA40033DD93 /* RESTAPIProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTAPIProxy.swift; sourceTree = ""; }; 06FAE67428F83CA40033DD93 /* RESTRequestHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTRequestHandler.swift; sourceTree = ""; }; 06FAE67528F83CA40033DD93 /* RESTTaskIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTTaskIdentifier.swift; sourceTree = ""; }; - 06FAE67628F83CA40033DD93 /* RESTRetryStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTRetryStrategy.swift; sourceTree = ""; }; + 06FAE67628F83CA40033DD93 /* RetryStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RetryStrategy.swift; sourceTree = ""; }; 06FAE67728F83CA40033DD93 /* ServerRelaysResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerRelaysResponse.swift; sourceTree = ""; }; 06FAE67828F83CA50033DD93 /* RESTCreateApplePaymentResponse+Localization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RESTCreateApplePaymentResponse+Localization.swift"; sourceTree = ""; }; 06FAE67928F83CA50033DD93 /* RESTAuthorization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTAuthorization.swift; sourceTree = ""; }; @@ -1535,7 +1535,7 @@ A97FF54F2A0D2FFC00900996 /* NSFileCoordinator+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSFileCoordinator+Extensions.swift"; sourceTree = ""; }; A988DF252ADE86ED00D807EF /* WireGuardObfuscationSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WireGuardObfuscationSettings.swift; sourceTree = ""; }; A988DF282ADE880300D807EF /* TunnelSettingsV3.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelSettingsV3.swift; sourceTree = ""; }; - A9A1DE782AD5708E0073F689 /* RESTTransportStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RESTTransportStrategy.swift; sourceTree = ""; }; + A9A1DE782AD5708E0073F689 /* TransportStrategy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransportStrategy.swift; sourceTree = ""; }; A9A5F9A12ACB003D0083449F /* TunnelManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelManagerTests.swift; sourceTree = ""; }; A9A8A8EA2A262AB30086D569 /* FileCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileCache.swift; sourceTree = ""; }; A9B6AC172ADE8F4300F7802A /* MigrationManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MigrationManagerTests.swift; sourceTree = ""; }; @@ -1558,8 +1558,11 @@ F028A5692A34D4E700C0CAA3 /* RedeemVoucherViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemVoucherViewController.swift; sourceTree = ""; }; F028A56B2A34D8E600C0CAA3 /* AddCreditSucceededViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddCreditSucceededViewController.swift; sourceTree = ""; }; F03580242A13842C00E5DAFD /* IncreasedHitButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IncreasedHitButton.swift; sourceTree = ""; }; - F04F95A02B21D24400431E08 /* shadowsocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = shadowsocks.h; path = "shadowsocks-proxy/include/shadowsocks.h"; sourceTree = ""; }; + F04F95A02B21D24400431E08 /* shadowsocks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = shadowsocks.h; sourceTree = ""; }; F04FBE602A8379EE009278D7 /* AppPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPreferences.swift; sourceTree = ""; }; + F06045E52B231EB700B2D37A /* URLSessionTransport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSessionTransport.swift; sourceTree = ""; }; + F06045E92B23217E00B2D37A /* ShadowsocksTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksTransport.swift; sourceTree = ""; }; + F06045EB2B2322A500B2D37A /* Jittered.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Jittered.swift; sourceTree = ""; }; F07BF2572A26112D00042943 /* InputTextFormatterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputTextFormatterTests.swift; sourceTree = ""; }; F07BF2612A26279100042943 /* RedeemVoucherOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RedeemVoucherOperation.swift; sourceTree = ""; }; F07CFF1F29F2720E008C0343 /* RegisteredDeviceInAppNotificationProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisteredDeviceInAppNotificationProvider.swift; sourceTree = ""; }; @@ -1584,9 +1587,7 @@ F0DDE40F2B220458006B57A7 /* ShadowSocksProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowSocksProxy.swift; sourceTree = ""; }; F0DDE4102B220458006B57A7 /* ShadowsocksConfigurationCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksConfigurationCache.swift; sourceTree = ""; }; F0DDE4112B220458006B57A7 /* TransportProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransportProvider.swift; sourceTree = ""; }; - F0DDE4122B220458006B57A7 /* URLSessionShadowsocksTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionShadowsocksTransport.swift; sourceTree = ""; }; F0DDE4132B220458006B57A7 /* ShadowsocksConfiguration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShadowsocksConfiguration.swift; sourceTree = ""; }; - F0DDE4192B220531006B57A7 /* URLSessionTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = URLSessionTransport.swift; sourceTree = ""; }; F0DDE4272B220A15006B57A7 /* Haversine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Haversine.swift; sourceTree = ""; }; F0DDE4282B220A15006B57A7 /* RelaySelector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RelaySelector.swift; sourceTree = ""; }; F0DDE4292B220A15006B57A7 /* Midpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Midpoint.swift; sourceTree = ""; }; @@ -1783,49 +1784,14 @@ 06799ABD28F98E1D00ACD94E /* MullvadREST */ = { isa = PBXGroup; children = ( - 06AC114128F8413A0037AF9A /* AddressCache.swift */, + F06045F02B2324DA00B2D37A /* ApiHandlers */, 062B45A228FD4C0F00746E77 /* Assets */, - 585DA87626B024A600B8C587 /* CachedRelays.swift */, - 5897F1732913EAF800AF5695 /* ExponentialBackoff.swift */, - F0DDE4272B220A15006B57A7 /* Haversine.swift */, - 06FAE67128F83CA40033DD93 /* HTTP.swift */, 582FFA82290A84E700895745 /* Info.plist */, - F0DDE4292B220A15006B57A7 /* Midpoint.swift */, 06799ABE28F98E1D00ACD94E /* MullvadREST.h */, - 5820675A26E6576800655B05 /* RelayCache.swift */, - F0DDE4282B220A15006B57A7 /* RelaySelector.swift */, + F0DC779F2B2222D20087F09D /* Relay */, 06FAE67B28F83CA50033DD93 /* REST.swift */, - 06FAE67228F83CA40033DD93 /* RESTAccessTokenManager.swift */, - 06FAE66828F83CA30033DD93 /* RESTAccountsProxy.swift */, - 06FAE67328F83CA40033DD93 /* RESTAPIProxy.swift */, - 06FAE67028F83CA40033DD93 /* RESTAuthenticationProxy.swift */, - 06FAE67928F83CA50033DD93 /* RESTAuthorization.swift */, - 06FAE66C28F83CA40033DD93 /* RESTCoding.swift */, - 062B45BB28FD8C3B00746E77 /* RESTDefaults.swift */, - 06FAE67A28F83CA50033DD93 /* RESTDevicesProxy.swift */, - 06FAE66928F83CA30033DD93 /* RESTError.swift */, - 06FAE66F28F83CA40033DD93 /* RESTNetworkOperation.swift */, - 06FAE66E28F83CA40033DD93 /* RESTProxy.swift */, - 06FAE66728F83CA30033DD93 /* RESTProxyFactory.swift */, - 589E76BF2A9378F100E502F3 /* RESTRequestExecutor.swift */, - 06FAE66A28F83CA30033DD93 /* RESTRequestFactory.swift */, - 06FAE67428F83CA40033DD93 /* RESTRequestHandler.swift */, - 06FAE66628F83CA30033DD93 /* RESTResponseHandler.swift */, - 06FAE67628F83CA40033DD93 /* RESTRetryStrategy.swift */, - 06FAE67528F83CA40033DD93 /* RESTTaskIdentifier.swift */, - 06FAE67D28F83CA50033DD93 /* RESTTransport.swift */, - 58E7BA182A975DF70068EC3A /* RESTTransportProvider.swift */, - A9A1DE782AD5708E0073F689 /* RESTTransportStrategy.swift */, - 06FAE66528F83CA30033DD93 /* RESTURLSession.swift */, - 06FAE67728F83CA40033DD93 /* ServerRelaysResponse.swift */, - F04F95A02B21D24400431E08 /* shadowsocks.h */, - F0DDE4132B220458006B57A7 /* ShadowsocksConfiguration.swift */, - F0DDE4102B220458006B57A7 /* ShadowsocksConfigurationCache.swift */, - F0DDE40F2B220458006B57A7 /* ShadowSocksProxy.swift */, - 06FAE66B28F83CA30033DD93 /* SSLPinningURLSessionDelegate.swift */, - F0DDE4112B220458006B57A7 /* TransportProvider.swift */, - F0DDE4122B220458006B57A7 /* URLSessionShadowsocksTransport.swift */, - F0DDE4192B220531006B57A7 /* URLSessionTransport.swift */, + F0DC77A12B2313330087F09D /* RetryStrategy */, + F0DC77A02B2223290087F09D /* Transport */, ); path = MullvadREST; sourceTree = ""; @@ -2916,6 +2882,35 @@ path = RedeemVoucher; sourceTree = ""; }; + F06045F02B2324DA00B2D37A /* ApiHandlers */ = { + isa = PBXGroup; + children = ( + 06AC114128F8413A0037AF9A /* AddressCache.swift */, + 06FAE67128F83CA40033DD93 /* HTTP.swift */, + 06FAE67228F83CA40033DD93 /* RESTAccessTokenManager.swift */, + 06FAE66828F83CA30033DD93 /* RESTAccountsProxy.swift */, + 06FAE67328F83CA40033DD93 /* RESTAPIProxy.swift */, + 06FAE67028F83CA40033DD93 /* RESTAuthenticationProxy.swift */, + 06FAE67928F83CA50033DD93 /* RESTAuthorization.swift */, + 06FAE66C28F83CA40033DD93 /* RESTCoding.swift */, + 062B45BB28FD8C3B00746E77 /* RESTDefaults.swift */, + 06FAE67A28F83CA50033DD93 /* RESTDevicesProxy.swift */, + 06FAE66928F83CA30033DD93 /* RESTError.swift */, + 06FAE66F28F83CA40033DD93 /* RESTNetworkOperation.swift */, + 06FAE66E28F83CA40033DD93 /* RESTProxy.swift */, + 06FAE66728F83CA30033DD93 /* RESTProxyFactory.swift */, + 589E76BF2A9378F100E502F3 /* RESTRequestExecutor.swift */, + 06FAE66A28F83CA30033DD93 /* RESTRequestFactory.swift */, + 06FAE67428F83CA40033DD93 /* RESTRequestHandler.swift */, + 06FAE66628F83CA30033DD93 /* RESTResponseHandler.swift */, + 06FAE67528F83CA40033DD93 /* RESTTaskIdentifier.swift */, + 06FAE66528F83CA30033DD93 /* RESTURLSession.swift */, + 06FAE67728F83CA40033DD93 /* ServerRelaysResponse.swift */, + 06FAE66B28F83CA30033DD93 /* SSLPinningURLSessionDelegate.swift */, + ); + path = ApiHandlers; + sourceTree = ""; + }; F09D04B82AE94F27003D4F89 /* GeneralAPIs */ = { isa = PBXGroup; children = ( @@ -2925,6 +2920,61 @@ path = GeneralAPIs; sourceTree = ""; }; + F0DC779F2B2222D20087F09D /* Relay */ = { + isa = PBXGroup; + children = ( + 585DA87626B024A600B8C587 /* CachedRelays.swift */, + F0DDE4272B220A15006B57A7 /* Haversine.swift */, + F0DDE4292B220A15006B57A7 /* Midpoint.swift */, + 5820675A26E6576800655B05 /* RelayCache.swift */, + F0DDE4282B220A15006B57A7 /* RelaySelector.swift */, + ); + path = Relay; + sourceTree = ""; + }; + F0DC77A02B2223290087F09D /* Transport */ = { + isa = PBXGroup; + children = ( + F0DC77A32B2315800087F09D /* Direct */, + 06FAE67D28F83CA50033DD93 /* RESTTransport.swift */, + 58E7BA182A975DF70068EC3A /* RESTTransportProvider.swift */, + F0DC77A22B2314EF0087F09D /* Shadowsocks */, + F0DDE4112B220458006B57A7 /* TransportProvider.swift */, + A9A1DE782AD5708E0073F689 /* TransportStrategy.swift */, + ); + path = Transport; + sourceTree = ""; + }; + F0DC77A12B2313330087F09D /* RetryStrategy */ = { + isa = PBXGroup; + children = ( + 5897F1732913EAF800AF5695 /* ExponentialBackoff.swift */, + F06045EB2B2322A500B2D37A /* Jittered.swift */, + 06FAE67628F83CA40033DD93 /* RetryStrategy.swift */, + ); + path = RetryStrategy; + sourceTree = ""; + }; + F0DC77A22B2314EF0087F09D /* Shadowsocks */ = { + isa = PBXGroup; + children = ( + F04F95A02B21D24400431E08 /* shadowsocks.h */, + F0DDE4132B220458006B57A7 /* ShadowsocksConfiguration.swift */, + F0DDE4102B220458006B57A7 /* ShadowsocksConfigurationCache.swift */, + F0DDE40F2B220458006B57A7 /* ShadowSocksProxy.swift */, + F06045E92B23217E00B2D37A /* ShadowsocksTransport.swift */, + ); + path = Shadowsocks; + sourceTree = ""; + }; + F0DC77A32B2315800087F09D /* Direct */ = { + isa = PBXGroup; + children = ( + F06045E52B231EB700B2D37A /* URLSessionTransport.swift */, + ); + path = Direct; + sourceTree = ""; + }; F0E361892A4ADCF500AEEF2B /* Welcome */ = { isa = PBXGroup; children = ( @@ -3792,9 +3842,10 @@ 58E7BA192A975DF70068EC3A /* RESTTransportProvider.swift in Sources */, 06799ADE28F98E4800ACD94E /* RESTRequestHandler.swift in Sources */, F0DDE4162B220458006B57A7 /* TransportProvider.swift in Sources */, - 06799AEF28F98E4800ACD94E /* RESTRetryStrategy.swift in Sources */, + 06799AEF28F98E4800ACD94E /* RetryStrategy.swift in Sources */, 06799AE128F98E4800ACD94E /* SSLPinningURLSessionDelegate.swift in Sources */, - A9A1DE792AD5708E0073F689 /* RESTTransportStrategy.swift in Sources */, + A9A1DE792AD5708E0073F689 /* TransportStrategy.swift in Sources */, + F06045EC2B2322A500B2D37A /* Jittered.swift in Sources */, F0DDE4152B220458006B57A7 /* ShadowsocksConfigurationCache.swift in Sources */, 06799AEA28F98E4800ACD94E /* RESTProxy.swift in Sources */, 06799ADD28F98E4800ACD94E /* RESTError.swift in Sources */, @@ -3803,8 +3854,8 @@ 06799AF228F98E4800ACD94E /* RESTAccessTokenManager.swift in Sources */, 06799AF328F98E4800ACD94E /* RESTAuthenticationProxy.swift in Sources */, F0DDE4142B220458006B57A7 /* ShadowSocksProxy.swift in Sources */, + F06045E62B231EB700B2D37A /* URLSessionTransport.swift in Sources */, 06799AE628F98E4800ACD94E /* ServerRelaysResponse.swift in Sources */, - F0DDE4172B220458006B57A7 /* URLSessionShadowsocksTransport.swift in Sources */, F0DDE42B2B220A15006B57A7 /* RelaySelector.swift in Sources */, F0DDE42C2B220A15006B57A7 /* Midpoint.swift in Sources */, 06799AF128F98E4800ACD94E /* RESTAPIProxy.swift in Sources */, @@ -3813,8 +3864,8 @@ 06799AE528F98E4800ACD94E /* HTTP.swift in Sources */, A9D99B9A2A1F7C3200DE27D3 /* RESTTransport.swift in Sources */, 06799AE028F98E4800ACD94E /* RESTCoding.swift in Sources */, + F06045EA2B23217E00B2D37A /* ShadowsocksTransport.swift in Sources */, 06799AFC28F98EE300ACD94E /* AddressCache.swift in Sources */, - F0DDE41A2B220531006B57A7 /* URLSessionTransport.swift in Sources */, 06799AF028F98E4800ACD94E /* REST.swift in Sources */, 06799ADF28F98E4800ACD94E /* RESTDevicesProxy.swift in Sources */, 06799ADA28F98E4800ACD94E /* RESTResponseHandler.swift in Sources */, @@ -4458,7 +4509,6 @@ buildActionMask = 2147483647; files = ( 58B465702A98C53300467203 /* RequestExecutorTests.swift in Sources */, - A988DF212ADD293D00D807EF /* RESTTransportStrategy.swift in Sources */, A917352129FAAA5200D5DCFD /* TransportStrategyTests.swift in Sources */, 58FBFBE9291622580020E046 /* ExponentialBackoffTests.swift in Sources */, 58BDEB9D2A98F69E00F578F2 /* MemoryCache.swift in Sources */, @@ -4739,7 +4789,7 @@ "LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = "$(PROJECT_DIR)/../target/aarch64-apple-ios/debug"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = "$(PROJECT_DIR)/../target/aarch64-apple-ios-sim/debug"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = "$(PROJECT_DIR)/../target/x86_64-apple-ios/debug"; - MODULEMAP_PRIVATE_FILE = $PROJECT_DIR/MullvadREST/module.private.modulemap; + MODULEMAP_PRIVATE_FILE = $PROJECT_DIR/MullvadREST/Transport/Shadowsocks/module.private.modulemap; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; PRODUCT_BUNDLE_IDENTIFIER = "$(APPLICATION_IDENTIFIER).MullvadREST"; @@ -4779,7 +4829,7 @@ "LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = "$(PROJECT_DIR)/../target/aarch64-apple-ios/release"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = "$(PROJECT_DIR)/../target/aarch64-apple-ios-sim/release"; "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = "$(PROJECT_DIR)/../target/x86_64-apple-ios/release"; - MODULEMAP_PRIVATE_FILE = $PROJECT_DIR/MullvadREST/module.private.modulemap; + MODULEMAP_PRIVATE_FILE = $PROJECT_DIR/MullvadREST/Transport/Shadowsocks/module.private.modulemap; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; PRODUCT_BUNDLE_IDENTIFIER = "$(APPLICATION_IDENTIFIER).MullvadREST"; diff --git a/ios/MullvadVPN/AppDelegate.swift b/ios/MullvadVPN/AppDelegate.swift index 859ffd084e1c..2a7e869888bf 100644 --- a/ios/MullvadVPN/AppDelegate.swift +++ b/ios/MullvadVPN/AppDelegate.swift @@ -83,7 +83,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD transactionLog: .default ) - let urlSessionTransport = REST.URLSessionTransport(urlSession: REST.makeURLSession()) + let urlSessionTransport = URLSessionTransport(urlSession: REST.makeURLSession()) let shadowsocksCache = ShadowsocksConfigurationCache(cacheDirectory: containerURL) // This init cannot fail as long as the security group identifier is valid diff --git a/ios/MullvadVPN/Coordinators/RelayFilterCoordinator.swift b/ios/MullvadVPN/Coordinators/RelayFilterCoordinator.swift index 6141ba6d8cee..deb57141e4b5 100644 --- a/ios/MullvadVPN/Coordinators/RelayFilterCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/RelayFilterCoordinator.swift @@ -6,8 +6,8 @@ // Copyright © 2023 Mullvad VPN AB. All rights reserved. // -import MullvadTypes import MullvadREST +import MullvadTypes import Routing import UIKit diff --git a/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift b/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift index 26c22a23b13f..59cb2a644a07 100644 --- a/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift +++ b/ios/MullvadVPN/Coordinators/SelectLocationCoordinator.swift @@ -6,8 +6,8 @@ // Copyright © 2023 Mullvad VPN AB. All rights reserved. // -import MullvadTypes import MullvadREST +import MullvadTypes import Routing import UIKit diff --git a/ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift b/ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift index aca8a309fc0b..9474a0a4813f 100644 --- a/ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift +++ b/ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift @@ -8,10 +8,10 @@ import Foundation import MullvadLogging +import MullvadREST import NetworkExtension import Operations import PacketTunnelCore -import MullvadREST class StartTunnelOperation: ResultOperation { typealias EncodeErrorHandler = (Error) -> Void diff --git a/ios/MullvadVPN/View controllers/Preferences/PreferencesInteractor.swift b/ios/MullvadVPN/View controllers/Preferences/PreferencesInteractor.swift index 792d7655fddc..96958f26740d 100644 --- a/ios/MullvadVPN/View controllers/Preferences/PreferencesInteractor.swift +++ b/ios/MullvadVPN/View controllers/Preferences/PreferencesInteractor.swift @@ -7,8 +7,8 @@ // import Foundation -import MullvadSettings import MullvadREST +import MullvadSettings final class PreferencesInteractor { private let tunnelManager: TunnelManager diff --git a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift index 585a44d98977..8728a4761b1b 100644 --- a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift +++ b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift @@ -7,8 +7,8 @@ // import Combine -import MullvadTypes import MullvadREST +import MullvadTypes import UIKit class RelayFilterViewController: UIViewController { diff --git a/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift b/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift index 1fc5970af598..b19fef0df605 100644 --- a/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift +++ b/ios/MullvadVPN/View controllers/SelectLocation/SelectLocationViewController.swift @@ -7,8 +7,8 @@ // import MullvadLogging -import MullvadTypes import MullvadREST +import MullvadTypes import UIKit final class SelectLocationViewController: UIViewController { diff --git a/ios/MullvadVPNTests/RelayCacheTracker+Stubs.swift b/ios/MullvadVPNTests/RelayCacheTracker+Stubs.swift index a9e146aff719..4adcccececbf 100644 --- a/ios/MullvadVPNTests/RelayCacheTracker+Stubs.swift +++ b/ios/MullvadVPNTests/RelayCacheTracker+Stubs.swift @@ -7,8 +7,8 @@ // import Foundation -@testable import MullvadTypes @testable import MullvadREST +@testable import MullvadTypes struct RelayCacheTrackerStub: RelayCacheTrackerProtocol { func startPeriodicUpdates() {} diff --git a/ios/PacketTunnel/PacketTunnelProvider/PacketTunnelProvider.swift b/ios/PacketTunnel/PacketTunnelProvider/PacketTunnelProvider.swift index 72720c6fea6d..cd3ccc8bd1f7 100644 --- a/ios/PacketTunnel/PacketTunnelProvider/PacketTunnelProvider.swift +++ b/ios/PacketTunnel/PacketTunnelProvider/PacketTunnelProvider.swift @@ -36,7 +36,7 @@ class PacketTunnelProvider: NEPacketTunnelProvider { let relayCache = RelayCache(cacheDirectory: containerURL) let urlSession = REST.makeURLSession() - let urlSessionTransport = REST.URLSessionTransport(urlSession: urlSession) + let urlSessionTransport = URLSessionTransport(urlSession: urlSession) let shadowsocksCache = ShadowsocksConfigurationCache(cacheDirectory: containerURL) // This init cannot fail as long as the security group identifier is valid diff --git a/ios/PacketTunnel/PacketTunnelProvider/RelaySelectorWrapper.swift b/ios/PacketTunnel/PacketTunnelProvider/RelaySelectorWrapper.swift index f5450cfc257f..5127e0a55b32 100644 --- a/ios/PacketTunnel/PacketTunnelProvider/RelaySelectorWrapper.swift +++ b/ios/PacketTunnel/PacketTunnelProvider/RelaySelectorWrapper.swift @@ -7,9 +7,9 @@ // import Foundation +import MullvadREST import MullvadTypes import PacketTunnelCore -import MullvadREST struct RelaySelectorWrapper: RelaySelectorProtocol { let relayCache: RelayCache diff --git a/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift b/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift index 5f772643dae5..b80d92df95b7 100644 --- a/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift +++ b/ios/PacketTunnelCoreTests/PacketTunnelActorTests.swift @@ -7,11 +7,11 @@ // import Combine +@testable import MullvadREST @testable import MullvadSettings import MullvadTypes import Network @testable import PacketTunnelCore -@testable import MullvadREST import WireGuardKitTypes import XCTest