From b0997a02b9f4e07d414804386f3fa2c9e64e8573 Mon Sep 17 00:00:00 2001 From: Diego Rey Mendez Date: Fri, 21 Jun 2024 11:37:50 +0200 Subject: [PATCH] Prevent sendProviderMessage calls when not necessary --- .../ConnectionErrorObserverThroughSession.swift | 4 +++- .../ConnectionServerInfoObserverThroughSession.swift | 4 ++++ .../DataVolumeObserver/DataVolumeObserverThroughSession.swift | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/NetworkProtection/Status/ConnectionErrorObserver/ConnectionErrorObserverThroughSession.swift b/Sources/NetworkProtection/Status/ConnectionErrorObserver/ConnectionErrorObserverThroughSession.swift index 6b7c595e0..56c8bb39b 100644 --- a/Sources/NetworkProtection/Status/ConnectionErrorObserver/ConnectionErrorObserverThroughSession.swift +++ b/Sources/NetworkProtection/Status/ConnectionErrorObserver/ConnectionErrorObserverThroughSession.swift @@ -88,7 +88,9 @@ public class ConnectionErrorObserverThroughSession: ConnectionErrorObserver { private func handleStatusChangeNotification(_ notification: Notification) { do { - guard let session = ConnectionSessionUtilities.session(from: notification) else { + guard let session = ConnectionSessionUtilities.session(from: notification), + session.status == .disconnected else { + return } diff --git a/Sources/NetworkProtection/Status/ConnectionServerInfoObserver/ConnectionServerInfoObserverThroughSession.swift b/Sources/NetworkProtection/Status/ConnectionServerInfoObserver/ConnectionServerInfoObserverThroughSession.swift index c03747c04..c34034c8a 100644 --- a/Sources/NetworkProtection/Status/ConnectionServerInfoObserver/ConnectionServerInfoObserverThroughSession.swift +++ b/Sources/NetworkProtection/Status/ConnectionServerInfoObserver/ConnectionServerInfoObserverThroughSession.swift @@ -98,6 +98,10 @@ public class ConnectionServerInfoObserverThroughSession: ConnectionServerInfoObs // MARK: - Obtaining the NetP VPN status private func updateServerInfo(session: NETunnelProviderSession) async { + guard session.status == .connected else { + return + } + let serverAddress = await self.serverAddress(from: session) let serverLocation = await self.serverLocation(from: session) diff --git a/Sources/NetworkProtection/Status/DataVolumeObserver/DataVolumeObserverThroughSession.swift b/Sources/NetworkProtection/Status/DataVolumeObserver/DataVolumeObserverThroughSession.swift index 717c45a09..678497410 100644 --- a/Sources/NetworkProtection/Status/DataVolumeObserver/DataVolumeObserverThroughSession.swift +++ b/Sources/NetworkProtection/Status/DataVolumeObserver/DataVolumeObserverThroughSession.swift @@ -99,7 +99,9 @@ public class DataVolumeObserverThroughSession: DataVolumeObserver { private func updateDataVolume() { Task { - guard let session = await tunnelSessionProvider.activeSession() else { + guard let session = await tunnelSessionProvider.activeSession(), + session.status == .connected else { + return }