PacketTunnel - server down

I have a question regarding the life cycle of my PacketTunnel extension app -

If im connected to my server, and the server goes down -

Is it possible for the extension to tell the containing app that the tunnel had stopped, and in the same time to set a timer (on the extension) to start the tunnel again ? is the extension is still alive after it called cancelTunnelWithError ?


(Or maybe this is not possible, and I need to set a timer on the containing app to start the extension again?)


Thanks!

This notification will notify you about disconnectinng your connection.

NEVPNConnection class , NEVPNStatusDidChangeNotification

I'm already observing this notification, and I can see when the tunnel is disconnected.
The question is, while i'm disconnected - can I give the extenstion a timer to reestablish the connection ? or the extension is deallocated when disconnected? (so the timer has to be on the containing app and not on the extension)


Also, Im not sure when the extension's deinit function is called


What I want to do, is when the tunnel is closed as the result of an error, to cancel the VPN with cancelTunnelWithError *and* to set a timer at the extension that will try to make a new tunnel in 1 min.

Is it possible?

Accepted Answer

I believe the lifecycle of your NEPacketTunnelProvider instance is completely in the control of the system. Same for the process in which your extension is running. Once you call cancelTunnelWithError: inside your extension and your stopTunnelWithReason:completionHandler: method is called inside your extension, the NEPacketTunnelProvider instance may be deinit'd at any time and the extension process may be terminated/killed at any time. In your containing app, assuming it's running (which you cannot guarantee AFAIK), you could set a timer when the tunnel stops and retry again when the timer expires.


The docs are not exactly verbose, but I think the proper way to handle temporary and short networking issues that cause your tunnel to go down is to use the reasserting property inside your extension. The reasserting property is inherited from NETunnelProvider. So if your tunnel is disconnected because of a networking problem (e.g. the tunnel server severs the connection for any reason), you can set reasserting to true and try to reconnect. You should set a timer in your extension so that you do not try to reassert forever.


If the networking problem that caused your tunnel to disconnect is because the tunnel is unreachable (e.g. look at the currentPath property of NWUDPSession, the connectedPath of NWTCPConnection, or the defaultPath of NEProvider), I think the correct way to proceed is to cancel/stop the tunnel and not to try to reassert any longer.

Thanks, that what i thought but I hoped that maybe there is some way to keep the extension alive for a long time when the server is down.
Anyway, as you said - I can make a timer in my containing app to startTunnelWithOptions again.
But what about the 2 following cases:
1. The server went down, so im starting a timer to startTunnelWithOptions in 15 min, but after I set the timer, the user kills my app ? How can I run the extension then?
2. At the time the server went down - my main app not running at all (already kiiled by the user) ? I won't be able to set a timer.

If the user quits your containing app, then you might be out of luck.


If you're on OS X, one option might be to have a "helper app" that runs at login and monitors the tunnel connection. See Adding Login Items Using the Service Management Framework.

I'm on iOS, but I guess that timer while the app is open will be enough.
Thanks again!

PacketTunnel - server down
 
 
Q