Retry stale Android VPN WebSocket connects
This commit is contained in:
@@ -30,8 +30,8 @@ android {
|
||||
applicationId "su.cin.rapvpn"
|
||||
minSdk 26
|
||||
targetSdk 35
|
||||
versionCode 189
|
||||
versionName "0.2.189"
|
||||
versionCode 190
|
||||
versionName "0.2.190"
|
||||
buildConfigField "String", "DEFAULT_BACKEND_URL", "\"${normalizeGradleString(defaultBackendUrl)}\""
|
||||
buildConfigField "String", "DEFAULT_CLUSTER_ID", "\"${normalizeGradleString(defaultClusterId)}\""
|
||||
buildConfigField "String", "DEFAULT_ORGANIZATION_ID", "\"${normalizeGradleString(defaultOrganizationId)}\""
|
||||
|
||||
@@ -24,6 +24,7 @@ final class VpnPacketWebSocketRelay {
|
||||
private static final int MAX_PACKET_BATCH_PACKETS = 512;
|
||||
private static final int MAX_PACKET_BATCH_BYTES = 1024 * 1024;
|
||||
private static final int MAX_SINGLE_PACKET_BYTES = 65535;
|
||||
private static final long CONNECTING_STALE_MS = 8000;
|
||||
|
||||
private final String baseUrl;
|
||||
private final VpnService vpnService;
|
||||
@@ -37,6 +38,7 @@ final class VpnPacketWebSocketRelay {
|
||||
private String connectedVpnConnectionId = "";
|
||||
private volatile boolean open;
|
||||
private volatile boolean connecting;
|
||||
private volatile long connectingSinceMs;
|
||||
private volatile long reconnectAfterMs;
|
||||
private volatile String lastError = "";
|
||||
|
||||
@@ -87,8 +89,12 @@ final class VpnPacketWebSocketRelay {
|
||||
return;
|
||||
}
|
||||
if (connecting && clusterId.equals(connectedClusterId) && vpnConnectionId.equals(connectedVpnConnectionId)) {
|
||||
if (now - connectingSinceMs < CONNECTING_STALE_MS) {
|
||||
return;
|
||||
}
|
||||
lastError = "stale websocket connect";
|
||||
closeLocked();
|
||||
}
|
||||
if (now < reconnectAfterMs) {
|
||||
return;
|
||||
}
|
||||
@@ -102,6 +108,7 @@ final class VpnPacketWebSocketRelay {
|
||||
connectedClusterId = clusterId;
|
||||
connectedVpnConnectionId = vpnConnectionId;
|
||||
connecting = true;
|
||||
connectingSinceMs = now;
|
||||
Request.Builder requestBuilder = new Request.Builder().url(wsUrl);
|
||||
this.fabricServiceChannel.applyHeaders(requestBuilder);
|
||||
Request request = requestBuilder.build();
|
||||
@@ -147,6 +154,7 @@ final class VpnPacketWebSocketRelay {
|
||||
private void closeLocked() {
|
||||
open = false;
|
||||
connecting = false;
|
||||
connectingSinceMs = 0;
|
||||
incoming.clear();
|
||||
if (webSocket != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user