From 67f669b9f8760fb8932ae83c447ebe671d53cdb2 Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Tue, 22 Oct 2024 10:38:06 +0200 Subject: [PATCH] Remove the concept of opening and closing sockets --- ios/MullvadVPN.xcodeproj/project.pbxproj | 4 ++-- .../xcshareddata/swiftpm/Package.resolved | 3 ++- ios/PacketTunnelCore/Pinger/PingerProtocol.swift | 4 ++-- ios/PacketTunnelCore/Pinger/TunnelPinger.swift | 10 ++-------- ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift | 8 ++++---- ios/PacketTunnelCoreTests/Mocks/PingerMock.swift | 4 ++-- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj index 7fe94e8467cf..437aac0d3340 100644 --- a/ios/MullvadVPN.xcodeproj/project.pbxproj +++ b/ios/MullvadVPN.xcodeproj/project.pbxproj @@ -9251,8 +9251,8 @@ isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/mullvad/wireguard-apple.git"; requirement = { - kind = revision; - revision = afb345188c187dddafae0f9e27c5466be11451c2; + branch = "icmp-socket-always-on"; + kind = branch; }; }; /* End XCRemoteSwiftPackageReference section */ diff --git a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2b8fd8c64f52..a6a820179091 100644 --- a/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ios/MullvadVPN.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -14,7 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mullvad/wireguard-apple.git", "state" : { - "revision" : "afb345188c187dddafae0f9e27c5466be11451c2" + "branch" : "icmp-socket-always-on", + "revision" : "5e051810193e089230529691ea7b8d2244f3a05b" } } ], diff --git a/ios/PacketTunnelCore/Pinger/PingerProtocol.swift b/ios/PacketTunnelCore/Pinger/PingerProtocol.swift index 67c64c14482e..9df8ac50b0ba 100644 --- a/ios/PacketTunnelCore/Pinger/PingerProtocol.swift +++ b/ios/PacketTunnelCore/Pinger/PingerProtocol.swift @@ -32,7 +32,7 @@ public struct PingerSendResult { public protocol PingerProtocol { var onReply: ((PingerReply) -> Void)? { get set } - func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws - func closeSocket() + func startPinging(destAddress: IPv4Address) throws + func stopPinging() func send() throws -> PingerSendResult } diff --git a/ios/PacketTunnelCore/Pinger/TunnelPinger.swift b/ios/PacketTunnelCore/Pinger/TunnelPinger.swift index 47c5d8734ae0..d5ad6a95ac17 100644 --- a/ios/PacketTunnelCore/Pinger/TunnelPinger.swift +++ b/ios/PacketTunnelCore/Pinger/TunnelPinger.swift @@ -31,12 +31,7 @@ public final class TunnelPinger: PingerProtocol { self.logger = Logger(label: "TunnelPinger") } - deinit { - pingProvider.closeICMP() - } - - public func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws { - try pingProvider.openICMP(address: destAddress) + public func startPinging(destAddress: IPv4Address) throws { stateLock.withLock { self.destAddress = destAddress } @@ -64,10 +59,9 @@ public final class TunnelPinger: PingerProtocol { } } - public func closeSocket() { + public func stopPinging() { stateLock.withLock { self.destAddress = nil - pingProvider.closeICMP() } } diff --git a/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift b/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift index e2b3dbd17bfc..dbd8fcbf2f05 100644 --- a/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift +++ b/ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift @@ -298,12 +298,12 @@ public final class TunnelMonitor: TunnelMonitorProtocol { private func startMonitoring() { do { - guard let interfaceName = tunnelDeviceInfo.interfaceName, let probeAddress else { - logger.debug("Failed to obtain utun interface name or probe address.") + guard let probeAddress else { + logger.debug("Failed to obtain probe address.") return } - try pinger.openSocket(bindTo: interfaceName, destAddress: probeAddress) + try pinger.startPinging(destAddress: probeAddress) state.connectionState = .connecting startConnectivityCheckTimer() @@ -314,7 +314,7 @@ public final class TunnelMonitor: TunnelMonitorProtocol { private func stopMonitoring(resetRetryAttempt: Bool) { stopConnectivityCheckTimer() - pinger.closeSocket() + pinger.stopPinging() state.netStats = WgStats() state.lastSeenRx = nil diff --git a/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift b/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift index 0dd16f6f65b3..463acc54b4ba 100644 --- a/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift +++ b/ios/PacketTunnelCoreTests/Mocks/PingerMock.swift @@ -34,14 +34,14 @@ class PingerMock: PingerProtocol { self.decideOutcome = decideOutcome } - func openSocket(bindTo interfaceName: String?, destAddress: IPv4Address) throws { + func startPinging(destAddress: IPv4Address) throws { stateLock.withLock { state.destAddress = destAddress state.isSocketOpen = true } } - func closeSocket() { + func stopPinging() { stateLock.withLock { state.isSocketOpen = false }