Remove unused

This commit is contained in:
arm64v8a 2023-09-10 12:14:04 +09:00
parent 1c7944080e
commit a6062d0aee
13 changed files with 9 additions and 259 deletions

View File

@ -107,19 +107,16 @@ object Key {
const val SERVER_DOWNLOAD_SPEED = "serverDownloadSpeed"
const val SERVER_STREAM_RECEIVE_WINDOW = "serverStreamReceiveWindow"
const val SERVER_CONNECTION_RECEIVE_WINDOW = "serverConnectionReceiveWindow"
const val SERVER_MTU = "serverMTU"
const val SERVER_DISABLE_MTU_DISCOVERY = "serverDisableMtuDiscovery"
const val SERVER_HOP_INTERVAL = "hopInterval"
const val SERVER_PRIVATE_KEY = "serverPrivateKey"
const val SERVER_LOCAL_ADDRESS = "serverLocalAddress"
const val SERVER_INSECURE_CONCURRENCY = "serverInsecureConcurrency"
const val SERVER_UDP_RELAY_MODE = "serverUDPRelayMode"
const val SERVER_CONGESTION_CONTROLLER = "serverCongestionController"
const val SERVER_DISABLE_SNI = "serverDisableSNI"
const val SERVER_REDUCE_RTT = "serverReduceRTT"
const val SERVER_FAST_CONNECT = "serverFastConnect"
const val ROUTE_NAME = "routeName"
const val ROUTE_DOMAIN = "routeDomain"

View File

@ -14,9 +14,6 @@ import io.nekohasekai.sagernet.fmt.naive.NaiveBean
import io.nekohasekai.sagernet.fmt.naive.buildNaiveConfig
import io.nekohasekai.sagernet.fmt.trojan_go.TrojanGoBean
import io.nekohasekai.sagernet.fmt.trojan_go.buildTrojanGoConfig
import io.nekohasekai.sagernet.fmt.tuic.TuicBean
import io.nekohasekai.sagernet.fmt.tuic.buildTuicConfig
import io.nekohasekai.sagernet.fmt.tuic.pluginId
import io.nekohasekai.sagernet.ktx.*
import io.nekohasekai.sagernet.plugin.PluginManager
import kotlinx.coroutines.*
@ -85,19 +82,6 @@ abstract class BoxInstance(
}
}
is TuicBean -> {
initPlugin(bean.pluginId())
pluginConfigs[port] = profile.type to bean.buildTuicConfig(port) {
File(
app.noBackupFilesDir,
"tuic_" + SystemClock.elapsedRealtime() + ".ca"
).apply {
parentFile?.mkdirs()
cacheFiles.add(this)
}
}
}
is NekoBean -> {
// check if plugin binary can be loaded
initPlugin(bean.plgId)
@ -238,23 +222,6 @@ abstract class BoxInstance(
processes.start(commands)
}
bean is TuicBean -> {
val configFile =
File(cacheDir, "tuic_" + SystemClock.elapsedRealtime() + ".json")
configFile.parentFile?.mkdirs()
configFile.writeText(config)
cacheFiles.add(configFile)
val commands = mutableListOf(
initPlugin(bean.pluginId()).path,
"-c",
configFile.absolutePath,
)
processes.start(commands)
}
}
}
}

View File

