Skip to content

Commit

Permalink
Remove the concept of opening and closing sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Oct 31, 2024
1 parent 1eb6eb3 commit 67f669b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 19 deletions.
4 changes: 2 additions & 2 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mullvad/wireguard-apple.git",
"state" : {
"revision" : "afb345188c187dddafae0f9e27c5466be11451c2"
"branch" : "icmp-socket-always-on",
"revision" : "5e051810193e089230529691ea7b8d2244f3a05b"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions ios/PacketTunnelCore/Pinger/PingerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 2 additions & 8 deletions ios/PacketTunnelCore/Pinger/TunnelPinger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -64,10 +59,9 @@ public final class TunnelPinger: PingerProtocol {
}
}

public func closeSocket() {
public func stopPinging() {
stateLock.withLock {
self.destAddress = nil
pingProvider.closeICMP()
}
}

Expand Down
8 changes: 4 additions & 4 deletions ios/PacketTunnelCore/TunnelMonitor/TunnelMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ios/PacketTunnelCoreTests/Mocks/PingerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 67f669b

Please sign in to comment.