Skip to content

Commit

Permalink
apply doamin_strategy for inbounds
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Mar 22, 2023
1 parent 03c99d7 commit 506daa8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions app/src/main/java/io/nekohasekai/sagernet/fmt/ConfigBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ fun buildConfig(
val resolveDestination = DataStore.resolveDestination
val alerts = mutableListOf<Pair<Int, String>>()

fun genDomainStrategy(noAsIs: Boolean): String {
return when {
!resolveDestination && !noAsIs -> ""
ipv6Mode == IPv6Mode.DISABLE -> "ipv4_only"
ipv6Mode == IPv6Mode.PREFER -> "prefer_ipv6"
ipv6Mode == IPv6Mode.ONLY -> "ipv6_only"
else -> "prefer_ipv4"
}
}

return MyOptions().apply {
if (!forTest && DataStore.enableClashAPI) experimental = ExperimentalOptions().apply {
clash_api = ClashAPIOptions().apply {
Expand Down Expand Up @@ -206,6 +216,7 @@ fun buildConfig(
stack = if (DataStore.tunImplementation == 1) "system" else "gvisor"
sniff = needSniff
endpoint_independent_nat = true
domain_strategy = genDomainStrategy(false)
when (ipv6Mode) {
IPv6Mode.DISABLE -> {
inet4_address = listOf(VpnService.PRIVATE_VLAN4_CLIENT + "/28")
Expand All @@ -224,6 +235,7 @@ fun buildConfig(
tag = TAG_MIXED
listen = bind
listen_port = DataStore.mixedPort
domain_strategy = genDomainStrategy(false)
if (needSniff) {
sniff = true
// destOverride = when {
Expand All @@ -245,6 +257,7 @@ fun buildConfig(
listen = bind
listen_port = DataStore.transproxyPort
sniff = needSniff
domain_strategy = genDomainStrategy(false)
})
} else {
inbounds.add(Inbound_RedirectOptions().apply {
Expand All @@ -253,6 +266,7 @@ fun buildConfig(
listen = bind
listen_port = DataStore.transproxyPort
sniff = needSniff
domain_strategy = genDomainStrategy(false)
})
}
}
Expand Down Expand Up @@ -288,16 +302,6 @@ fun buildConfig(
val chainTag = "c-$chainId"
var muxApplied = false

fun genDomainStrategy(noAsIs: Boolean): String {
return when {
!resolveDestination && !noAsIs -> ""
ipv6Mode == IPv6Mode.DISABLE -> "ipv4_only"
ipv6Mode == IPv6Mode.PREFER -> "prefer_ipv6"
ipv6Mode == IPv6Mode.ONLY -> "ipv6_only"
else -> "prefer_ipv4"
}
}

var currentDomainStrategy = genDomainStrategy(false)

profileList.forEachIndexed { index, proxyEntity ->
Expand Down

0 comments on commit 506daa8

Please sign in to comment.