@ -202,7 +202,6 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var serverDownloadSpeed by profileCacheStore.stringToInt(Key.SERVER_DOWNLOAD_SPEED)
var serverStreamReceiveWindow by profileCacheStore.stringToIntIfExists(Key.SERVER_STREAM_RECEIVE_WINDOW)
var serverConnectionReceiveWindow by profileCacheStore.stringToIntIfExists(Key.SERVER_CONNECTION_RECEIVE_WINDOW)
var serverMTU by profileCacheStore.stringToInt(Key.SERVER_MTU) { 1420 }
var serverDisableMtuDiscovery by profileCacheStore.boolean(Key.SERVER_DISABLE_MTU_DISCOVERY)
var serverHopInterval by profileCacheStore.stringToInt(Key.SERVER_HOP_INTERVAL) { 10 }
@ -216,7 +215,6 @@ object DataStore : OnPreferenceDataStoreChangeListener {
var serverCongestionController by profileCacheStore.string(Key.SERVER_CONGESTION_CONTROLLER)
var serverDisableSNI by profileCacheStore.boolean(Key.SERVER_DISABLE_SNI)
var serverReduceRTT by profileCacheStore.boolean(Key.SERVER_REDUCE_RTT)
var serverFastConnect by profileCacheStore.boolean(Key.SERVER_FAST_CONNECT)
var routeName by profileCacheStore.string(Key.ROUTE_NAME)
var routeDomain by profileCacheStore.string(Key.ROUTE_DOMAIN)

View File

@ -25,7 +25,6 @@ import io.nekohasekai.sagernet.fmt.trojan_go.buildTrojanGoConfig
import io.nekohasekai.sagernet.fmt.trojan_go.toUri
import io.nekohasekai.sagernet.fmt.tuic.TuicBean
import io.nekohasekai.sagernet.fmt.tuic.toUri
import io.nekohasekai.sagernet.fmt.tuic.buildTuicConfig
import io.nekohasekai.sagernet.fmt.v2ray.*
import io.nekohasekai.sagernet.fmt.wireguard.WireGuardBean
import io.nekohasekai.sagernet.ktx.app
@ -280,11 +279,6 @@ data class ProxyEntity(
append("\n\n")
append(bean.buildHysteria1Config(port, null))
}
is TuicBean -> {
append("\n\n")
append(bean.buildTuicConfig(port, null))
}
}
}
}
@ -297,7 +291,6 @@ data class ProxyEntity(
TYPE_TROJAN_GO -> true
TYPE_NAIVE -> true
TYPE_HYSTERIA -> !hysteriaBean!!.canUseSingBox()
TYPE_TUIC -> tuicBean!!.protocolVersion == 4
TYPE_NEKO -> true
else -> false
}

View File

