summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ios/MullvadREST/Relay/RelayPicking/MultihopPicker.swift18
-rw-r--r--ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift2
-rw-r--r--ios/MullvadREST/Relay/RelayPicking/SinglehopPicker.swift8
-rw-r--r--ios/MullvadVPN/Coordinators/LocationCoordinator.swift60
4 files changed, 65 insertions, 23 deletions
diff --git a/ios/MullvadREST/Relay/RelayPicking/MultihopPicker.swift b/ios/MullvadREST/Relay/RelayPicking/MultihopPicker.swift
index afe620154c..5faa369d53 100644
--- a/ios/MullvadREST/Relay/RelayPicking/MultihopPicker.swift
+++ b/ios/MullvadREST/Relay/RelayPicking/MultihopPicker.swift
@@ -10,13 +10,19 @@ import MullvadLogging
import MullvadSettings
import MullvadTypes
-struct MultihopPicker: RelayPicking {
- let logger = Logger(label: "MultihopPicker")
- let relays: REST.ServerRelaysResponse
- let tunnelSettings: LatestTunnelSettings
- let connectionAttemptCount: UInt
+public struct MultihopPicker: RelayPicking {
+ public let logger = Logger(label: "MultihopPicker")
+ public let relays: REST.ServerRelaysResponse
+ public let tunnelSettings: LatestTunnelSettings
+ public let connectionAttemptCount: UInt
- func pick() throws -> SelectedRelays {
+ public init(relays: REST.ServerRelaysResponse, tunnelSettings: LatestTunnelSettings, connectionAttemptCount: UInt) {
+ self.relays = relays
+ self.tunnelSettings = tunnelSettings
+ self.connectionAttemptCount = connectionAttemptCount
+ }
+
+ public func pick() throws -> SelectedRelays {
let constraints = tunnelSettings.relayConstraints
let entryConstraints = tunnelSettings.automaticMultihopIsEnabled ? .any : constraints.entryLocations
let entryFilter = tunnelSettings.automaticMultihopIsEnabled ? .any : constraints.entryFilter
diff --git a/ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift b/ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift
index 4d0f8077b9..d6e3ec2a1c 100644
--- a/ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift
+++ b/ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift
@@ -11,7 +11,7 @@ import MullvadSettings
import MullvadTypes
import Network
-protocol RelayPicking {
+public protocol RelayPicking {
var logger: Logger { get }
var relays: REST.ServerRelaysResponse { get }
var tunnelSettings: LatestTunnelSettings { get }
diff --git a/ios/MullvadREST/Relay/RelayPicking/SinglehopPicker.swift b/ios/MullvadREST/Relay/RelayPicking/SinglehopPicker.swift
index 692babd854..a165f28449 100644
--- a/ios/MullvadREST/Relay/RelayPicking/SinglehopPicker.swift
+++ b/ios/MullvadREST/Relay/RelayPicking/SinglehopPicker.swift
@@ -11,10 +11,10 @@ import MullvadSettings
import MullvadTypes
public struct SinglehopPicker: RelayPicking {
- let logger = Logger(label: "SinglehopPicker")
- let relays: REST.ServerRelaysResponse
- let tunnelSettings: LatestTunnelSettings
- let connectionAttemptCount: UInt
+ public let logger = Logger(label: "SinglehopPicker")
+ public let relays: REST.ServerRelaysResponse
+ public let tunnelSettings: LatestTunnelSettings
+ public let connectionAttemptCount: UInt
public init(relays: REST.ServerRelaysResponse, tunnelSettings: LatestTunnelSettings, connectionAttemptCount: UInt) {
self.relays = relays
diff --git a/ios/MullvadVPN/Coordinators/LocationCoordinator.swift b/ios/MullvadVPN/Coordinators/LocationCoordinator.swift
index 7f3095093b..a8b98a46a7 100644
--- a/ios/MullvadVPN/Coordinators/LocationCoordinator.swift
+++ b/ios/MullvadVPN/Coordinators/LocationCoordinator.swift
@@ -100,27 +100,63 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
)
hostingController.view.setAccessibilityIdentifier(.selectLocationView)
- gatherMultihopData()
+// print("Multihop: .whenNeeded")
+//
+// gatherMultihopData(obfuscationState: .lwo, multihopState: .whenNeeded)
+// gatherMultihopData(obfuscationState: .quic, multihopState: .whenNeeded)
+//
+// print("")
+// print("Multihop: .always + Automatic")
+//
+ gatherMultihopData(obfuscationState: .lwo, multihopState: .always)
+ gatherMultihopData(obfuscationState: .quic, multihopState: .always)
navigationController.pushViewController(hostingController, animated: false)
}
- private func gatherMultihopData() {
- var settings = LatestTunnelSettings(tunnelMultihopState: .whenNeeded, daita: .init(daitaState: .on))
- settings.wireGuardObfuscation.state = .quic
+ private func gatherMultihopData(obfuscationState: WireGuardObfuscationState, multihopState: MultihopState) {
+ var settings = LatestTunnelSettings(tunnelMultihopState: multihopState, daita: .init(daitaState: .on))
+ settings.wireGuardObfuscation.state = obfuscationState
let relays = try! relayCacheTracker.getCachedRelays().relays
+ let relayLocations = RelayWithLocation.locateRelays(relays: relays.wireguard.relays, locations: relays.locations)
- let singlehopPicker = SinglehopPicker(
- relays: relays,
- tunnelSettings: settings,
- connectionAttemptCount: 0
- )
+ print("")
+ print("Obfuscation: \(obfuscationState)")
+ print("")
+
+ relayLocations.forEach {
+ guard $0.relay.active else { return }
+
+ let picker: RelayPicking
+
+ let splitLocation = $0.relay.hostname.split(separator: "-")
+ let location = RelayLocation(dashSeparatedString: "\(splitLocation[0])-\(splitLocation[1])-\($0.relay.hostname)")!
+
+ let selectedRelay = UserSelectedRelays(locations: [location])
+ settings.relayConstraints.exitLocations = .only(selectedRelay)
+
+ if multihopState == .always {
+ settings.relayConstraints.entryLocations = .any
+
+ picker = MultihopPicker(
+ relays: relays,
+ tunnelSettings: settings,
+ connectionAttemptCount: 0
+ )
+ } else {
+ picker = SinglehopPicker(
+ relays: relays,
+ tunnelSettings: settings,
+ connectionAttemptCount: 0
+ )
+ }
- relays.wireguard.relays.forEach {
do {
- let relays = try singlehopPicker.pick()
- print("Relays: \(relays.entry?.location.countryCode), Country: \($0.location.country), city: \($0.location.city)")
+ let routedRelays = try picker.pick()
+ if let routedEntry = routedRelays.entry {
+ print("Selected: \($0.serverLocation.country), \($0.serverLocation.city) (\($0.relay.hostname)) - Routed: \(routedEntry.location.country), \(routedEntry.location.city) (\(routedEntry.hostname))")
+ }
} catch {
print(error.description)
}