Skip to content

Commit 177a3e9

Browse files
improved test country code
1 parent 0139b7c commit 177a3e9

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreConfigManager.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ object CoreConfigManager {
5353
return buildV2rayCustomConfig(configContext)
5454
}
5555
val v2rayConfig = buildUnifiedConfig(configContext)
56-
postProcessForSpeedtest(v2rayConfig)
56+
val primaryResolvedOutbound = configContext.resolvedOutbounds.first()
57+
val isBalancer = primaryResolvedOutbound.resolvedType == CoreResolvedType.POLICYGROUP
58+
val targetTag = if (isBalancer) AppConfig.TAG_BALANCER else AppConfig.TAG_PROXY
59+
postProcessForSpeedtest(v2rayConfig, targetTag, isBalancer)
5760

5861
return toConfigResult(configContext, v2rayConfig)
5962
} catch (e: Exception) {
@@ -376,10 +379,23 @@ object CoreConfigManager {
376379
policyGroupBalancerTags[resolvedOutbound.tag] = balancerTag
377380
}
378381

379-
private fun postProcessForSpeedtest(v2rayConfig: V2rayConfig) {
382+
private fun postProcessForSpeedtest(v2rayConfig: V2rayConfig, targetTag: String, isBalancer: Boolean) {
380383
v2rayConfig.log.loglevel = MmkvManager.decodeSettingsString(AppConfig.PREF_LOGLEVEL) ?: "warning"
381384
v2rayConfig.inbounds.clear()
385+
// Clearing all routing rules also wipes the catch-all rule that routes into the
386+
// balancer for POLICYGROUP profiles. Without it, the core falls back to the first
387+
// outbound in the list (an arbitrary group member), so the tested country code can
388+
// end up not matching the intended server/group. Re-add an explicit catch-all rule
389+
// pointing at the correct target (plain proxy tag, or the balancer tag for groups)
390+
// so the test always goes through the outbound that is actually being tested.
382391
v2rayConfig.routing.rules.clear()
392+
v2rayConfig.routing.rules.add(
393+
V2rayConfig.RoutingBean.RulesBean(
394+
network = "tcp,udp",
395+
outboundTag = if (isBalancer) null else targetTag,
396+
balancerTag = if (isBalancer) targetTag else null,
397+
)
398+
)
383399
v2rayConfig.dns = null
384400
v2rayConfig.fakedns = null
385401
v2rayConfig.stats = null

0 commit comments

Comments
 (0)