From 930f05c984a4bca78f9a6aa98f7de629c5c23486 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sun, 19 May 2019 12:39:20 +0200 Subject: [PATCH] Move OpenVPN timeouts out of Core --- .../Sources/AppExtension/Transport/NETCPInterface.swift | 4 ---- .../Sources/AppExtension/Transport/NEUDPInterface.swift | 4 ---- TunnelKit/Sources/Core/LinkInterface.swift | 6 ------ TunnelKit/Sources/OpenVPN/CoreConfiguration+OpenVPN.swift | 4 ++++ TunnelKit/Sources/OpenVPN/SessionProxy+SessionKey.swift | 4 ++-- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift b/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift index 1039192..395f5f3 100644 --- a/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift +++ b/TunnelKit/Sources/AppExtension/Transport/NETCPInterface.swift @@ -200,10 +200,6 @@ class NETCPLink: LinkInterface { return maxPacketSize } - let negotiationTimeout: TimeInterval = 60.0 - - let hardResetTimeout: TimeInterval = 20.0 - func setReadHandler(queue: DispatchQueue, _ handler: @escaping ([Data]?, Error?) -> Void) { loopReadPackets(queue, Data(), handler) } diff --git a/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift b/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift index 0f500f0..3e99f63 100644 --- a/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift +++ b/TunnelKit/Sources/AppExtension/Transport/NEUDPInterface.swift @@ -202,10 +202,6 @@ class NEUDPLink: LinkInterface { return maxDatagrams } - let negotiationTimeout: TimeInterval = 10.0 - - let hardResetTimeout: TimeInterval = 5.0 - func setReadHandler(queue: DispatchQueue, _ handler: @escaping ([Data]?, Error?) -> Void) { // WARNING: runs in Network.framework queue diff --git a/TunnelKit/Sources/Core/LinkInterface.swift b/TunnelKit/Sources/Core/LinkInterface.swift index 520a00f..e5a5bf2 100644 --- a/TunnelKit/Sources/Core/LinkInterface.swift +++ b/TunnelKit/Sources/Core/LinkInterface.swift @@ -50,10 +50,4 @@ public protocol LinkInterface: IOInterface { /// The number of packets that this interface is able to bufferize. var packetBufferSize: Int { get } - - /// Timeout in seconds for negotiation start. - var negotiationTimeout: TimeInterval { get } - - /// Timeout in seconds for HARD_RESET response. - var hardResetTimeout: TimeInterval { get } } diff --git a/TunnelKit/Sources/OpenVPN/CoreConfiguration+OpenVPN.swift b/TunnelKit/Sources/OpenVPN/CoreConfiguration+OpenVPN.swift index c23467d..0e31a98 100644 --- a/TunnelKit/Sources/OpenVPN/CoreConfiguration+OpenVPN.swift +++ b/TunnelKit/Sources/OpenVPN/CoreConfiguration+OpenVPN.swift @@ -44,7 +44,11 @@ extension CoreConfiguration { // MARK: Session static let usesReplayProtection = true + + static let negotiationTimeout = 30.0 + static let hardResetTimeout = 10.0 + static let tickInterval = 0.2 static let pushRequestInterval = 2.0 diff --git a/TunnelKit/Sources/OpenVPN/SessionProxy+SessionKey.swift b/TunnelKit/Sources/OpenVPN/SessionProxy+SessionKey.swift index 34a852c..2091bee 100644 --- a/TunnelKit/Sources/OpenVPN/SessionProxy+SessionKey.swift +++ b/TunnelKit/Sources/OpenVPN/SessionProxy+SessionKey.swift @@ -85,12 +85,12 @@ extension SessionProxy { // Ruby: Key.hard_reset_timeout func didHardResetTimeOut(link: LinkInterface) -> Bool { - return ((state == .hardReset) && (-startTime.timeIntervalSinceNow > link.hardResetTimeout)) + return ((state == .hardReset) && (-startTime.timeIntervalSinceNow > CoreConfiguration.OpenVPN.hardResetTimeout)) } // Ruby: Key.negotiate_timeout func didNegotiationTimeOut(link: LinkInterface) -> Bool { - let timeout = (softReset ? CoreConfiguration.OpenVPN.softNegotiationTimeout : link.negotiationTimeout) + let timeout = (softReset ? CoreConfiguration.OpenVPN.softNegotiationTimeout : CoreConfiguration.OpenVPN.negotiationTimeout) return ((controlState != .connected) && (-startTime.timeIntervalSinceNow > timeout)) }