Use fabric WebSocket dataplane for Android VPN
This commit is contained in:
@@ -30,8 +30,8 @@ android {
|
||||
applicationId "su.cin.rapvpn"
|
||||
minSdk 26
|
||||
targetSdk 35
|
||||
versionCode 187
|
||||
versionName "0.2.187"
|
||||
versionCode 188
|
||||
versionName "0.2.188"
|
||||
buildConfigField "String", "DEFAULT_BACKEND_URL", "\"${normalizeGradleString(defaultBackendUrl)}\""
|
||||
buildConfigField "String", "DEFAULT_CLUSTER_ID", "\"${normalizeGradleString(defaultClusterId)}\""
|
||||
buildConfigField "String", "DEFAULT_ORGANIZATION_ID", "\"${normalizeGradleString(defaultOrganizationId)}\""
|
||||
|
||||
@@ -53,7 +53,7 @@ public class RapVpnService extends VpnService {
|
||||
private static final String PREFS = "rap-vpn-runtime";
|
||||
private static final int DEFAULT_VPN_MTU = 1000;
|
||||
private static final int VPN_TCP_MSS_CLAMP = 900;
|
||||
private static final boolean PACKET_WEBSOCKET_DATAPLANE_ENABLED = false;
|
||||
private static final boolean PACKET_WEBSOCKET_DATAPLANE_ENABLED = true;
|
||||
private static final int VPN_BATCH_MAX_PACKETS = 512;
|
||||
private static final int VPN_BATCH_MAX_BYTES = 1024 * 1024;
|
||||
private static final int UPLINK_WORKER_MAX_COUNT = 1;
|
||||
@@ -603,6 +603,9 @@ public class RapVpnService extends VpnService {
|
||||
FabricServiceChannel channel = FabricServiceChannel.fromLease(serviceChannelLease);
|
||||
if (channel.enabled) {
|
||||
config.fabricServiceChannel = channel;
|
||||
if (!channel.webSocketPathTemplate.isEmpty()) {
|
||||
config.dataplaneSelectedTransport = "fabric_packet_websocket_v1";
|
||||
}
|
||||
config.configNotes.add("Fabric service channel enabled: " + channel.channelId);
|
||||
}
|
||||
}
|
||||
@@ -1040,6 +1043,9 @@ public class RapVpnService extends VpnService {
|
||||
configureBackendBypass(selectedRelayUrl);
|
||||
if (PACKET_WEBSOCKET_DATAPLANE_ENABLED) {
|
||||
startPacketWebSocketRelay(selectedRelayUrl, clusterId, vpnConnectionId);
|
||||
if (activeFabricServiceChannel.enabled) {
|
||||
writeRuntimeDetail("fabric_websocket_dataplane", "fabric websocket packet stream required; HTTP batch fallback disabled", "relay", 0, 0, "", -1);
|
||||
}
|
||||
} else {
|
||||
writeRuntimeDetail("http_packet_batch", "packet websocket disabled; using confirmed HTTP batches", "relay", 0, 0, "", -1);
|
||||
}
|
||||
@@ -2481,6 +2487,18 @@ public class RapVpnService extends VpnService {
|
||||
if (sendUplinkBatchOverWebSocket(relayUrl, clusterId, vpnConnectionId, batch, workerIndex)) {
|
||||
return true;
|
||||
}
|
||||
if (activeFabricServiceChannel.enabled) {
|
||||
for (int attempt = 0; attempt <= UPLINK_TRANSIENT_RETRY_COUNT && running; attempt++) {
|
||||
lastUplinkSendErrorMessage = "fabric websocket packet stream unavailable: " + lastWebSocketRelayError();
|
||||
writeRuntimeDetail("websocket_required_wait", "fabric websocket unavailable; HTTP batch fallback disabled relay=" + relayUrl + " attempt=" + attempt + " error=" + lastUplinkSendErrorMessage, "uplink_sender", -1, -1, "WEBSOCKET_REQUIRED", workerIndex);
|
||||
sleepQuietly(Math.min(UPLINK_TRANSIENT_RETRY_MAX_SLEEP_MS, UPLINK_TRANSIENT_RETRY_SLEEP_MS * (attempt + 1L)));
|
||||
if (sendUplinkBatchOverWebSocket(relayUrl, clusterId, vpnConnectionId, batch, workerIndex)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
switchPacketRelayUrl(relayUrl, "websocket_unavailable");
|
||||
continue;
|
||||
}
|
||||
RapApiClient client = packetRelayClientForUrl(relayUrl);
|
||||
int attempt = 0;
|
||||
while (running) {
|
||||
@@ -2516,6 +2534,21 @@ public class RapVpnService extends VpnService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private String lastWebSocketRelayError() {
|
||||
VpnPacketWebSocketRelay relay = packetWebSocketRelay;
|
||||
if (relay == null) {
|
||||
return "relay_not_started";
|
||||
}
|
||||
String error = relay.lastError();
|
||||
if (error == null || error.isEmpty()) {
|
||||
if (relay.isOpen()) {
|
||||
return "open_no_error";
|
||||
}
|
||||
return "not_open";
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
private boolean isTransientUplinkSendError(Exception e) {
|
||||
String message = e == null ? null : e.getMessage();
|
||||
if (message == null) {
|
||||
@@ -3003,6 +3036,10 @@ public class RapVpnService extends VpnService {
|
||||
}
|
||||
writeRuntimeDetail("websocket_receive_fallback", "websocket receive fallback " + relay.lastError(), "downlink", -1, -1, "WEBSOCKET_RECEIVE", -1);
|
||||
}
|
||||
if (activeFabricServiceChannel.enabled) {
|
||||
writeRuntimeDetail("websocket_receive_required", "fabric websocket unavailable; HTTP batch receive disabled " + lastWebSocketRelayError(), "downlink", -1, -1, "WEBSOCKET_REQUIRED", -1);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return client.receiveClientPacketBatch(clusterId, vpnConnectionId, timeoutMs);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user