Skip to content

Commit

Permalink
Allow relay selector to filter DAITA enabled relays
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Aug 15, 2024
1 parent 08a805d commit 6a8494e
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ios/MullvadREST/Relay/RelaySelectorWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ import MullvadTypes

public final class RelaySelectorWrapper: RelaySelectorProtocol {
let relayCache: RelayCacheProtocol

let tunnelSettingsUpdater: SettingsUpdater
private var tunnelSettings = LatestTunnelSettings()
private var observer: SettingsObserverBlock!

// TODO: Remove, Jon
func setDaita(state: MultihopState) {
daitaState = state
}

deinit {
self.tunnelSettingsUpdater.removeObserver(observer)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"originHash" : "c15149b2d59d9e9c72375f65339c04f41a19943e1117e682df27fc9f943fdc56",
"pins" : [
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "173f567a2dfec11d74588eea82cecea555bdc0bc",
"version" : "1.4.0"
}
},
{
"identity" : "wireguard-apple",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mullvad/wireguard-apple.git",
"state" : {
"revision" : "3c55cc305d30a02f87af5d6228ff416d3901d8dd"
}
}
],
"version" : 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,74 @@ class RelaySelectorWrapperTests: XCTestCase {
let selectedRelays = try wrapper.selectRelays(connectionAttemptCount: 0)
XCTAssertNotNil(selectedRelays.entry)
}

func testCanSelectRelayWithMultihopOnAndDaitaOn() throws {
let wrapper = RelaySelectorWrapper(
relayCache: relayCache,
multihopUpdater: multihopUpdater
)

multihopStateListener.onNewMultihop?(.on)
wrapper.setDaita(state: .on)

let constraints = RelayConstraints(
entryLocations: .only(UserSelectedRelays(locations: [.country("es")])), // Relay with DAITA.
exitLocations: .only(UserSelectedRelays(locations: [.country("us")]))
)

XCTAssertNoThrow(try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0))
}

func testCannotSelectRelayWithMultihopOnAndDaitaOn() throws {
let wrapper = RelaySelectorWrapper(
relayCache: relayCache,
multihopUpdater: multihopUpdater
)

multihopStateListener.onNewMultihop?(.on)
wrapper.setDaita(state: .on)

let constraints = RelayConstraints(
entryLocations: .only(UserSelectedRelays(locations: [.country("se")])), // Relay without DAITA.
exitLocations: .only(UserSelectedRelays(locations: [.country("us")]))
)

XCTAssertThrowsError(try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0))
}

func testCanSelectRelayWithMultihopOffAndDaitaOn() throws {
let wrapper = RelaySelectorWrapper(
relayCache: relayCache,
multihopUpdater: multihopUpdater
)

multihopStateListener.onNewMultihop?(.off)
wrapper.setDaita(state: .on)

let constraints = RelayConstraints(
exitLocations: .only(UserSelectedRelays(locations: [.country("es")])) // Relay with DAITA.
)

let selectedRelays = try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0)
XCTAssertNil(selectedRelays.entry)
}

// If DAITA is enabled and no supported relays are found, we should try to find the nearest
// available relay that supports DAITA and use it as entry in a multihop selection.
func testCanSelectRelayWithMultihopOffAndDaitaOnThroughMultihop() throws {
let wrapper = RelaySelectorWrapper(
relayCache: relayCache,
multihopUpdater: multihopUpdater
)

multihopStateListener.onNewMultihop?(.off)
wrapper.setDaita(state: .on)

let constraints = RelayConstraints(
exitLocations: .only(UserSelectedRelays(locations: [.country("se")])) // Relay without DAITA.
)

let selectedRelays = try wrapper.selectRelays(with: constraints, connectionAttemptCount: 0)
XCTAssertNotNil(selectedRelays.entry)
}
}

0 comments on commit 6a8494e

Please sign in to comment.