feat: resolveServer

This commit is contained in:
arm64v8a 2023-06-17 13:32:14 +09:00
parent 5d75cbacd4
commit d81178ce64
7 changed files with 13 additions and 7 deletions

View File

@ -32,6 +32,7 @@ object Key {
const val TRAFFIC_SNIFFING = "trafficSniffing" const val TRAFFIC_SNIFFING = "trafficSniffing"
const val RESOLVE_DESTINATION = "resolveDestination" const val RESOLVE_DESTINATION = "resolveDestination"
const val RESOLVE_SERVER = "resolveServer"
const val BYPASS_LAN = "bypassLan" const val BYPASS_LAN = "bypassLan"
const val BYPASS_LAN_IN_CORE = "bypassLanInCore" const val BYPASS_LAN_IN_CORE = "bypassLanInCore"

View File

@ -84,6 +84,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var trafficSniffing by configurationStore.stringToInt(Key.TRAFFIC_SNIFFING) { 1 } var trafficSniffing by configurationStore.stringToInt(Key.TRAFFIC_SNIFFING) { 1 }
var resolveDestination by configurationStore.boolean(Key.RESOLVE_DESTINATION) var resolveDestination by configurationStore.boolean(Key.RESOLVE_DESTINATION)
var resolveServer by configurationStore.boolean(Key.RESOLVE_SERVER)
// var tcpKeepAliveInterval by configurationStore.stringToInt(Key.TCP_KEEP_ALIVE_INTERVAL) { 15 } // var tcpKeepAliveInterval by configurationStore.stringToInt(Key.TCP_KEEP_ALIVE_INTERVAL) { 15 }
var mtu by configurationStore.stringToInt(Key.MTU) { 9000 } var mtu by configurationStore.stringToInt(Key.MTU) { 9000 }

View File

@ -153,12 +153,11 @@ fun buildConfig(
val externalIndexMap = ArrayList<IndexEntity>() val externalIndexMap = ArrayList<IndexEntity>()
val requireTransproxy = if (forTest) false else DataStore.requireTransproxy val requireTransproxy = if (forTest) false else DataStore.requireTransproxy
val ipv6Mode = if (forTest) IPv6Mode.ENABLE else DataStore.ipv6Mode val ipv6Mode = if (forTest) IPv6Mode.ENABLE else DataStore.ipv6Mode
val resolveDestination = DataStore.resolveDestination
val alerts = mutableListOf<Pair<Int, String>>() val alerts = mutableListOf<Pair<Int, String>>()
fun genDomainStrategy(noAsIs: Boolean): String { fun genDomainStrategy(noAsIs: Boolean): String {
return when { return when {
!resolveDestination && !noAsIs -> "" !noAsIs -> ""
ipv6Mode == IPv6Mode.DISABLE -> "ipv4_only" ipv6Mode == IPv6Mode.DISABLE -> "ipv4_only"
ipv6Mode == IPv6Mode.PREFER -> "prefer_ipv6" ipv6Mode == IPv6Mode.PREFER -> "prefer_ipv6"
ipv6Mode == IPv6Mode.ONLY -> "ipv6_only" ipv6Mode == IPv6Mode.ONLY -> "ipv6_only"
@ -216,7 +215,7 @@ fun buildConfig(
tag = "tun-in" tag = "tun-in"
stack = if (DataStore.tunImplementation == 1) "system" else "gvisor" stack = if (DataStore.tunImplementation == 1) "system" else "gvisor"
endpoint_independent_nat = true endpoint_independent_nat = true
domain_strategy = genDomainStrategy(false) domain_strategy = genDomainStrategy(DataStore.resolveDestination)
sniff = needSniff sniff = needSniff
sniff_override_destination = needSniffOverride sniff_override_destination = needSniffOverride
when (ipv6Mode) { when (ipv6Mode) {
@ -239,7 +238,7 @@ fun buildConfig(
tag = TAG_MIXED tag = TAG_MIXED
listen = bind listen = bind
listen_port = DataStore.mixedPort listen_port = DataStore.mixedPort
domain_strategy = genDomainStrategy(false) domain_strategy = genDomainStrategy(DataStore.resolveDestination)
sniff = needSniff sniff = needSniff
sniff_override_destination = needSniffOverride sniff_override_destination = needSniffOverride
}) })
@ -252,7 +251,6 @@ fun buildConfig(
tag = TAG_TRANS tag = TAG_TRANS
listen = bind listen = bind
listen_port = DataStore.transproxyPort listen_port = DataStore.transproxyPort
domain_strategy = genDomainStrategy(false)
sniff = needSniff sniff = needSniff
sniff_override_destination = needSniffOverride sniff_override_destination = needSniffOverride
}) })
@ -262,7 +260,6 @@ fun buildConfig(
tag = TAG_TRANS tag = TAG_TRANS
listen = bind listen = bind
listen_port = DataStore.transproxyPort listen_port = DataStore.transproxyPort
domain_strategy = genDomainStrategy(false)
sniff = needSniff sniff = needSniff
sniff_override_destination = needSniffOverride sniff_override_destination = needSniffOverride
}) })
@ -300,7 +297,7 @@ fun buildConfig(
val chainTag = "c-$chainId" val chainTag = "c-$chainId"
var muxApplied = false var muxApplied = false
var currentDomainStrategy = genDomainStrategy(false) var currentDomainStrategy = genDomainStrategy(DataStore.resolveServer)
profileList.forEachIndexed { index, proxyEntity -> profileList.forEachIndexed { index, proxyEntity ->
val bean = proxyEntity.requireBean() val bean = proxyEntity.requireBean()

View File

@ -191,6 +191,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
val tunImplementation = findPreference<SimpleMenuPreference>(Key.TUN_IMPLEMENTATION)!! val tunImplementation = findPreference<SimpleMenuPreference>(Key.TUN_IMPLEMENTATION)!!
val resolveDestination = findPreference<SwitchPreference>(Key.RESOLVE_DESTINATION)!! val resolveDestination = findPreference<SwitchPreference>(Key.RESOLVE_DESTINATION)!!
val resolveServer = findPreference<SwitchPreference>(Key.RESOLVE_SERVER)!!
val acquireWakeLock = findPreference<SwitchPreference>(Key.ACQUIRE_WAKE_LOCK)!! val acquireWakeLock = findPreference<SwitchPreference>(Key.ACQUIRE_WAKE_LOCK)!!
val enableClashAPI = findPreference<SwitchPreference>(Key.ENABLE_CLASH_API)!! val enableClashAPI = findPreference<SwitchPreference>(Key.ENABLE_CLASH_API)!!
enableClashAPI.setOnPreferenceChangeListener { _, newValue -> enableClashAPI.setOnPreferenceChangeListener { _, newValue ->
@ -223,6 +224,7 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
transproxyMode.onPreferenceChangeListener = reloadListener transproxyMode.onPreferenceChangeListener = reloadListener
resolveDestination.onPreferenceChangeListener = reloadListener resolveDestination.onPreferenceChangeListener = reloadListener
resolveServer.onPreferenceChangeListener = reloadListener
tunImplementation.onPreferenceChangeListener = reloadListener tunImplementation.onPreferenceChangeListener = reloadListener
acquireWakeLock.onPreferenceChangeListener = reloadListener acquireWakeLock.onPreferenceChangeListener = reloadListener

View File

@ -477,4 +477,5 @@
<string name="mux_type">Mux 协议</string> <string name="mux_type">Mux 协议</string>
<string name="sniff_routing">探测结果用于路由判断</string> <string name="sniff_routing">探测结果用于路由判断</string>
<string name="sniff_override">探测结果用于目标地址</string> <string name="sniff_override">探测结果用于目标地址</string>
<string name="resolve_server">根据 IPv6 策略解析服务器地址</string>
</resources> </resources>

View File

@ -518,5 +518,6 @@ Anyone can write advanced plugins, which can control NekoBox. please download an
<string name="mux_type">Mux protocol</string> <string name="mux_type">Mux protocol</string>
<string name="sniff_routing">Sniff result for routing</string> <string name="sniff_routing">Sniff result for routing</string>
<string name="sniff_override">Sniff result for destination</string> <string name="sniff_override">Sniff result for destination</string>
<string name="resolve_server">Resolve the server address according to the IPv6 policy</string>
</resources> </resources>

View File

@ -116,6 +116,9 @@
app:key="resolveDestination" app:key="resolveDestination"
app:summary="@string/resolve_destination_summary" app:summary="@string/resolve_destination_summary"
app:title="@string/resolve_destination" /> app:title="@string/resolve_destination" />
<SwitchPreference
app:key="resolveServer"
app:title="@string/resolve_server" />
<moe.matsuri.nb4a.ui.SimpleMenuPreference <moe.matsuri.nb4a.ui.SimpleMenuPreference
app:defaultValue="0" app:defaultValue="0"
app:entries="@array/ipv6_mode" app:entries="@array/ipv6_mode"