Skip to content

Commit 57089f8

Browse files
committedFeb 26, 2024
Add Mobius framework; define Model/Event/Effect types for TunnelManager, wire applicationBecameActive through Mobius
1 parent 3543421 commit 57089f8

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed
 

‎ios/MullvadVPN.xcodeproj/project.pbxproj

+17
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
06AC116228F94C450037AF9A /* ApplicationConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58BFA5CB22A7CE1F00A6173D /* ApplicationConfiguration.swift */; };
4343
449872E12B7BBC5400094DDC /* TunnelSettingsUpdate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449872E02B7BBC5400094DDC /* TunnelSettingsUpdate.swift */; };
4444
449872E42B7CB96300094DDC /* TunnelSettingsUpdateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 449872E32B7CB96300094DDC /* TunnelSettingsUpdateTests.swift */; };
45+
449872E82B8CC3DF00094DDC /* MobiusCore in Frameworks */ = {isa = PBXBuildFile; productRef = 449872E72B8CC3DF00094DDC /* MobiusCore */; };
4546
44DD7D242B6CFFD70005F67F /* StartTunnelOperationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D232B6CFFD70005F67F /* StartTunnelOperationTests.swift */; };
4647
44DD7D272B6D18FB0005F67F /* MockTunnelInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D262B6D18FB0005F67F /* MockTunnelInteractor.swift */; };
4748
44DD7D292B7113CA0005F67F /* MockTunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44DD7D282B7113CA0005F67F /* MockTunnel.swift */; };
@@ -2065,6 +2066,7 @@
20652066
58D223E6294C8F120029F5F8 /* MullvadTypes.framework in Frameworks */,
20662067
7ABCA5B32A9349F20044A708 /* Routing.framework in Frameworks */,
20672068
58D223CC294C8BCB0029F5F8 /* Operations.framework in Frameworks */,
2069+
449872E82B8CC3DF00094DDC /* MobiusCore in Frameworks */,
20682070
06799AD128F98E1D00ACD94E /* MullvadREST.framework in Frameworks */,
20692071
58B2FDD92AA71D2A003EB5C6 /* MullvadSettings.framework in Frameworks */,
20702072
);
@@ -4036,6 +4038,7 @@
40364038
name = MullvadVPN;
40374039
packageProductDependencies = (
40384040
58F0974D2A20C31100DA2DAD /* WireGuardKitTypes */,
4041+
449872E72B8CC3DF00094DDC /* MobiusCore */,
40394042
);
40404043
productName = MullvadVPN;
40414044
productReference = 58CE5E60224146200008646E /* MullvadVPN.app */;
@@ -4329,6 +4332,7 @@
43294332
packageReferences = (
43304333
585834F624D2BC1F00A8AF56 /* XCRemoteSwiftPackageReference "swift-log" */,
43314334
58F097482A20C30000DA2DAD /* XCRemoteSwiftPackageReference "wireguard-apple" */,
4335+
449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */,
43324336
);
43334337
productRefGroup = 58CE5E61224146200008646E /* Products */;
43344338
projectDirPath = "";
@@ -8276,6 +8280,14 @@
82768280
/* End XCConfigurationList section */
82778281

