Skip to content

Commit 6a8494e

Browse files
author
Jon Petersson
committed
Allow relay selector to filter DAITA enabled relays
1 parent 08a805d commit 6a8494e

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

ios/MullvadREST/Relay/RelaySelectorWrapper.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import MullvadTypes
1111

1212
public final class RelaySelectorWrapper: RelaySelectorProtocol {
1313
let relayCache: RelayCacheProtocol
14-
1514
let tunnelSettingsUpdater: SettingsUpdater
1615
private var tunnelSettings = LatestTunnelSettings()
1716
private var observer: SettingsObserverBlock!
1817

18+
// TODO: Remove, Jon
19+
func setDaita(state: MultihopState) {
20+
daitaState = state
21+
}
22+
1923
deinit {
2024
self.tunnelSettingsUpdater.removeObserver(observer)
2125
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"originHash" : "c15149b2d59d9e9c72375f65339c04f41a19943e1117e682df27fc9f943fdc56",
3+
"pins" : [
4+
{
5+
"identity" : "swift-log",
6+
"kind" : "remoteSourceControl",
7+
"location" : "https://github.com/apple/swift-log.git",
8+
"state" : {
9+
"revision" : "173f567a2dfec11d74588eea82cecea555bdc0bc",
10+
"version" : "1.4.0"
11+
}
12+
},
13+
{
14+
"identity" : "wireguard-apple",
15+
"kind" : "remoteSourceControl",
16+
"location" : "https://github.com/mullvad/wireguard-apple.git",
17+
"state" : {
18+
"revision" : "3c55cc305d30a02f87af5d6228ff416d3901d8dd"
19+
}
20+
}
21+
],
22+
"version" : 3
23+
}

ios/MullvadVPNTests/MullvadREST/Relay/RelaySelectorWrapperTests.swift

+70
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,74 @@ class RelaySelectorWrapperTests: XCTestCase {
138138
let selectedRelays = try wrapper.selectRelays(connectionAttemptCount: 0)
139139
XCTAssertNotNil(selectedRelays.entry)
140140
}
141+
142+
func testCanSelectRelayWithMultihopOnAndDaitaOn() throws {
143+
let wrapper = RelaySelectorWrapper(
144+
relayCache: relayCache,
145+
multihopUpdater: multihopUpdater
146+
)
147+
148+
multihopStateListener.onNewMultihop?(.on)
149+
wrapper.setDaita(state: .on)
150+
151+
let constraints = RelayConstraints(
152+
entryLocations: .only(UserSelectedRelays(locations: [.country("es")])), // Relay with DAITA.
153+
exitLocations: .only(UserSelectedRelays(locations: [.country("us")]))
154+
)
155+
156+
XCTAssertNoThrow(try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0))
157+
}
158+
159+
func testCannotSelectRelayWithMultihopOnAndDaitaOn() throws {
160+
let wrapper = RelaySelectorWrapper(
161+
relayCache: relayCache,
162+
multihopUpdater: multihopUpdater
163+
)
164+
165+
multihopStateListener.onNewMultihop?(.on)
166+
wrapper.setDaita(state: .on)
167+
168+
let constraints = RelayConstraints(
169+
entryLocations: .only(UserSelectedRelays(locations: [.country("se")])), // Relay without DAITA.
170+
exitLocations: .only(UserSelectedRelays(locations: [.country("us")]))
171+
)
172+
173+
XCTAssertThrowsError(try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0))
174+
}
175+
176+
func testCanSelectRelayWithMultihopOffAndDaitaOn() throws {
177+
let wrapper = RelaySelectorWrapper(
178+
relayCache: relayCache,
179+
multihopUpdater: multihopUpdater
180+
)
181+
182+
multihopStateListener.onNewMultihop?(.off)
183+
wrapper.setDaita(state: .on)
184+
185+
let constraints = RelayConstraints(
186+
exitLocations: .only(UserSelectedRelays(locations: [.country("es")])) // Relay with DAITA.
187+
)
188+
189+
let selectedRelays = try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0)
190+
XCTAssertNil(selectedRelays.entry)
191+
}
192+
193+
// If DAITA is enabled and no supported relays are found, we should try to find the nearest
194+
// available relay that supports DAITA and use it as entry in a multihop selection.
195+
func testCanSelectRelayWithMultihopOffAndDaitaOnThroughMultihop() throws {
196+
let wrapper = RelaySelectorWrapper(
197+
relayCache: relayCache,
198+
multihopUpdater: multihopUpdater
199+
)
200+
201+
multihopStateListener.onNewMultihop?(.off)
202+
wrapper.setDaita(state: .on)
203+
204+
let constraints = RelayConstraints(
205+
exitLocations: .only(UserSelectedRelays(locations: [.country("se")])) // Relay without DAITA.
206+
)
207+
208+
let selectedRelays = try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0)
209+
XCTAssertNotNil(selectedRelays.entry)
210+
}
141211
}

0 commit comments

Comments
 (0)