diff --git a/Library/Sources/CommonLibrary/Domain/Constants.swift b/Library/Sources/CommonLibrary/Domain/Constants.swift index c203ab58..610c2f6c 100644 --- a/Library/Sources/CommonLibrary/Domain/Constants.swift +++ b/Library/Sources/CommonLibrary/Domain/Constants.swift @@ -101,6 +101,8 @@ public struct Constants: Decodable, Sendable { public let refreshInterval: TimeInterval public let betaReceiptPath: String + + public let eligibilityCheckInterval: TimeInterval } public struct API: Decodable, Sendable { diff --git a/Library/Sources/CommonLibrary/Resources/Constants.json b/Library/Sources/CommonLibrary/Resources/Constants.json index 23d6f6c7..b98a9033 100644 --- a/Library/Sources/CommonLibrary/Resources/Constants.json +++ b/Library/Sources/CommonLibrary/Resources/Constants.json @@ -26,7 +26,8 @@ "tunnel": { "profileTitleFormat": "Passepartout: %@", "refreshInterval": 3.0, - "betaReceiptPath": "beta-receipt" + "betaReceiptPath": "beta-receipt", + "eligibilityCheckInterval": 600.0 }, "api": { "timeoutInterval": 5.0 diff --git a/Passepartout/Tunnel/PacketTunnelProvider.swift b/Passepartout/Tunnel/PacketTunnelProvider.swift index 388b0c59..0957a599 100644 --- a/Passepartout/Tunnel/PacketTunnelProvider.swift +++ b/Passepartout/Tunnel/PacketTunnelProvider.swift @@ -89,17 +89,28 @@ final class PacketTunnelProvider: NEPacketTunnelProvider, @unchecked Sendable { // MARK: - Eligibility -@MainActor private extension PacketTunnelProvider { func checkEligibility(of profile: Profile, environment: TunnelEnvironment) async throws { - await context.iapManager.reloadReceipt() do { - try context.iapManager.verify(profile) + pp_log(.app, .info, "Verify profile") + await context.iapManager.reloadReceipt() + try await context.iapManager.verify(profile) } catch { let error = PassepartoutError(.App.ineligibleProfile) environment.setEnvironmentValue(error.code, forKey: TunnelEnvironmentKeys.lastErrorCode) pp_log(.app, .fault, "Verification failed for profile \(profile.id), shutting down: \(error)") throw error } + + Task { + let interval = Constants.shared.tunnel.eligibilityCheckInterval + pp_log(.app, .info, "Will verify profile again in \(interval) seconds...") + try await Task.sleep(interval: interval) + do { + try await checkEligibility(of: profile, environment: environment) + } catch { + cancelTunnelWithError(error) + } + } } }