82788282
/* Begin XCRemoteSwiftPackageReference section */
8283+
449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */ = {
8284+
isa = XCRemoteSwiftPackageReference;
8285+
repositoryURL = "https://github.com/spotify/Mobius.swift";
8286+
requirement = {
8287+
kind = upToNextMajorVersion;
8288+
minimumVersion = 0.5.2;
8289+
};
8290+
};
82798291
585834F624D2BC1F00A8AF56 /* XCRemoteSwiftPackageReference "swift-log" */ = {
82808292
isa = XCRemoteSwiftPackageReference;
82818293
repositoryURL = "https://github.com/apple/swift-log.git";
@@ -8295,6 +8307,11 @@
82958307
/* End XCRemoteSwiftPackageReference section */
82968308

82978309
/* Begin XCSwiftPackageProductDependency section */
8310+
449872E72B8CC3DF00094DDC /* MobiusCore */ = {
8311+
isa = XCSwiftPackageProductDependency;
8312+
package = 449872E62B8CC3DF00094DDC /* XCRemoteSwiftPackageReference "Mobius" */;
8313+
productName = MobiusCore;
8314+
};
82988315
586A0DD02A20E371006C731C /* WireGuardKitTypes */ = {
82998316
isa = XCSwiftPackageProductDependency;
83008317
package = 58F097482A20C30000DA2DAD /* XCRemoteSwiftPackageReference "wireguard-apple" */;

‎ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

+54
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
{
22
"pins" : [
3+
{
4+
"identity" : "cwlcatchexception",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
7+
"state" : {
8+
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00",
9+
"version" : "2.1.2"
10+
}
11+
},
12+
{
13+
"identity" : "cwlpreconditiontesting",
14+
"kind" : "remoteSourceControl",
15+
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
16+
"state" : {
17+
"revision" : "dc9af4781f2afdd1e68e90f80b8603be73ea7abc",
18+
"version" : "2.2.0"
19+
}
20+
},
21+
{
22+
"identity" : "mobius.swift",
23+
"kind" : "remoteSourceControl",
24+
"location" : "https://github.com/spotify/Mobius.swift",
25+
"state" : {
26+
"revision" : "8606126a33258c290ad1cfbcccd0a7becb3cff52",
27+
"version" : "0.5.2"
28+
}
29+
},
30+
{
31+
"identity" : "nimble",
32+
"kind" : "remoteSourceControl",
33+
"location" : "https://github.com/Quick/Nimble",
34+
"state" : {
35+
"revision" : "1f3bde57bde12f5e7b07909848c071e9b73d6edc",
36+
"version" : "10.0.0"
37+
}
38+
},
39+
{
40+
"identity" : "quick",
41+
"kind" : "remoteSourceControl",
42+
"location" : "https://github.com/Quick/Quick",
43+
"state" : {
44+
"revision" : "f9d519828bb03dfc8125467d8f7b93131951124c",
45+
"version" : "5.0.1"
46+
}
47+
},
48+
{
49+
"identity" : "swift-case-paths",
50+
"kind" : "remoteSourceControl",
51+
"location" : "https://github.com/pointfreeco/swift-case-paths",
52+
"state" : {
53+
"revision" : "bb436421f57269fbcfe7360735985321585a86e5",
54+
"version" : "0.10.1"
55+
}
56+
},
357
{
458
"identity" : "swift-log",
559
"kind" : "remoteSourceControl",

‎ios/MullvadVPN/TunnelManager/TunnelManager.swift

+41-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import Foundation
10+
import MobiusCore
1011
import MullvadLogging
1112
import MullvadREST
1213
import MullvadSettings
@@ -18,6 +19,7 @@ import StoreKit
1819
import UIKit
1920
import WireGuardKitTypes
2021

22+
2123
/// Interval used for periodic polling of tunnel relay status when tunnel is establishing
2224
/// connection.
2325
private let establishingTunnelStatusPollInterval: Duration = .seconds(3)
@@ -76,6 +78,36 @@ final class TunnelManager: StorePaymentObserver {
7678
/// Last processed device check.
7779
private var lastPacketTunnelKeyRotation: Date?
7880

81+
/// Experimental Mobius types
82+
struct Model {
83+
var isRunningPeriodicPrivateKeyRotation = false
84+
}
85+
86+
enum Event {
87+
case applicationBecameActive
88+
}
89+
90+
enum Effect {
91+
case updatePrivateKeyRotationTimer
92+
case startNetworkMonitor
93+
case startTunnel
94+
case stopTunnel
95+
case reconnectTunnel(selectNewRelay: Bool)
96+
case refreshDeviceState
97+
case refreshTunnelStatus
98+
}
99+
100+
private func update(model: Model, event: Event) -> Next<Model, Effect> {
101+
switch event {
102+
case .applicationBecameActive:
103+
return .dispatchEffects([.refreshTunnelStatus, .refreshDeviceState])
104+
}
105+
// .noChange // TODO
106+
}
107+
108+
var effectHandler: EffectRouter<Effect, Event>! = nil
109+
var mobiusLoop: MobiusLoop<Model, Event, Effect>! = nil
110+
79111
// MARK: - Initialization
80112

81113
init(
@@ -97,6 +129,12 @@ final class TunnelManager: StorePaymentObserver {
97129
self.operationQueue.underlyingQueue = internalQueue
98130
self.accessTokenManager = accessTokenManager
99131

132+
effectHandler = EffectRouter<Effect, Event>()
133+
.routeCase(Effect.refreshTunnelStatus).to { self.refreshTunnelStatus() }
134+
.routeCase(Effect.refreshDeviceState).to { self.refreshDeviceState() }
135+
136+
mobiusLoop = Mobius.loop(update: self.update, effectHandler: effectHandler.asConnectable).start(from: .init())
137+
100138
NotificationCenter.default.addObserver(
101139
self,
102140
selector: #selector(applicationDidBecomeActive(_:)),
@@ -759,8 +797,9 @@ final class TunnelManager: StorePaymentObserver {
759797
#if DEBUG
760798
logger.debug("Refresh device state and tunnel status due to application becoming active.")
761799
#endif
762-
refreshTunnelStatus()
763-
refreshDeviceState()
800+
mobiusLoop.dispatchEvent(.applicationBecameActive)
801+
// refreshTunnelStatus()
802+
// refreshDeviceState()
764803
}
765804

766805
private func didUpdateNetworkPath(_ path: Network.NWPath) {

0 commit comments

Comments
 (0)