-
Notifications
You must be signed in to change notification settings - Fork 1.4k
cleanup(client): Clean up Go VPN APIs #2480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,25 +197,24 @@ private synchronized PlatformError startTunnel( | |
| } | ||
| } | ||
|
|
||
| final NewClientResult clientResult = Outline.newClient(config.transportConfig); | ||
| if (clientResult.getError() != null) { | ||
| LOG.log(Level.WARNING, "Failed to create Outline Client", clientResult.getError()); | ||
| final NewRemoteDeviceResult deviceResult = Outline.newRemoteDevice(config.transportConfig); | ||
| if (deviceResult.getError() != null) { | ||
| LOG.log(Level.WARNING, "Failed to create Outline remote IP device", deviceResult.getError()); | ||
| tearDownActiveTunnel(); | ||
| return clientResult.getError(); | ||
| return deviceResult.getError(); | ||
| } | ||
| final outline.Client client = clientResult.getClient(); | ||
| final outline.RemoteDevice remoteDevice = deviceResult.getRemoteDevice(); | ||
|
|
||
| PlatformError udpConnError = null; | ||
| PlatformError deviceConnError = null; | ||
| if (!isAutoStart) { | ||
| try { | ||
| // Do not perform connectivity checks when connecting on startup. We should avoid failing | ||
| // the connection due to a network error, as network may not be ready. | ||
| final TCPAndUDPConnectivityResult connResult = checkServerConnectivity(client); | ||
| if (connResult.getTCPError() != null) { | ||
| deviceConnError = remoteDevice.HasConnectivity(); | ||
| if (deviceConnError != null) { | ||
| tearDownActiveTunnel(); | ||
| return connResult.getTCPError(); | ||
| return deviceConnError; | ||
| } | ||
| udpConnError = connResult.getUDPError(); | ||
| } catch (Exception e) { | ||
| tearDownActiveTunnel(); | ||
| return new PlatformError(Platerrors.InternalError, "failed to check connectivity"); | ||
|
|
@@ -233,10 +232,8 @@ private synchronized PlatformError startTunnel( | |
| startNetworkConnectivityMonitor(); | ||
| } | ||
|
|
||
| final boolean remoteUdpForwardingEnabled = | ||
| isAutoStart ? tunnelStore.isUdpSupported() : udpConnError == null; | ||
| try { | ||
| final PlatformError tunError = vpnTunnel.connectTunnel(client, remoteUdpForwardingEnabled); | ||
| final PlatformError tunError = vpnTunnel.connectTunnel(remoteDevice); | ||
| if (tunError != null) { | ||
| LOG.log(Level.SEVERE, "Failed to connect the tunnel", tunError); | ||
| tearDownActiveTunnel(); | ||
|
|
@@ -249,7 +246,7 @@ private synchronized PlatformError startTunnel( | |
| "failed to connect the tunnel"); | ||
| } | ||
| startForegroundWithNotification(config.name); | ||
| storeActiveTunnel(config, remoteUdpForwardingEnabled); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where we store the UDP connectivity state for resuming a connection. Do we need to store it somewhere in the new arch?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking we should check it again. I don't think it makes sense to save this, since we check on network changes. |
||
| storeActiveTunnel(config); | ||
| return null; | ||
| } | ||
|
|
||
|
|
@@ -279,20 +276,13 @@ private void tearDownActiveTunnel() { | |
| tunnelStore.setTunnelStatus(TunnelStatus.DISCONNECTED); | ||
| } | ||
|
|
||
| /* Helper method that stops the Outline client, tun2socks, and tears down the VPN. */ | ||
| /* Helper method that stops the Outline remote device, and tears down the VPN. */ | ||
| private void stopVpnTunnel() { | ||
| vpnTunnel.disconnectTunnel(); | ||
| vpnTunnel.tearDownVpn(); | ||
| } | ||
|
|
||
| // Connectivity | ||
|
|
||
| private TCPAndUDPConnectivityResult checkServerConnectivity(final outline.Client client) { | ||
| final TCPAndUDPConnectivityResult result = Outline.checkTCPAndUDPConnectivity(client); | ||
| LOG.info(String.format(Locale.ROOT, "Go connectivity check result: %s", result)); | ||
| return result; | ||
| } | ||
|
|
||
| private class NetworkConnectivityMonitor extends ConnectivityManager.NetworkCallback { | ||
| private final ConnectivityManager connectivityManager; | ||
|
|
||
|
|
@@ -320,10 +310,7 @@ public void onAvailable(Network network) { | |
| // `getActiveNetworkInfo` have been observed to return the underlying network set by us. | ||
| setUnderlyingNetworks(new Network[] {network}); | ||
| } | ||
| boolean isUdpSupported = vpnTunnel.updateUDPSupport(); | ||
| LOG.info( | ||
| String.format("UDP support: %s -> %s", tunnelStore.isUdpSupported(), isUdpSupported)); | ||
| tunnelStore.setIsUdpSupported(isUdpSupported); | ||
| vpnTunnel.notifyNetworkChange(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -416,7 +403,7 @@ private void startLastSuccessfulTunnel() { | |
| } | ||
| } | ||
|
|
||
| private void storeActiveTunnel(final TunnelConfig config, boolean isUdpSupported) { | ||
| private void storeActiveTunnel(final TunnelConfig config) { | ||
| LOG.info("Storing active tunnel."); | ||
| JSONObject tunnel = new JSONObject(); | ||
| try { | ||
|
|
@@ -427,7 +414,6 @@ private void storeActiveTunnel(final TunnelConfig config, boolean isUdpSupported | |
| LOG.log(Level.SEVERE, "Failed to store JSON tunnel data", e); | ||
| } | ||
| tunnelStore.setTunnelStatus(TunnelStatus.CONNECTED); | ||
| tunnelStore.setIsUdpSupported(isUdpSupported); | ||
| } | ||
|
|
||
| // Error reporting | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably
TestConnectivitywould be a better name.HasConnectivitysounds like it will return aboolinstead of anError.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.