summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Bulhak <andrew.bulhak@mullvad.net>2024-02-26 15:01:57 +0100
committerAndrew Bulhak <andrew.bulhak@mullvad.net>2024-02-26 15:01:57 +0100
commit57089f84605e3b9b6afd0c38cc49ee70ba2a4100 (patch)
tree9af76e22b007184b3f03aa262504169f51f57e59
parent3543421d7aca91797067d6f22cca30f37a600845 (diff)
downloadmullvadvpn-experiment-reducer-mobius.tar.xz
mullvadvpn-experiment-reducer-mobius.zip
Add Mobius framework; define Model/Event/Effect types for TunnelManager, wire applicationBecameActive through Mobiusexperiment-reducer-mobius
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj17
-rw-r--r--ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved54
-rw-r--r--ios/MullvadVPN/TunnelManager/TunnelManager.swift43
3 files changed, 112 insertions, 2 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index c648222b8f..d0af2b5b91 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -42,6 +42,7 @@
06AC116228F94C450037AF9A /* ApplicationConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */; };
449872E12B7BBC5400094DDC /* TunnelSettingsUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449872E02B7BBC5400094DDC /* TunnelSettingsUpdate.swift */; };
449872E42B7CB96300094DDC /* TunnelSettingsUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449872E32B7CB96300094DDC /* TunnelSettingsUpdateTests.swift */; };
+ 449872E82B8CC3DF00094DDC /* MobiusCore in Frameworks */ = {isa = PBXBuildFile; productRef = 449872E72B8CC3DF00094DDC /* MobiusCore */; };
44DD7D242B6CFFD70005F67F /* StartTunnelOperationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */; };
44DD7D272B6D18FB0005F67F /* MockTunnelInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D262B6D18FB0005F67F /* MockTunnelInteractor.swift */; };
44DD7D292B7113CA0005F67F /* MockTunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D282B7113CA0005F67F /* MockTunnel.swift */; };
@@ -2065,6 +2066,7 @@
58D223E6294C8F120029F5F8 /* MullvadTypes.framework in Frameworks */,
7ABCA5B32A9349F20044A708 /* Routing.framework in Frameworks */,
58D223CC294C8BCB0029F5F8 /* Operations.framework in Frameworks */,
+ 449872E82B8CC3DF00094DDC /* MobiusCore in Frameworks */,
06799AD128F98E1D00ACD94E /* MullvadREST.framework in Frameworks */,
58B2FDD92AA71D2A003EB5C6 /* MullvadSettings.framework in Frameworks */,
);
@@ -4036,6 +4038,7 @@
name = MullvadVPN;
packageProductDependencies = (
58F0974D2A20C31100DA2DAD /* WireGuardKitTypes */,
+ 449872E72B8CC3DF00094DDC /* MobiusCore */,
);
productName = MullvadVPN;
productReference = 58CE5E60224146200008646E /* MullvadVPN.app */;
@@ -4329,6 +4332,7 @@
packageReferences = (
585834F624D2BC1F00A8AF56 /* XCRemoteSwiftPackageReference "swift-log" */,
58F097482A20C30000DA2DAD /* XCRemoteSwiftPackageReference "wireguard-apple" */,
+ 449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */,
);
productRefGroup = 58CE5E61224146200008646E /* Products */;
projectDirPath = "";
@@ -8276,6 +8280,14 @@
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
+ 449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */ = {
+ isa = XCRemoteSwiftPackageReference;
+ repositoryURL = "https://github.com/spotify/Mobius.swift";
+ requirement = {
+ kind = upToNextMajorVersion;
+ minimumVersion = 0.5.2;
+ };
+ };
585834F624D2BC1F00A8AF56 /* XCRemoteSwiftPackageReference "swift-log" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-log.git";
@@ -8295,6 +8307,11 @@
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
+ 449872E72B8CC3DF00094DDC /* MobiusCore */ = {
+ isa = XCSwiftPackageProductDependency;
+ package = 449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */;
+ productName = MobiusCore;
+ };
586A0DD02A20E371006C731C /* WireGuardKitTypes */ = {
isa = XCSwiftPackageProductDependency;
package = 58F097482A20C30000DA2DAD /* XCRemoteSwiftPackageReference "wireguard-apple" */;
diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
index 02691892fe..c637f7d1c5 100644
--- a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
+++ b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
@@ -1,6 +1,60 @@
{
"pins" : [
{
+ "identity" : "cwlcatchexception",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/mattgallagher/CwlCatchException.git",
+ "state" : {
+ "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00",
+ "version" : "2.1.2"
+ }
+ },
+ {
+ "identity" : "cwlpreconditiontesting",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
+ "state" : {
+ "revision" : "dc9af4781f2afdd1e68e90f80b8603be73ea7abc",
+ "version" : "2.2.0"
+ }
+ },
+ {
+ "identity" : "mobius.swift",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/spotify/Mobius.swift",
+ "state" : {
+ "revision" : "8606126a33258c290ad1cfbcccd0a7becb3cff52",
+ "version" : "0.5.2"
+ }
+ },
+ {
+ "identity" : "nimble",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/Quick/Nimble",
+ "state" : {
+ "revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc",
+ "version" : "10.0.0"
+ }
+ },
+ {
+ "identity" : "quick",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/Quick/Quick",
+ "state" : {
+ "revision" : "f9d519828bb03dfc8125467d8f7b93131951124c",
+ "version" : "5.0.1"
+ }
+ },
+ {
+ "identity" : "swift-case-paths",
+ "kind" : "remoteSourceControl",
+ "location" : "https://github.com/pointfreeco/swift-case-paths",
+ "state" : {
+ "revision" : "bb436421f57269fbcfe7360735985321585a86e5",
+ "version" : "0.10.1"
+ }
+ },
+ {
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
diff --git a/ios/MullvadVPN/TunnelManager/TunnelManager.swift b/ios/MullvadVPN/TunnelManager/TunnelManager.swift
index 3f0e69459f..7f9d5797b8 100644
--- a/ios/MullvadVPN/TunnelManager/TunnelManager.swift
+++ b/ios/MullvadVPN/TunnelManager/TunnelManager.swift
@@ -7,6 +7,7 @@
//
import Foundation
+import MobiusCore
import MullvadLogging
import MullvadREST
import MullvadSettings
@@ -18,6 +19,7 @@ import StoreKit
import UIKit
import WireGuardKitTypes
+
/// Interval used for periodic polling of tunnel relay status when tunnel is establishing
/// connection.
private let establishingTunnelStatusPollInterval: Duration = .seconds(3)
@@ -76,6 +78,36 @@ final class TunnelManager: StorePaymentObserver {
/// Last processed device check.
private var lastPacketTunnelKeyRotation: Date?
+ /// Experimental Mobius types
+ struct Model {
+ var isRunningPeriodicPrivateKeyRotation = false
+ }
+
+ enum Event {
+ case applicationBecameActive
+ }
+
+ enum Effect {
+ case updatePrivateKeyRotationTimer
+ case startNetworkMonitor
+ case startTunnel
+ case stopTunnel
+ case reconnectTunnel(selectNewRelay: Bool)
+ case refreshDeviceState
+ case refreshTunnelStatus
+ }
+
+ private func update(model: Model, event: Event) -> Next<Model, Effect> {
+ switch event {
+ case .applicationBecameActive:
+ return .dispatchEffects([.refreshTunnelStatus, .refreshDeviceState])
+ }
+// .noChange // TODO
+ }
+
+ var effectHandler: EffectRouter<Effect, Event>! = nil
+ var mobiusLoop: MobiusLoop<Model, Event, Effect>! = nil
+
// MARK: - Initialization
init(
@@ -97,6 +129,12 @@ final class TunnelManager: StorePaymentObserver {
self.operationQueue.underlyingQueue = internalQueue
self.accessTokenManager = accessTokenManager
+ effectHandler = EffectRouter<Effect, Event>()
+ .routeCase(Effect.refreshTunnelStatus).to { self.refreshTunnelStatus() }
+ .routeCase(Effect.refreshDeviceState).to { self.refreshDeviceState() }
+
+ mobiusLoop = Mobius.loop(update: self.update, effectHandler: effectHandler.asConnectable).start(from: .init())
+
NotificationCenter.default.addObserver(
self,
selector: #selector(applicationDidBecomeActive(_:)),
@@ -759,8 +797,9 @@ final class TunnelManager: StorePaymentObserver {
#if DEBUG
logger.debug("Refresh device state and tunnel status due to application becoming active.")
#endif
- refreshTunnelStatus()
- refreshDeviceState()
+ mobiusLoop.dispatchEvent(.applicationBecameActive)
+// refreshTunnelStatus()
+// refreshDeviceState()
}
private func didUpdateNetworkPath(_ path: Network.NWPath) {