diff --git a/ios/MullvadVPN/View controllers/Tunnel/ConnectionPanelView.swift b/ios/MullvadVPN/View controllers/Tunnel/ConnectionPanelView.swift index 31804f74b343..7908906d3b66 100644 --- a/ios/MullvadVPN/View controllers/Tunnel/ConnectionPanelView.swift +++ b/ios/MullvadVPN/View controllers/Tunnel/ConnectionPanelView.swift @@ -124,6 +124,8 @@ class ConnectionPanelView: UIView { private func didChangeDataSource() { inAddressRow.value = dataSource?.inAddress + inAddressRow.alpha = dataSource?.inAddress == nil ? 0 : 1.0 + outAddressRow.value = dataSource?.outAddress outAddressRow.alpha = dataSource?.outAddress == nil ? 0 : 1.0 } diff --git a/ios/MullvadVPN/View controllers/Tunnel/OutgoingConnectionService.swift b/ios/MullvadVPN/View controllers/Tunnel/OutgoingConnectionService.swift index 12ed55c47251..b68b6d527ca6 100644 --- a/ios/MullvadVPN/View controllers/Tunnel/OutgoingConnectionService.swift +++ b/ios/MullvadVPN/View controllers/Tunnel/OutgoingConnectionService.swift @@ -23,7 +23,7 @@ final class OutgoingConnectionService: OutgoingConnectionServiceHandling { func getOutgoingConnectionInfo() async throws -> OutgoingConnectionInfo { let ipv4ConnectionInfo = try await outgoingConnectionProxy.getIPV4(retryStrategy: .default) - let ipv6ConnectionInfo = try await outgoingConnectionProxy.getIPV6(retryStrategy: .noRetry) + let ipv6ConnectionInfo = try? await outgoingConnectionProxy.getIPV6(retryStrategy: .noRetry) return OutgoingConnectionInfo(ipv4: ipv4ConnectionInfo, ipv6: ipv6ConnectionInfo) } } @@ -33,12 +33,17 @@ struct OutgoingConnectionInfo { let ipv4: IPV4ConnectionData /// IPv6 exit connection. - let ipv6: IPV6ConnectionData + let ipv6: IPV6ConnectionData? var outAddress: String? { - let v4 = ipv4.exitIP ? "\(ipv4.ip)" : nil - let v6 = ipv6.exitIP ? "\(ipv6.ip)" : nil - let outAddress = [v4, v6].compactMap { $0 }.joined(separator: "\n") + let ipv4String = ipv4.exitIP ? "\(ipv4.ip)" : nil + + var ipv6String: String? + if let ipv6 = ipv6, ipv6.exitIP { + ipv6String = "\(ipv6.ip)" + } + + let outAddress = [ipv4String, ipv6String].compactMap { $0 }.joined(separator: "\n") return outAddress.isEmpty ? nil : outAddress } } diff --git a/ios/MullvadVPN/View controllers/Tunnel/TunnelControlViewModel.swift b/ios/MullvadVPN/View controllers/Tunnel/TunnelControlViewModel.swift index f1fb518efac0..833583efd389 100644 --- a/ios/MullvadVPN/View controllers/Tunnel/TunnelControlViewModel.swift +++ b/ios/MullvadVPN/View controllers/Tunnel/TunnelControlViewModel.swift @@ -11,60 +11,62 @@ import Foundation struct TunnelControlViewModel { let tunnelStatus: TunnelStatus let secureLabelText: String - let connectionPanel: ConnectionPanelData let enableButtons: Bool let city: String let country: String let connectedRelayName: String + let outgoingConnectionInfo: OutgoingConnectionInfo? + + var connectionPanel: ConnectionPanelData? { + guard let tunnelRelay = tunnelStatus.state.relay else { + return nil + } + + var portAndTransport = "" + if let inPort = tunnelStatus.observedState.connectionState?.remotePort { + let protocolLayer = tunnelStatus.observedState.connectionState?.transportLayer == .tcp ? "TCP" : "UDP" + portAndTransport = ":\(inPort) \(protocolLayer)" + } + + return ConnectionPanelData( + inAddress: "\(tunnelRelay.endpoint.ipv4Relay.ip)\(portAndTransport)", + outAddress: outgoingConnectionInfo?.outAddress + ) + } + + static var empty: Self { + TunnelControlViewModel( + tunnelStatus: TunnelStatus(), + secureLabelText: "", + enableButtons: true, + city: "", + country: "", + connectedRelayName: "", + outgoingConnectionInfo: nil + ) + } func update(status: TunnelStatus) -> TunnelControlViewModel { TunnelControlViewModel( tunnelStatus: status, secureLabelText: secureLabelText, - connectionPanel: connectionPanel, enableButtons: enableButtons, city: city, country: country, - connectedRelayName: connectedRelayName + connectedRelayName: connectedRelayName, + outgoingConnectionInfo: nil ) } func update(outgoingConnectionInfo: OutgoingConnectionInfo) -> TunnelControlViewModel { - let inPort = tunnelStatus.observedState.connectionState?.remotePort ?? 0 - - var connectionPanelData = ConnectionPanelData(inAddress: "") - if let tunnelRelay = tunnelStatus.state.relay { - var protocolLayer = "" - if case let .connected(state) = tunnelStatus.observedState { - protocolLayer = state.transportLayer == .tcp ? "TCP" : "UDP" - } - - connectionPanelData = ConnectionPanelData( - inAddress: "\(tunnelRelay.endpoint.ipv4Relay.ip):\(inPort) \(protocolLayer)", - outAddress: outgoingConnectionInfo.outAddress - ) - } - - return TunnelControlViewModel( + TunnelControlViewModel( tunnelStatus: tunnelStatus, secureLabelText: secureLabelText, - connectionPanel: connectionPanelData, enableButtons: enableButtons, city: city, country: country, - connectedRelayName: connectedRelayName - ) - } - - static var empty: Self { - TunnelControlViewModel( - tunnelStatus: TunnelStatus(), - secureLabelText: "", - connectionPanel: ConnectionPanelData(inAddress: ""), - enableButtons: true, - city: "", - country: "", - connectedRelayName: "" + connectedRelayName: connectedRelayName, + outgoingConnectionInfo: outgoingConnectionInfo ) } }