@ -23,7 +23,6 @@ import io.nekohasekai.sagernet.fmt.ssh.SSHBean
import io.nekohasekai.sagernet.fmt.ssh.buildSingBoxOutboundSSHBean
import io.nekohasekai.sagernet.fmt.tuic.TuicBean
import io.nekohasekai.sagernet.fmt.tuic.buildSingBoxOutboundTuicBean
import io.nekohasekai.sagernet.fmt.tuic.pluginId
import io.nekohasekai.sagernet.fmt.v2ray.StandardV2RayBean
import io.nekohasekai.sagernet.fmt.v2ray.buildSingBoxOutboundStandardV2RayBean
import io.nekohasekai.sagernet.fmt.wireguard.WireGuardBean
@ -464,8 +463,7 @@ fun buildConfig(
var needExternal = true
if (index == profileList.lastIndex) {
val pluginId = when (bean) {
is HysteriaBean -> "hysteria-plugin"
is TuicBean -> bean.pluginId()
is HysteriaBean -> if (bean.protocolVersion == 1) "hysteria-plugin" else "hysteria2-plugin"
else -> ""
}
if (Plugins.isUsingMatsuriExe(pluginId)) {

View File

@ -29,26 +29,6 @@ enum class PluginEntry(
downloadLink = "https://github.com/MatsuriDayo/plugins/releases?q=Hysteria"
)
),
TUIC(
"tuic-plugin",
"TUIC(v4)",
"moe.matsuri.exe.tuic",
DownloadSource(
playStore = false,
fdroid = false,
downloadLink = "https://github.com/MatsuriDayo/plugins/releases?q=tuic"
)
),
TUIC5(
"tuic-v5-plugin",
"TUIC(v5)",
"moe.matsuri.exe.tuic5",
DownloadSource(
playStore = false,
fdroid = false,
downloadLink = "https://github.com/MatsuriDayo/plugins/releases?q=tuic"
)
),
;
data class DownloadSource(

View File

@ -1,20 +1,15 @@
package io.nekohasekai.sagernet.fmt.tuic
import io.nekohasekai.sagernet.fmt.LOCALHOST
import io.nekohasekai.sagernet.ktx.*
import io.nekohasekai.sagernet.ktx.linkBuilder
import io.nekohasekai.sagernet.ktx.toLink
import io.nekohasekai.sagernet.ktx.urlSafe
import moe.matsuri.nb4a.SingBoxOptions
import moe.matsuri.nb4a.utils.JavaUtil
import moe.matsuri.nb4a.utils.Util
import moe.matsuri.nb4a.utils.listByLineOrComma
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
fun parseTuic(url: String): TuicBean {
// https://github.com/daeuniverse/dae/discussions/182
var link = url.replace("tuic://", "https://").toHttpUrlOrNull() ?: error(
val link = url.replace("tuic://", "https://").toHttpUrlOrNull() ?: error(
"invalid tuic link $url"
)
return TuicBean().apply {
@ -63,6 +58,7 @@ fun TuicBean.toUri(): String {
}
fun buildSingBoxOutboundTuicBean(bean: TuicBean): SingBoxOptions.Outbound_TUICOptions {
if (bean.protocolVersion == 4) throw Exception("TUIC v4 is no longer supported")
return SingBoxOptions.Outbound_TUICOptions().apply {
type = "tuic"
server = bean.serverAddress
@ -90,120 +86,3 @@ fun buildSingBoxOutboundTuicBean(bean: TuicBean): SingBoxOptions.Outbound_TUICOp
}
}
}
fun TuicBean.pluginId(): String {
return when (protocolVersion) {
5 -> "tuic-v5-plugin"
else -> "tuic-plugin"
}
}
fun TuicBean.buildTuicConfig(port: Int, cacheFile: (() -> File)?): String {
val config = when (protocolVersion) {
5 -> buildTuicConfigV5(port, cacheFile)
else -> buildTuicConfigV4(port, cacheFile)
}.toString()
var gsonMap = mutableMapOf<String, Any>()
gsonMap = JavaUtil.gson.fromJson(config, gsonMap.javaClass)
Util.mergeJSON(customJSON, gsonMap)
return JavaUtil.gson.toJson(gsonMap)
}
fun TuicBean.buildTuicConfigV5(port: Int, cacheFile: (() -> File)?): JSONObject {
return JSONObject().apply {
put("relay", JSONObject().apply {
var disableSNI2 = disableSNI
if (sni.isNotBlank()) { // domain + SNI
put("server", "$sni:$finalPort")
if (finalAddress.isIpAddress()) {
put("ip", finalAddress)
} else {
throw Exception("TUIC must use IP address when you need spoof SNI.")
}
} else if (!serverAddress.isIpAddress()) { // domain
put("server", "$serverAddress:$finalPort")
if (finalAddress.isIpAddress()) {
put("ip", finalAddress)
}
} else { // prue IP server
put("server", "example.com:$finalPort")
put("ip", finalAddress)
disableSNI2 = true
}
put("uuid", uuid)
put("password", token)
if (caText.isNotBlank() && cacheFile != null) {
val caFile = cacheFile()
caFile.writeText(caText)
put("certificates", JSONArray(listOf(caFile.absolutePath)))
}
put("udp_relay_mode", udpRelayMode)
if (alpn.isNotBlank()) {
put("alpn", JSONArray(alpn.listByLineOrComma()))
}
put("congestion_control", congestionController)
put("disable_sni", disableSNI2)
put("zero_rtt_handshake", reduceRTT)
if (allowInsecure) put("allow_insecure", true)
})
put("local", JSONObject().apply {
put("server", "127.0.0.1:$port")
})
put("log_level", "debug")
}
}
fun TuicBean.buildTuicConfigV4(port: Int, cacheFile: (() -> File)?): JSONObject {
return JSONObject().apply {
put("relay", JSONObject().apply {
var disableSNI2 = disableSNI
if (sni.isNotBlank()) { // domain + SNI
put("server", sni)
if (finalAddress.isIpAddress()) {
put("ip", finalAddress)
} else {
throw Exception("TUIC must use IP address when you need spoof SNI.")
}
} else if (!serverAddress.isIpAddress()) { // domain
put("server", serverAddress)
if (finalAddress.isIpAddress()) {
put("ip", finalAddress)
}
} else { // prue IP server
put("server", "example.com")
put("ip", finalAddress)
disableSNI2 = true
}
put("port", finalPort)
put("token", token)
if (caText.isNotBlank() && cacheFile != null) {
val caFile = cacheFile()
caFile.writeText(caText)
put("certificates", JSONArray(listOf(caFile.absolutePath)))
}
put("udp_relay_mode", udpRelayMode)
if (alpn.isNotBlank()) {
put("alpn", JSONArray(alpn.listByLineOrComma()))
}
put("congestion_controller", congestionController)
put("disable_sni", disableSNI2)
put("reduce_rtt", reduceRTT)
put("max_udp_relay_packet_size", mtu)
if (fastConnect) put("fast_connect", true)
if (allowInsecure) put("insecure", true)
})
put("local", JSONObject().apply {
put("ip", LOCALHOST)
put("port", port)
})
put("log_level", "debug")
}
}

View File

@ -71,8 +71,8 @@ object PluginManager {
return null
}
return when (pluginId) {
"tuic-v5-plugin" -> soIfExist("libtuic.so")
"hysteria-plugin" -> soIfExist("libhysteria.so")
"hysteria2-plugin" -> soIfExist("libhysteria2.so")
else -> null
}
}

View File

@ -9,7 +9,6 @@ import io.nekohasekai.sagernet.R
import io.nekohasekai.sagernet.database.DataStore
import io.nekohasekai.sagernet.fmt.tuic.TuicBean
import io.nekohasekai.sagernet.ktx.applyDefaultValues
import moe.matsuri.nb4a.ui.SimpleMenuPreference
class TuicSettingsActivity : ProfileSettingsActivity<TuicBean>() {
@ -19,6 +18,7 @@ class TuicSettingsActivity : ProfileSettingsActivity<TuicBean>() {
DataStore.profileName = name
DataStore.serverAddress = serverAddress
DataStore.serverPort = serverPort
DataStore.serverUsername = uuid
DataStore.serverPassword = token
DataStore.serverALPN = alpn
DataStore.serverCertificates = caText
@ -27,20 +27,14 @@ class TuicSettingsActivity : ProfileSettingsActivity<TuicBean>() {
DataStore.serverDisableSNI = disableSNI
DataStore.serverSNI = sni
DataStore.serverReduceRTT = reduceRTT
DataStore.serverMTU = mtu
//
DataStore.serverFastConnect = fastConnect
DataStore.serverAllowInsecure = allowInsecure
//
DataStore.serverConfig = customJSON
DataStore.protocolVersion = protocolVersion
DataStore.serverUsername = uuid
}
override fun TuicBean.serialize() {
name = DataStore.profileName
serverAddress = DataStore.serverAddress
serverPort = DataStore.serverPort
uuid = DataStore.serverUsername
token = DataStore.serverPassword
alpn = DataStore.serverALPN
caText = DataStore.serverCertificates
@ -49,14 +43,7 @@ class TuicSettingsActivity : ProfileSettingsActivity<TuicBean>() {
disableSNI = DataStore.serverDisableSNI
sni = DataStore.serverSNI
reduceRTT = DataStore.serverReduceRTT
mtu = DataStore.serverMTU
//
fastConnect = DataStore.serverFastConnect
allowInsecure = DataStore.serverAllowInsecure
//
customJSON = DataStore.serverConfig
protocolVersion = DataStore.protocolVersion
uuid = DataStore.serverUsername
}
override fun PreferenceFragmentCompat.createPreferences(
@ -65,26 +52,6 @@ class TuicSettingsActivity : ProfileSettingsActivity<TuicBean>() {
) {
addPreferencesFromResource(R.xml.tuic_preferences)
val uuid = findPreference<EditTextPreference>(Key.SERVER_USERNAME)!!
val mtu = findPreference<EditTextPreference>(Key.SERVER_MTU)!!
val fastConnect = findPreference<SwitchPreference>(Key.SERVER_FAST_CONNECT)!!
fun updateVersion(v: Int) {
if (v == 5) {
uuid.isVisible = true
mtu.isVisible = false
fastConnect.isVisible = false
} else {
uuid.isVisible = false
mtu.isVisible = true
fastConnect.isVisible = true
}
}
findPreference<SimpleMenuPreference>(Key.PROTOCOL_VERSION)!!.setOnPreferenceChangeListener { _, newValue ->
updateVersion(newValue.toString().toIntOrNull() ?: 4)
true
}
updateVersion(DataStore.protocolVersion)
val disableSNI = findPreference<SwitchPreference>(Key.SERVER_DISABLE_SNI)!!
val sni = findPreference<EditTextPreference>(Key.SERVER_SNI)!!
sni.isEnabled = !disableSNI.isChecked

View File

@ -419,13 +419,10 @@
<string name="release_wake_lock">WakeLock را آزاد کنید</string>
<string name="acquire_wake_lock_summary">CPU را روشن نگه دارید</string>
<string name="action_switch">تعویض</string>
<string name="tuic_token">توکن</string>
<string name="tuic_udp_relay_mode">حالت واقعی UDP</string>
<string name="tuic_congestion_controller">کنترل کننده ازدحام</string>
<string name="tuic_disable_sni">SNI را غیرفعال کنید</string>
<string name="tuic_reduce_rtt">UDP کاهش RTT</string>
<string name="tuic_fast_connect">اتصال سریع TCP</string>
<string name="tuic_fast_connect_summary">نیاز به پشتیبانی افزونه و سرور دارد</string>
<string name="please_update">ماتسوری شما خیلی قدیمی است (%s). و در %s کار نخواهد کرد. لطفا به روز رسانی کن!</string>
<string name="please_update_force">ماتسوری شما خیلی قدیمی است (%s). و در %s کار نمی کند. لطفا به روز رسانی کن!</string>
<string name="connection_test_delete_unavailable">پاک کردن در دسترس نیست</string>

View File

@ -446,11 +446,8 @@
<string name="domain_strategy_for_server">域名策略(服务器地址)</string>
<string name="tuic_disable_sni">禁用 SNI</string>
<string name="tuic_reduce_rtt">启用 0-RTT QUIC 握手</string>
<string name="tuic_fast_connect">TCP 快速打开</string>
<string name="tuic_fast_connect_summary">要求插件和服务器支持</string>
<string name="tuic_congestion_controller">拥塞控制</string>
<string name="tuic_udp_relay_mode">UDP 转发模式</string>
<string name="tuic_token">令牌</string>
<string name="menu_dashboard">sing-box 仪表板</string>
<string name="custom_outbound_json">自定义出站 JSON</string>
<string name="custom_config_json">自定义配置 JSON</string>

View File

@ -466,13 +466,10 @@
<string name="acquire_wake_lock_summary">Keep the CPU on</string>
<string name="action_switch">Switch</string>
<string name="tuic_token">Token</string>
<string name="tuic_udp_relay_mode">UDP Relay Mode</string>
<string name="tuic_congestion_controller">Congestion Controller</string>
<string name="tuic_disable_sni">Disable SNI</string>
<string name="tuic_reduce_rtt">Enable 0-RTT QUIC handshake</string>
<string name="tuic_fast_connect">TCP Fast Connect</string>
<string name="tuic_fast_connect_summary">Requires plugin and server support</string>
<string name="please_update">Your APP is too old (%s). And will stop working at %s. Please update!</string>
<string name="please_update_force">Your APP is too old (%s). And has been stopped working at %s. Please update!</string>

View File

@ -6,15 +6,6 @@
app:title="@string/profile_name"
app:useSimpleSummaryProvider="true" />
<moe.matsuri.nb4a.ui.SimpleMenuPreference
app:defaultValue="5"
app:entries="@array/tuic_version"
app:entryValues="@array/tuic_version"
app:icon="@drawable/ic_baseline_update_24"
app:key="protocolVersion"
app:title="@string/protocol_version"
app:useSimpleSummaryProvider="true" />
<PreferenceCategory app:title="@string/proxy_cat">
<EditTextPreference
@ -76,21 +67,10 @@
app:icon="@drawable/baseline_flight_takeoff_24"
app:key="serverReduceRTT"
app:title="@string/tuic_reduce_rtt" />
<SwitchPreference
app:icon="@drawable/baseline_flight_takeoff_24"
app:key="serverFastConnect"
app:summary="@string/tuic_fast_connect_summary"
app:title="@string/tuic_fast_connect" />
<SwitchPreference
app:icon="@drawable/ic_notification_enhanced_encryption"
app:key="serverAllowInsecure"
app:summary="@string/tuic_fast_connect_summary"
app:title="@string/allow_insecure" />
<EditTextPreference
app:icon="@drawable/baseline_public_24"
app:key="serverMTU"
app:title="@string/mtu"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
</PreferenceScreen>