-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
236 additions
and
74 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// Tunnel+Settings.swift | ||
// MullvadVPN | ||
// | ||
// Created by Mojgan on 2024-06-19. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import MullvadLogging | ||
import MullvadSettings | ||
|
||
protocol TunnelSettingsStrategyProtocol { | ||
func shouldReconnectToNewRelay(oldSettings: LatestTunnelSettings, newSettings: LatestTunnelSettings) -> Bool | ||
} | ||
|
||
struct TunnelSettingsStrategy: TunnelSettingsStrategyProtocol { | ||
let logger: Logger? | ||
|
||
init(logger: Logger? = nil) { | ||
self.logger = logger | ||
} | ||
|
||
func shouldReconnectToNewRelay(oldSettings: LatestTunnelSettings, newSettings: LatestTunnelSettings) -> Bool { | ||
switch (oldSettings, newSettings) { | ||
case let (old, new) where old.relayConstraints != new.relayConstraints: | ||
logger?.debug("Relay address changed from \(old.relayConstraints) to \(new.relayConstraints)") | ||
return true | ||
case let (old, new) where old.tunnelMultihopState != new.tunnelMultihopState: | ||
logger? | ||
.debug("Tunnel multi-hop state changed from \(old.tunnelMultihopState) to \(new.tunnelMultihopState)") | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
ios/MullvadVPNTests/MullvadVPN/TunnelManager/TunnelSettingsStrategyTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// TunnelSettingsStrategyTests.swift | ||
// MullvadVPNTests | ||
// | ||
// Created by Mojgan on 2024-06-19. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
import MullvadSettings | ||
import MullvadTypes | ||
import XCTest | ||
|
||
final class TunnelSettingsStrategyTests: XCTestCase { | ||
func connectToNewRelayOnMultihopChangesTest() { | ||
var currentSettings = LatestTunnelSettings() | ||
TunnelSettingsUpdate.multihop(.off).apply(to: ¤tSettings) | ||
|
||
var updatedSettings = currentSettings | ||
TunnelSettingsUpdate.multihop(.on).apply(to: &updatedSettings) | ||
|
||
let tunnelSettingsStrategy = TunnelSettingsStrategy() | ||
XCTAssertTrue(tunnelSettingsStrategy.shouldReconnectToNewRelay( | ||
oldSettings: currentSettings, | ||
newSettings: updatedSettings | ||
)) | ||
} | ||
|
||
func connectToNewRelayOnRelaysConstraintChangeTest() { | ||
var currentSettings = LatestTunnelSettings() | ||
TunnelSettingsUpdate.relayConstraints(RelayConstraints()).apply(to: ¤tSettings) | ||
|
||
var updatedSettings = currentSettings | ||
TunnelSettingsUpdate.relayConstraints(RelayConstraints( | ||
exitLocations: .only(UserSelectedRelays(locations: [.country("zz")])), | ||
port: .only(9999), | ||
filter: .only(.init(ownership: .rented, providers: .only(["foo", "bar"]))) | ||
)).apply(to: &updatedSettings) | ||
|
||
let tunnelSettingsStrategy = TunnelSettingsStrategy() | ||
XCTAssertTrue(tunnelSettingsStrategy.shouldReconnectToNewRelay( | ||
oldSettings: currentSettings, | ||
newSettings: updatedSettings | ||
)) | ||
} | ||
|
||
func connectToCurrentRelayOnDNSSettingsChangeTest() { | ||
let currentSettings = LatestTunnelSettings() | ||
|
||
var updatedSettings = currentSettings | ||
var dnsSettings = DNSSettings() | ||
dnsSettings.blockingOptions = [.blockAdvertising, .blockTracking] | ||
dnsSettings.enableCustomDNS = true | ||
TunnelSettingsUpdate.dnsSettings(dnsSettings).apply(to: &updatedSettings) | ||
|
||
let tunnelSettingsStrategy = TunnelSettingsStrategy() | ||
XCTAssertTrue(tunnelSettingsStrategy.shouldReconnectToNewRelay( | ||
oldSettings: currentSettings, | ||
newSettings: updatedSettings | ||
)) | ||
} | ||
|
||
func connectToCurrentRelayOnQuantumResistanceChangesTest() { | ||
var currentSettings = LatestTunnelSettings() | ||
TunnelSettingsUpdate.quantumResistance(.off).apply(to: ¤tSettings) | ||
|
||
var updatedSettings = currentSettings | ||
TunnelSettingsUpdate.quantumResistance(.on).apply(to: &updatedSettings) | ||
|
||
let tunnelSettingsStrategy = TunnelSettingsStrategy() | ||
XCTAssertTrue(tunnelSettingsStrategy.shouldReconnectToNewRelay( | ||
oldSettings: currentSettings, | ||
newSettings: updatedSettings | ||
)) | ||
} | ||
|
||
func connectToCurrentRelayOnWireGuardObfuscationChangeTest() { | ||
var currentSettings = LatestTunnelSettings() | ||
TunnelSettingsUpdate.obfuscation(WireGuardObfuscationSettings(state: .off, port: .port80)) | ||
.apply(to: ¤tSettings) | ||
|
||
var updatedSettings = currentSettings | ||
TunnelSettingsUpdate.obfuscation(WireGuardObfuscationSettings(state: .automatic, port: .automatic)) | ||
.apply(to: &updatedSettings) | ||
|
||
let tunnelSettingsStrategy = TunnelSettingsStrategy() | ||
XCTAssertTrue(tunnelSettingsStrategy.shouldReconnectToNewRelay( | ||
oldSettings: currentSettings, | ||
newSettings: updatedSettings | ||
)) | ||
} | ||
} |
Oops, something went wrong.