Skip to content

Commit 84ba135

Browse files
committed
Add overridden IP to selected relays
1 parent 7c3d859 commit 84ba135

19 files changed

+61
-73
lines changed

ios/MullvadMockData/MullvadREST/RelaySelectorStub.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public final class RelaySelectorStub: RelaySelectorProtocol {
5959
latitude: 0,
6060
longitude: 0
6161
),
62+
isIPOverridden: false,
6263
features: nil
6364
)
6465

ios/MullvadREST/ApiHandlers/ServerRelaysResponse.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ extension REST {
2525
}
2626
}
2727

28-
public struct BridgeRelay: Codable, Equatable, Sendable {
28+
public struct BridgeRelay: Codable, Equatable, Sendable, AnyRelay {
29+
2930
public let hostname: String
3031
public let active: Bool
3132
public let owned: Bool
@@ -35,6 +36,12 @@ extension REST {
3536
public let weight: UInt64
3637
public let includeInCountry: Bool
3738
public var daita: Bool?
39+
public var isIPOverridden: Bool = false
40+
41+
enum CodingKeys: String, CodingKey {
42+
case hostname, active, owned, location, provider,
43+
ipv4AddrIn, weight, includeInCountry, daita
44+
}
3845

3946
public func override(ipv4AddrIn: IPv4Address?) -> Self {
4047
BridgeRelay(
@@ -45,12 +52,13 @@ extension REST {
4552
provider: provider,
4653
ipv4AddrIn: ipv4AddrIn ?? self.ipv4AddrIn,
4754
weight: weight,
48-
includeInCountry: includeInCountry
55+
includeInCountry: includeInCountry,
56+
isIPOverridden: true
4957
)
5058
}
5159
}
5260

53-
public struct ServerRelay: Codable, Equatable, Sendable {
61+
public struct ServerRelay: Codable, Equatable, Sendable, AnyRelay {
5462
public struct Features: Codable, Equatable, Sendable {
5563
public struct DAITA: Codable, Equatable, Sendable {
5664
// this structure intentionally left blank
@@ -79,6 +87,13 @@ extension REST {
7987
public let daita: Bool?
8088
public let shadowsocksExtraAddrIn: [String]?
8189
public let features: Features?
90+
public var isIPOverridden: Bool = false
91+
92+
enum CodingKeys: String, CodingKey {
93+
case hostname, active, owned, location, provider, weight,
94+
ipv4AddrIn, ipv6AddrIn, publicKey, includeInCountry,
95+
daita, shadowsocksExtraAddrIn, features
96+
}
8297

8398
public var supportsQuic: Bool {
8499
!(features?.quic?.addrIn.isEmpty ?? true)
@@ -98,7 +113,8 @@ extension REST {
98113
includeInCountry: includeInCountry,
99114
daita: daita,
100115
shadowsocksExtraAddrIn: shadowsocksExtraAddrIn,
101-
features: features
116+
features: features,
117+
isIPOverridden: true
102118
)
103119
}
104120

@@ -116,7 +132,8 @@ extension REST {
116132
includeInCountry: includeInCountry,
117133
daita: daita,
118134
shadowsocksExtraAddrIn: shadowsocksExtraAddrIn,
119-
features: features
135+
features: features,
136+
isIPOverridden: true
120137
)
121138
}
122139

ios/MullvadREST/Relay/AnyRelay.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ public protocol AnyRelay {
1818
var active: Bool { get }
1919
var includeInCountry: Bool { get }
2020
var daita: Bool? { get }
21-
21+
var isIPOverridden: Bool { get }
2222
func override(ipv4AddrIn: IPv4Address?, ipv6AddrIn: IPv6Address?) -> Self
2323
}
24-
25-
extension REST.ServerRelay: AnyRelay {}
26-
extension REST.BridgeRelay: AnyRelay {
24+
extension REST.BridgeRelay {
2725
public func override(ipv4AddrIn: IPv4Address?, ipv6AddrIn: IPv6Address?) -> REST.BridgeRelay {
2826
override(ipv4AddrIn: ipv4AddrIn)
2927
}

ios/MullvadREST/Relay/RelayPicking/RelayPicking.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ extension RelayPicking {
5454
endpoint: selectedEndpoint,
5555
hostname: match.relay.hostname,
5656
location: match.location,
57+
isIPOverridden: match.relay.isIPOverridden,
5758
features: match.relay.features
5859
)
5960
}

ios/MullvadREST/Relay/RelaySelectorProtocol.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,30 @@ public struct SelectedRelay: Equatable, Codable, Sendable {
3333
/// Relay geo location.
3434
public let location: Location
3535

36+
public let isIPOverridden: Bool
37+
3638
/// Relay features, such as `DAITA` or `QUIC`.
3739
public let features: REST.ServerRelay.Features?
3840

3941
/// Designated initializer.
40-
public init(endpoint: SelectedEndpoint, hostname: String, location: Location, features: REST.ServerRelay.Features?)
41-
{
42+
public init(
43+
endpoint: SelectedEndpoint,
44+
hostname: String,
45+
location: Location,
46+
isIPOverridden: Bool,
47+
features: REST.ServerRelay.Features?
48+
) {
4249
self.endpoint = endpoint
4350
self.hostname = hostname
4451
self.location = location
4552
self.features = features
53+
self.isIPOverridden = isIPOverridden
4654
}
4755
}
4856

49-
extension SelectedRelay: CustomDebugStringConvertible {
50-
public var debugDescription: String {
51-
"\(hostname) -> \(endpoint.socketAddress)"
57+
extension SelectedRelay: CustomStringConvertible {
58+
public var description: String {
59+
"\(hostname)(\(endpoint.socketAddress))\(isIPOverridden ? " [IP Overridden]" : "")"
5260
}
5361
}
5462

ios/MullvadVPN/Coordinators/ApplicationCoordinator.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,7 @@ final class ApplicationCoordinator: Coordinator, Presenting, @preconcurrency Roo
536536
private func makeTunnelCoordinator() -> TunnelCoordinator {
537537
let tunnelCoordinator = TunnelCoordinator(
538538
tunnelManager: tunnelManager,
539-
outgoingConnectionService: outgoingConnectionService,
540-
ipOverrideRepository: ipOverrideRepository
539+
outgoingConnectionService: outgoingConnectionService
541540
)
542541

543542
tunnelCoordinator.showSelectLocationPicker = { [weak self] in

ios/MullvadVPN/Coordinators/TunnelCoordinator.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ class TunnelCoordinator: Coordinator, Presenting {
2828

2929
init(
3030
tunnelManager: TunnelManager,
31-
outgoingConnectionService: OutgoingConnectionServiceHandling,
32-
ipOverrideRepository: IPOverrideRepositoryProtocol
31+
outgoingConnectionService: OutgoingConnectionServiceHandling
3332
) {
3433
self.tunnelManager = tunnelManager
3534

3635
let interactor = TunnelViewControllerInteractor(
3736
tunnelManager: tunnelManager,
38-
outgoingConnectionService: outgoingConnectionService,
39-
ipOverrideRepository: ipOverrideRepository
37+
outgoingConnectionService: outgoingConnectionService
4038
)
4139

4240
controller = TunnelViewController(interactor: interactor)

ios/MullvadVPN/TunnelManager/TunnelState.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ enum TunnelState: Equatable, CustomStringConvertible, Sendable {
9999
"""
100100
connecting \(isPostQuantum ? "(PQ) " : ""), \
101101
daita: \(isDaita), \
102-
to \(tunnelRelays.exit.hostname)\
103-
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
102+
to \(tunnelRelays.exit.description)\
103+
\(tunnelRelays.entry.flatMap { " via \($0.description)" } ?? "")
104104
"""
105105
} else {
106106
"connecting\(isPostQuantum ? " (PQ)" : ""), fetching relay"
@@ -109,8 +109,8 @@ enum TunnelState: Equatable, CustomStringConvertible, Sendable {
109109
"""
110110
connected \(isPostQuantum ? "(PQ) " : ""), \
111111
daita: \(isDaita), \
112-
to \(tunnelRelays.exit.hostname)\
113-
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
112+
to \(tunnelRelays.exit.description)\
113+
\(tunnelRelays.entry.flatMap { " via \($0.description)" } ?? "")
114114
"""
115115
case let .disconnecting(actionAfterDisconnect):
116116
"disconnecting and then \(actionAfterDisconnect)"
@@ -120,17 +120,17 @@ enum TunnelState: Equatable, CustomStringConvertible, Sendable {
120120
"""
121121
reconnecting \(isPostQuantum ? "(PQ) " : ""), \
122122
daita: \(isDaita), \
123-
to \(tunnelRelays.exit.hostname)\
124-
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? "")
123+
to \(tunnelRelays.exit.description)\
124+
\(tunnelRelays.entry.flatMap { " via \($0.description)" } ?? "")
125125
"""
126126
case .waitingForConnectivity:
127127
"waiting for connectivity"
128128
case let .error(blockedStateReason):
129129
"error state: \(blockedStateReason)"
130130
case let .negotiatingEphemeralPeer(tunnelRelays, _, isPostQuantum, isDaita):
131131
"""
132-
negotiating key with exit relay: \(tunnelRelays.exit.hostname)\
133-
\(tunnelRelays.entry.flatMap { " via \($0.hostname)" } ?? ""), \
132+
negotiating key with exit relay: \(tunnelRelays.exit.description)\
133+
\(tunnelRelays.entry.flatMap { " via \($0.description)" } ?? ""), \
134134
isPostQuantum: \(isPostQuantum), isDaita: \(isDaita)
135135
"""
136136
}

ios/MullvadVPN/View controllers/Tunnel/ConnectionView/ChipView/ChipContainerView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ struct ChipContainerView<ViewModel>: View where ViewModel: ChipViewModelProtocol
119119
latitude: 1234,
120120
longitude: 1234
121121
),
122+
isIPOverridden: false,
122123
features: nil
123124
),
124125
retryAttempt: 0,

ios/MullvadVPN/View controllers/Tunnel/ConnectionView/ChipView/ChipFeature.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,24 +119,9 @@ struct DNSFeature: ChipFeature {
119119
struct IPOverrideFeature: ChipFeature {
120120
let id: FeatureType = .ipOverrides
121121
let state: TunnelState
122-
let overrides: [IPOverride]
123122

124123
var isEnabled: Bool {
125-
guard
126-
let endpoint = state.relays?.ingress.endpoint
127-
else { return false }
128-
129-
// Check if the socket address matches any override
130-
switch endpoint.socketAddress {
131-
case let .ipv4(ipv4Endpoint):
132-
return overrides.contains { override in
133-
override.ipv4Address.map { $0 == ipv4Endpoint.ip } ?? false
134-
}
135-
case let .ipv6(ipv6Endpoint):
136-
return overrides.contains { override in
137-
override.ipv6Address.map { $0 == ipv6Endpoint.ip } ?? false
138-
}
139-
}
124+
state.relays?.entry?.isIPOverridden ?? state.relays?.exit.isIPOverridden ?? false
140125
}
141126

142127
var name: String {

0 commit comments

Comments
 (0)