Parcourir la source

Addded seamless VPN handover comments.

Eugene Fryntov il y a 6 ans
Parent
commit
a3dbd69651
1 fichiers modifiés avec 11 ajouts et 0 suppressions
  1. 11 0
      MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

+ 11 - 0
MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java

@@ -194,11 +194,21 @@ public class PsiphonTunnel implements PsiphonProvider {
     // complete VPN and tunnel restart, for example, caused by host app settings change.
     // complete VPN and tunnel restart, for example, caused by host app settings change.
     // Note: same deadlock note as stop().
     // Note: same deadlock note as stop().
     public synchronized void seamlessVpnRestart(VpnService.Builder vpnServiceBuilder) throws Exception {
     public synchronized void seamlessVpnRestart(VpnService.Builder vpnServiceBuilder) throws Exception {
+        // Perform seamless VPN interface swap Psiphon VPN -> dummy VPN
+        //
+        // From https://developer.android.com/reference/android/net/VpnService.Builder.html#establish()
+        // "However, it is rare but not impossible to have two interfaces while performing a seamless handover.
+        // In this case, the old interface will be deactivated when the new one is created successfully. Both
+        // file descriptors are valid but now outgoing packets will be routed to the new interface. Therefore,
+        // after draining the old file descriptor, the application MUST close it and start using the new file
+        // descriptor."
         ParcelFileDescriptor dummyVpnFd = startDummyVpn(vpnServiceBuilder);
         ParcelFileDescriptor dummyVpnFd = startDummyVpn(vpnServiceBuilder);
         try {
         try {
+            // Clean up and restart Psiphon VPN interface, which will also do the swap dummy VPN -> Psiphon VPN
             stopVpn();
             stopVpn();
             startVpn();
             startVpn();
         } finally {
         } finally {
+            // Close dummy VPN file descriptor as per documentation.
             if (dummyVpnFd != null) {
             if (dummyVpnFd != null) {
                 try {
                 try {
                     dummyVpnFd.close();
                     dummyVpnFd.close();
@@ -206,6 +216,7 @@ public class PsiphonTunnel implements PsiphonProvider {
                 }
                 }
             }
             }
         }
         }
+        // Restart the tunnel.
         restartPsiphon();
         restartPsiphon();
     }
     }