Commit ae951834 authored by Daniel Wolf's avatar Daniel Wolf

Restart VPN if previous run finished cleaning

parent 588c0d57
......@@ -80,7 +80,9 @@ class RetryingVPNTunnelProxy(packetProxy: PacketProxy,
lastCrash = System.currentTimeMillis()
retryCount++
if(retryCount < maxRetries){
runProxyWithRetry(readEnd, writeEnd)
afterCleanup {
runProxyWithRetry(readEnd, writeEnd)
}
}
else {
throw it
......
......@@ -58,12 +58,14 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
private var deviceOutput: FileOutputStream? = null
private var tunnelHandle: TunnelHandle? = null
private var exceptionCallbacks = mutableListOf<(Throwable) -> Unit>()
private var cleanupCallbacks = mutableListOf<() -> Unit>()
private var proxyThread:Thread? = null
private var nonPollableProxyThread:Thread? = null
@Volatile
private var polling = false
var forwardingMode:ForwardingMode = ForwardingMode.MIXED
private var proxyThreadActive:Boolean = false
private var cleanupFinalized:Boolean = false
constructor(packetProxy: PacketProxy,
trafficStats: TrafficStats = TrafficStats(0, 0),
......@@ -96,6 +98,11 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
exceptionCallbacks.add(callback)
}
protected fun afterCleanup(callback:() -> Unit) {
if(cleanupFinalized) callback()
else cleanupCallbacks.add(callback)
}
@Throws(IOException::class, ErrnoException::class)
fun run(tunnel: ParcelFileDescriptor) {
run(tunnel, tunnel)
......@@ -104,6 +111,7 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
open fun run(readEnd: ParcelFileDescriptor, writeEnd: ParcelFileDescriptor) {
shouldRun = true
cleanupFinalized = false
logger?.info("run() called.")
val errorStruct = createErrorPipe()
logger?.info("Creating device polls")
......@@ -272,6 +280,9 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
pipesToClose.clear()
forwardedPacketStore?.clear(proxyStopped)
tunnelHandle?.clear(false)
cleanupFinalized = true
cleanupCallbacks?.forEach { it() }
cleanupCallbacks.clear()
}
@Throws(ErrnoException::class)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment