@@ -16,7 +16,7 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
16
16
private let tunnelManager : TunnelManager
17
17
private let relayCacheTracker : RelayCacheTracker
18
18
private let customListRepository : CustomListRepositoryProtocol
19
- private var cachedRelays : CachedRelays ?
19
+ private var cachedRelays : LocationRelays ?
20
20
21
21
let navigationController : UINavigationController
22
22
@@ -54,10 +54,16 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
54
54
}
55
55
56
56
func start( ) {
57
+ let startContext : LocationViewControllerWrapper . MultihopContext =
58
+ if case . noRelaysSatisfyingDaitaConstraints = tunnelManager. tunnelStatus. observedState
59
+ . blockedState? . reason { . entry } else { . exit }
60
+
57
61
let locationViewControllerWrapper = LocationViewControllerWrapper (
58
62
customListRepository: customListRepository,
59
63
constraints: tunnelManager. settings. relayConstraints,
60
- multihopEnabled: tunnelManager. settings. tunnelMultihopState. isEnabled
64
+ multihopEnabled: tunnelManager. settings. tunnelMultihopState. isEnabled,
65
+ daitaEnabled: tunnelManager. settings. daita. state. isEnabled,
66
+ startContext: startContext
61
67
)
62
68
locationViewControllerWrapper. delegate = self
63
69
@@ -69,8 +75,13 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
69
75
relayCacheTracker. addObserver ( self )
70
76
71
77
if let cachedRelays = try ? relayCacheTracker. getCachedRelays ( ) {
72
- self . cachedRelays = cachedRelays
73
- locationViewControllerWrapper. setCachedRelays ( cachedRelays, filter: relayFilter)
78
+ let locationRelays = LocationRelays (
79
+ relays: cachedRelays. relays. wireguard. relays,
80
+ locations: cachedRelays. relays. locations
81
+ )
82
+ self . cachedRelays = locationRelays
83
+
84
+ locationViewControllerWrapper. setCachedRelays ( locationRelays, filter: relayFilter)
74
85
}
75
86
76
87
navigationController. pushViewController ( locationViewControllerWrapper, animated: false )
@@ -87,8 +98,14 @@ class LocationCoordinator: Coordinator, Presentable, Presenting {
87
98
)
88
99
89
100
relayFilterCoordinator. didFinish = { [ weak self] coordinator, filter in
90
- if let cachedRelays = self ? . cachedRelays, let filter {
91
- self ? . locationViewControllerWrapper? . setCachedRelays ( cachedRelays, filter: filter)
101
+ guard let self else { return }
102
+
103
+ if var cachedRelays, let filter {
104
+ cachedRelays. relays = cachedRelays. relays. filter { relay in
105
+ RelaySelector . relayMatchesFilter ( relay, filter: filter)
106
+ }
107
+
108
+ locationViewControllerWrapper? . setCachedRelays ( cachedRelays, filter: filter)
92
109
}
93
110
94
111
coordinator. dismiss ( animated: true )
@@ -148,9 +165,13 @@ extension LocationCoordinator: RelayCacheTrackerObserver {
148
165
_ tracker: RelayCacheTracker ,
149
166
didUpdateCachedRelays cachedRelays: CachedRelays
150
167
) {
151
- self . cachedRelays = cachedRelays
168
+ let locationRelays = LocationRelays (
169
+ relays: cachedRelays. relays. wireguard. relays,
170
+ locations: cachedRelays. relays. locations
171
+ )
172
+ self . cachedRelays = locationRelays
152
173
153
- locationViewControllerWrapper? . setCachedRelays ( cachedRelays , filter: relayFilter)
174
+ locationViewControllerWrapper? . setCachedRelays ( locationRelays , filter: relayFilter)
154
175
}
155
176
}
156
177
@@ -178,6 +199,10 @@ extension LocationCoordinator: LocationViewControllerWrapperDelegate {
178
199
relayConstraints. filter = . only( filter)
179
200
180
201
tunnelManager. updateSettings ( [ . relayConstraints( relayConstraints) ] )
202
+
203
+ if let cachedRelays {
204
+ locationViewControllerWrapper? . setCachedRelays ( cachedRelays, filter: filter)
205
+ }
181
206
}
182
207
183
208
func navigateToFilter( ) {
0 commit comments