Skip to content

Commit

Permalink
Querying the outgoing connection IP should not affect the in IP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Petersson committed Dec 8, 2023
1 parent 6f66168 commit 3115ad0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
}
}
68 changes: 35 additions & 33 deletions ios/MullvadVPN/View controllers/Tunnel/TunnelControlViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

0 comments on commit 3115ad0

Please sign in to comment.