From 3d263b21f434429bad034680ad4cbf572ad57230 Mon Sep 17 00:00:00 2001 From: Anh Do Date: Wed, 10 Jan 2024 13:14:35 -0500 Subject: [PATCH] Report path change --- .../Feedback/VPNMetadataCollector.swift | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/DuckDuckGo/Feedback/VPNMetadataCollector.swift b/DuckDuckGo/Feedback/VPNMetadataCollector.swift index 1708c60998..db91dc9b8d 100644 --- a/DuckDuckGo/Feedback/VPNMetadataCollector.swift +++ b/DuckDuckGo/Feedback/VPNMetadataCollector.swift @@ -97,13 +97,16 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector { private let statusObserver: ConnectionStatusObserver private let serverInfoObserver: ConnectionServerInfoObserver private let errorStore: NetworkProtectionTunnelErrorStore + private let healthStore: NetworkProtectionTunnelHealthStore init(statusObserver: ConnectionStatusObserver = ConnectionStatusObserverThroughSession(), serverInfoObserver: ConnectionServerInfoObserver = ConnectionServerInfoObserverThroughSession(), - errorStore: NetworkProtectionTunnelErrorStore = NetworkProtectionTunnelErrorStore()) { + errorStore: NetworkProtectionTunnelErrorStore = NetworkProtectionTunnelErrorStore(), + healthStore: NetworkProtectionTunnelHealthStore = NetworkProtectionTunnelHealthStore()) { self.statusObserver = statusObserver self.serverInfoObserver = serverInfoObserver self.errorStore = errorStore + self.healthStore = healthStore } func collectMetadata() async -> VPNMetadata { @@ -143,17 +146,27 @@ final class DefaultVPNMetadataCollector: VPNMetadataCollector { var path: Network.NWPath? let startTime = CFAbsoluteTimeGetCurrent() + let dateFormatter = DateFormatter() + dateFormatter.calendar = Calendar.current + dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + while true { if !monitor.currentPath.availableInterfaces.isEmpty { path = monitor.currentPath + healthStore.updateNetworkPath(path, updatesTimestamp: false) monitor.cancel() - return .init(currentPath: path.debugDescription, lastPathChangeDate: "none", lastPathChange: "none") + return .init(currentPath: path.debugDescription, + lastPathChangeDate: dateFormatter.string(from: healthStore.lastNetworkPathChangeDate), + lastPathChange: healthStore.lastNetworkPathChange) } // Wait up to 3 seconds to fetch the path. let currentExecutionTime = CFAbsoluteTimeGetCurrent() - startTime if currentExecutionTime >= 3.0 { - return .init(currentPath: "Timed out fetching path", lastPathChangeDate: "none", lastPathChange: "none") + return .init(currentPath: "Timed out fetching path", + lastPathChangeDate: dateFormatter.string(from: healthStore.lastNetworkPathChangeDate), + lastPathChange: healthStore.lastNetworkPathChange) } } }