From dc72b5dda58d425327fd04bd058ca0533dc527f6 Mon Sep 17 00:00:00 2001 From: Jon Petersson Date: Tue, 29 Oct 2024 12:40:19 +0100 Subject: [PATCH] Add shadowsocks fields to relay list response from the API --- .../ApiHandlers/ServerRelaysResponse.swift | 17 ++++++++++--- ios/MullvadREST/Relay/IPOverrideWrapper.swift | 3 ++- .../RelayCacheTracker/RelayCacheTracker.swift | 3 ++- .../Settings/SettingsInteractor.swift | 2 +- .../ServerRelaysResponse+Stubs.swift | 24 ++++++++++++------- .../MullvadREST/Relay/RelayCacheTests.swift | 3 ++- .../Relay/RelaySelectorTests.swift | 6 +++-- .../IPOverrideWrapperTests.swift | 3 ++- 8 files changed, 43 insertions(+), 18 deletions(-) diff --git a/ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift b/ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift index 256a101857e6..5ea32c0951e4 100644 --- a/ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift +++ b/ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift @@ -62,6 +62,7 @@ extension REST { public let publicKey: Data public let includeInCountry: Bool public let daita: Bool? + public let shadowsocksExtraAddrIn: [String]? public func override(ipv4AddrIn: IPv4Address?, ipv6AddrIn: IPv6Address?) -> Self { return ServerRelay( @@ -75,7 +76,8 @@ extension REST { ipv6AddrIn: ipv6AddrIn ?? self.ipv6AddrIn, publicKey: publicKey, includeInCountry: includeInCountry, - daita: daita + daita: daita, + shadowsocksExtraAddrIn: shadowsocksExtraAddrIn ) } @@ -91,7 +93,8 @@ extension REST { ipv6AddrIn: ipv6AddrIn, publicKey: publicKey, includeInCountry: includeInCountry, - daita: daita + daita: daita, + shadowsocksExtraAddrIn: shadowsocksExtraAddrIn ) } } @@ -101,12 +104,20 @@ extension REST { public let ipv6Gateway: IPv6Address public let portRanges: [[UInt16]] public let relays: [ServerRelay] + public let shadowsocksPortRanges: [[UInt16]] - public init(ipv4Gateway: IPv4Address, ipv6Gateway: IPv6Address, portRanges: [[UInt16]], relays: [ServerRelay]) { + public init( + ipv4Gateway: IPv4Address, + ipv6Gateway: IPv6Address, + portRanges: [[UInt16]], + relays: [ServerRelay], + shadowsocksPortRanges: [[UInt16]] + ) { self.ipv4Gateway = ipv4Gateway self.ipv6Gateway = ipv6Gateway self.portRanges = portRanges self.relays = relays + self.shadowsocksPortRanges = shadowsocksPortRanges } } diff --git a/ios/MullvadREST/Relay/IPOverrideWrapper.swift b/ios/MullvadREST/Relay/IPOverrideWrapper.swift index 1ac2c4dc7dc6..3e11591317b0 100644 --- a/ios/MullvadREST/Relay/IPOverrideWrapper.swift +++ b/ios/MullvadREST/Relay/IPOverrideWrapper.swift @@ -58,7 +58,8 @@ public class IPOverrideWrapper: RelayCacheProtocol { ipv4Gateway: wireguard.ipv4Gateway, ipv6Gateway: wireguard.ipv6Gateway, portRanges: wireguard.portRanges, - relays: overridenWireguardRelays + relays: overridenWireguardRelays, + shadowsocksPortRanges: wireguard.shadowsocksPortRanges ), bridge: REST.ServerBridges( shadowsocks: bridge.shadowsocks, diff --git a/ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift b/ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift index 27f1caa1fa02..e8731b526827 100644 --- a/ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift +++ b/ios/MullvadVPN/RelayCacheTracker/RelayCacheTracker.swift @@ -110,7 +110,8 @@ final class RelayCacheTracker: RelayCacheTrackerProtocol { cachedRelays.relays.wireguard.ipv4Gateway, ipv6Gateway: cachedRelays.relays.wireguard.ipv6Gateway, portRanges: cachedRelays.relays.wireguard.portRanges, - relays: cachedRelaysWithFixedDaita + relays: cachedRelaysWithFixedDaita, + shadowsocksPortRanges: cachedRelays.relays.wireguard.shadowsocksPortRanges ) let updatedRelays = REST.ServerRelaysResponse( diff --git a/ios/MullvadVPN/View controllers/Settings/SettingsInteractor.swift b/ios/MullvadVPN/View controllers/Settings/SettingsInteractor.swift index 370f9253cd50..eb21e716ffca 100644 --- a/ios/MullvadVPN/View controllers/Settings/SettingsInteractor.swift +++ b/ios/MullvadVPN/View controllers/Settings/SettingsInteractor.swift @@ -54,7 +54,7 @@ final class SettingsInteractor { } catch let error as NoRelaysSatisfyingConstraintsError where error.reason == .noDaitaRelaysFound { // Return error if no relays could be selected due to DAITA constraints. compatibilityError = tunnelSettings.tunnelMultihopState.isEnabled ? .multihop : .singlehop - } catch let error as NoRelaysSatisfyingConstraintsError { + } catch _ as NoRelaysSatisfyingConstraintsError { // Even if the constraints error is not DAITA specific, if both DAITA and Direct only are enabled, // we should return a DAITA related error since the current settings would have resulted in the // relay selector not being able to select a DAITA relay anyway. diff --git a/ios/MullvadVPNTests/MullvadREST/ApiHandlers/ServerRelaysResponse+Stubs.swift b/ios/MullvadVPNTests/MullvadREST/ApiHandlers/ServerRelaysResponse+Stubs.swift index be0b8088a433..e2fe5ce04396 100644 --- a/ios/MullvadVPNTests/MullvadREST/ApiHandlers/ServerRelaysResponse+Stubs.swift +++ b/ios/MullvadVPNTests/MullvadREST/ApiHandlers/ServerRelaysResponse+Stubs.swift @@ -86,7 +86,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: true + daita: true, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "se10-wireguard", @@ -99,7 +100,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: false + daita: false, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "se2-wireguard", @@ -112,7 +114,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: false + daita: false, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "se6-wireguard", @@ -125,7 +128,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: false + daita: false, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "us-dal-wg-001", @@ -138,7 +142,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: true + daita: true, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "us-nyc-wg-301", @@ -151,7 +156,8 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: true + daita: true, + shadowsocksExtraAddrIn: nil ), REST.ServerRelay( hostname: "us-nyc-wg-302", @@ -164,9 +170,11 @@ enum ServerRelaysResponseStubs { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: true + daita: true, + shadowsocksExtraAddrIn: nil ), - ] + ], + shadowsocksPortRanges: [] ), bridge: REST.ServerBridges(shadowsocks: [ REST.ServerShadowsocks(protocol: "tcp", port: 443, cipher: "aes-256-gcm", password: "mullvad"), diff --git a/ios/MullvadVPNTests/MullvadREST/Relay/RelayCacheTests.swift b/ios/MullvadVPNTests/MullvadREST/Relay/RelayCacheTests.swift index 6d9699574216..54aa317be31e 100644 --- a/ios/MullvadVPNTests/MullvadREST/Relay/RelayCacheTests.swift +++ b/ios/MullvadVPNTests/MullvadREST/Relay/RelayCacheTests.swift @@ -50,7 +50,8 @@ extension REST.ServerRelaysResponse { ipv4Gateway: .loopback, ipv6Gateway: .loopback, portRanges: [], - relays: serverRelays + relays: serverRelays, + shadowsocksPortRanges: [] ), bridge: REST.ServerBridges(shadowsocks: [], relays: bridgeRelays) ) diff --git a/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift b/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift index d15d18aab367..7a3f6a7d73a2 100644 --- a/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift +++ b/ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorTests.swift @@ -338,9 +338,11 @@ extension RelaySelectorTests { ipv6AddrIn: .loopback, publicKey: PrivateKey().publicKey.rawValue, includeInCountry: true, - daita: true + daita: true, + shadowsocksExtraAddrIn: nil ), - ] + ], + shadowsocksPortRanges: [] ), bridge: REST.ServerBridges(shadowsocks: [], relays: []) ) diff --git a/ios/MullvadVPNTests/MullvadSettings/IPOverrideWrapperTests.swift b/ios/MullvadVPNTests/MullvadSettings/IPOverrideWrapperTests.swift index 5f5648c06b0b..8a71f1b0fc86 100644 --- a/ios/MullvadVPNTests/MullvadSettings/IPOverrideWrapperTests.swift +++ b/ios/MullvadVPNTests/MullvadSettings/IPOverrideWrapperTests.swift @@ -84,7 +84,8 @@ extension IPOverrideWrapperTests { ipv6AddrIn: .any, publicKey: Data(), includeInCountry: true, - daita: false + daita: false, + shadowsocksExtraAddrIn: nil ) }