Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ android {
applicationId = "com.whitedns.vpn"
minSdk = 26
targetSdk = 35
versionCode = 79
versionName = "1.6.4"
versionCode = 80
versionName = "1.6.5"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
resourceConfigurations += listOf("en", "fa")
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/whitedns/vpn/MihomoRuntime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1772,8 +1772,8 @@ class MihomoControllerClient(
val endpoint: String
get() = "core-actions"

fun getProxies(): JSONObject {
return invokeAction("getProxies")
fun getProxies(timeoutMs: Int = CORE_ACTION_TIMEOUT_MS): JSONObject {
return invokeAction("getProxies", timeoutMs = timeoutMs)
.optJSONObject("data")
?: throw IOException("Mihomo core getProxies returned no data")
}
Expand Down
36 changes: 25 additions & 11 deletions app/src/main/java/com/whitedns/vpn/WhiteDnsVpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1952,8 +1952,11 @@ class WhiteDnsVpnService : VpnService() {
?: MihomoSelectionPolicy.mainSelectorGroup(snapshot.summary)?.name
?: throw IOException("Mihomo traffic selector is unavailable")
val preferredSelectorRoots = listOf(selectedName)
suspend fun getStartupProxies(): JSONObject = withContext(Dispatchers.IO) {
controller.getProxies(RUNTIME_HEALTH_TIMEOUT_MS.toInt())
}
var liveProxies = try {
withContext(Dispatchers.IO) { controller.getProxies() }
getStartupProxies()
} catch (error: Throwable) {
if (
shouldRetryOriginalAfterAutomaticBridgeFailure(
Expand Down Expand Up @@ -1984,7 +1987,7 @@ class WhiteDnsVpnService : VpnService() {
"selector=${selection.selectorGroup} selected=${selection.selectedGroup}",
)
}
val updated = withContext(Dispatchers.IO) { controller.getProxies() }
val updated = getStartupProxies()
val verified = MihomoControllerProxies.currentSelections(updated, path)
.associate { it.selectorGroup to it.selectedGroup }
if (path.any { verified[it.selectorGroup] != it.selectedGroup }) {
Expand Down Expand Up @@ -2013,11 +2016,22 @@ class WhiteDnsVpnService : VpnService() {
if (!MihomoControllerProxies.isActiveThrough(liveProxies, selectedName, targetName)) {
throw IOException("Mihomo traffic selector did not resolve through the requested connection")
}
verifyRuntimeHealth(
timeoutMs = RUNTIME_HEALTH_TIMEOUT_MS,
event = "mihomo.proxy.health.explicit",
)
liveProxies = withContext(Dispatchers.IO) { controller.getProxies() }
val explicitDelayMs = explicitProfile
?.takeIf { forcedProxyName == null }
?.let { profile ->
realConnectionDelayMs(
controller = controller,
profile = profile,
timeoutMs = FOREGROUND_MIHOMO_DELAY_TIMEOUT_MS,
)
}
if (explicitDelayMs == null) {
verifyRuntimeHealth(
timeoutMs = RUNTIME_HEALTH_TIMEOUT_MS,
event = "mihomo.proxy.health.explicit",
)
}
liveProxies = getStartupProxies()
if (!MihomoControllerProxies.isActiveThrough(liveProxies, selectedName, targetName)) {
throw IOException("Mihomo traffic route changed before startup completed")
}
Expand Down Expand Up @@ -2060,7 +2074,7 @@ class WhiteDnsVpnService : VpnService() {
},
event = "mihomo.proxy.health.adaptive",
)
liveProxies = withContext(Dispatchers.IO) { controller.getProxies() }
liveProxies = getStartupProxies()
if (!MihomoControllerProxies.isActiveThrough(liveProxies, selectedName, adaptivePlan.groupName)) {
throw IOException("Adaptive traffic route changed before startup completed")
}
Expand Down Expand Up @@ -2116,7 +2130,7 @@ class WhiteDnsVpnService : VpnService() {
"root=$selectedName group=${adaptivePlan.groupName} type=${adaptivePlan.groupType} attempt=$adaptiveAttempt",
error,
)
liveProxies = withContext(Dispatchers.IO) { controller.getProxies() }
liveProxies = getStartupProxies()
if (selectedCountryCode != null) break
}
}
Expand Down Expand Up @@ -2181,7 +2195,7 @@ class WhiteDnsVpnService : VpnService() {
timeoutMs = FALLBACK_RUNTIME_HEALTH_TIMEOUT_MS,
event = "mihomo.proxy.health.fallback",
)
liveProxies = withContext(Dispatchers.IO) { controller.getProxies() }
liveProxies = getStartupProxies()
if (!MihomoControllerProxies.isActiveThrough(liveProxies, selectedName, candidate.tag)) {
throw IOException("Fallback traffic route changed before startup completed")
}
Expand All @@ -2202,7 +2216,7 @@ class WhiteDnsVpnService : VpnService() {
"attempt=${index + 1}/${orderedCandidates.size}",
error,
)
liveProxies = withContext(Dispatchers.IO) { controller.getProxies() }
liveProxies = getStartupProxies()
}
}
if (selectedLeaf == null) {
Expand Down
Loading