Skip to content

Commit

Permalink
Add smart routing to daita settings data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Sep 25, 2024
1 parent bea8e15 commit 3a830d0
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ios/MullvadREST/Relay/RelayPicking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct SinglehopPicker: RelayPicking {
by: constraints.exitLocations,
in: relays,
filterConstraint: constraints.filter,
daitaEnabled: daitaSettings.state.isEnabled
daitaEnabled: daitaSettings.daitaState.isEnabled
)
} catch let error as NoRelaysSatisfyingConstraintsError where error.reason == .noDaitaRelaysFound {
#if DEBUG
Expand Down Expand Up @@ -83,7 +83,7 @@ struct MultihopPicker: RelayPicking {
by: constraints.entryLocations,
in: relays,
filterConstraint: constraints.filter,
daitaEnabled: daitaSettings.state.isEnabled
daitaEnabled: daitaSettings.daitaState.isEnabled
)

let exitCandidates = try RelaySelector.WireGuard.findCandidates(
Expand Down
20 changes: 16 additions & 4 deletions ios/MullvadSettings/DAITASettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@ public enum DAITAState: Codable {
}
}

/// Selected relay is incompatible with Daita, either through singlehop or multihop.
/// Whether smart routing is enabled
public enum SmartRoutingState: Codable {
case on
case off

public var isEnabled: Bool {
self == .on
}
}

/// Selected relay is incompatible with DAITA, either through singlehop or multihop.
public enum DAITASettingsCompatibilityError {
case singlehop, multihop
}

public struct DAITASettings: Codable, Equatable {
public let state: DAITAState
public let daitaState: DAITAState
public let smartRoutingState: SmartRoutingState

public init(state: DAITAState = .off) {
self.state = state
public init(daitaState: DAITAState = .off, smartRoutingState: SmartRoutingState = .off) {
self.daitaState = daitaState
self.smartRoutingState = smartRoutingState
}
}
2 changes: 1 addition & 1 deletion ios/MullvadVPN/Coordinators/LocationCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
customListRepository: customListRepository,
constraints: tunnelManager.settings.relayConstraints,
multihopEnabled: tunnelManager.settings.tunnelMultihopState.isEnabled,
daitaEnabled: tunnelManager.settings.daita.state.isEnabled,
daitaEnabled: tunnelManager.settings.daita.daitaState.isEnabled,
startContext: startContext
)
locationViewControllerWrapper.delegate = self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ final class SimulatorTunnelProviderHost: SimulatorTunnelProviderDelegate {
remotePort: selectedRelays.entry?.endpoint.ipv4Relay.port ?? selectedRelays.exit.endpoint.ipv4Relay
.port,
isPostQuantum: settings.tunnelQuantumResistance.isEnabled,
isDaitaEnabled: settings.daita.state.isEnabled
isDaitaEnabled: settings.daita.daitaState.isEnabled
)
)
} catch {
Expand Down
2 changes: 1 addition & 1 deletion ios/MullvadVPN/TunnelManager/StartTunnelOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class StartTunnelOperation: ResultOperation<Void> {
tunnelStatus.state = .connecting(
selectedRelays,
isPostQuantum: interactor.settings.tunnelQuantumResistance.isEnabled,
isDaita: interactor.settings.daita.state.isEnabled
isDaita: interactor.settings.daita.daitaState.isEnabled
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ final class VPNSettingsCellFactory: CellFactoryProtocol {
comment: ""
)
cell.accessibilityIdentifier = item.accessibilityIdentifier
cell.setOn(viewModel.daitaSettings.state.isEnabled, animated: false)
cell.setOn(viewModel.daitaSettings.daitaState.isEnabled, animated: false)

cell.infoButtonHandler = { [weak self] in
self?.delegate?.showInfo(for: .daita)
}

cell.action = { [weak self] isEnabled in
let state: DAITAState = isEnabled ? .on : .off
self?.delegate?.switchDaitaState(DAITASettings(state: state))
self?.delegate?.switchDaitaState(DAITASettings(daitaState: state))
}

case .multihopSwitch:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class VPNSettingsInteractor {
}

func evaluateDaitaSettingsCompatibility(_ settings: DAITASettings) -> DAITASettingsCompatibilityError? {
guard settings.state.isEnabled else { return nil }
guard settings.daitaState.isEnabled else { return nil }

var tunnelSettings = tunnelSettings
tunnelSettings.daita = settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension PacketTunnelActor {
}

var daitaConfiguration: DaitaConfiguration?
if settings.daita.state.isEnabled {
if settings.daita.daitaState.isEnabled {
let maybeNot = Maybenot()
daitaConfiguration = DaitaConfiguration(
machines: maybeNot.machines,
Expand Down
8 changes: 4 additions & 4 deletions ios/PacketTunnelCore/Actor/PacketTunnelActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ extension PacketTunnelActor {
) async throws {
let settings: Settings = try settingsReader.read()

if settings.quantumResistance.isEnabled || settings.daita.state.isEnabled {
if settings.quantumResistance.isEnabled || settings.daita.daitaState.isEnabled {
try await tryStartEphemeralPeerNegotiation(withSettings: settings, nextRelays: nextRelays, reason: reason)
} else {
try await tryStartConnection(withSettings: settings, nextRelays: nextRelays, reason: reason)
Expand Down Expand Up @@ -307,7 +307,7 @@ extension PacketTunnelActor {
}

var daitaConfiguration: DaitaConfiguration?
if settings.daita.state.isEnabled {
if settings.daita.daitaState.isEnabled {
let maybeNot = Maybenot()
daitaConfiguration = DaitaConfiguration(
machines: maybeNot.machines,
Expand Down Expand Up @@ -417,7 +417,7 @@ extension PacketTunnelActor {
transportLayer: .udp,
remotePort: connectedRelay.endpoint.ipv4Relay.port,
isPostQuantum: settings.quantumResistance.isEnabled,
isDaitaEnabled: settings.daita.state.isEnabled
isDaitaEnabled: settings.daita.daitaState.isEnabled
)
case .disconnecting, .disconnected:
return nil
Expand Down Expand Up @@ -460,7 +460,7 @@ extension PacketTunnelActor {
transportLayer: transportLayer,
remotePort: protocolObfuscator.remotePort,
isPostQuantum: settings.quantumResistance.isEnabled,
isDaitaEnabled: settings.daita.state.isEnabled
isDaitaEnabled: settings.daita.daitaState.isEnabled
)
}

Expand Down

0 comments on commit 3a830d0

Please sign in to comment.