mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 14:40:06 +08:00
improve mux
This commit is contained in:
parent
d4fb7c614c
commit
20375c7560
@ -269,14 +269,17 @@ data class ProxyEntity(
|
||||
append("\n\n")
|
||||
append(bean.buildTrojanGoConfig(port))
|
||||
}
|
||||
|
||||
is NaiveBean -> {
|
||||
append("\n\n")
|
||||
append(bean.buildNaiveConfig(port))
|
||||
}
|
||||
|
||||
is HysteriaBean -> {
|
||||
append("\n\n")
|
||||
append(bean.buildHysteriaConfig(port, null))
|
||||
}
|
||||
|
||||
is TuicBean -> {
|
||||
append("\n\n")
|
||||
append(bean.buildTuicConfig(port, null))
|
||||
@ -299,18 +302,17 @@ data class ProxyEntity(
|
||||
}
|
||||
}
|
||||
|
||||
fun isV2RayNetworkTcp(): Boolean {
|
||||
val bean = requireBean() as StandardV2RayBean
|
||||
return when (bean.type) {
|
||||
"tcp", "ws", "http" -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun needCoreMux(): Boolean {
|
||||
return when (type) {
|
||||
TYPE_VMESS -> isV2RayNetworkTcp() && Protocols.shouldEnableMux("vmess") && !vmessBean!!.isVLESS
|
||||
TYPE_TROJAN -> isV2RayNetworkTcp() && Protocols.shouldEnableMux("trojan")
|
||||
TYPE_VMESS -> if (vmessBean!!.isVLESS) {
|
||||
Protocols.isProfileNeedMux(vmessBean!!) && Protocols.shouldEnableMux("vless")
|
||||
} else {
|
||||
Protocols.isProfileNeedMux(vmessBean!!) && Protocols.shouldEnableMux("vmess")
|
||||
}
|
||||
|
||||
TYPE_TROJAN -> Protocols.isProfileNeedMux(trojanBean!!)
|
||||
&& Protocols.shouldEnableMux("trojan")
|
||||
|
||||
TYPE_SS -> !ssBean!!.sUoT && Protocols.shouldEnableMux("shadowsocks")
|
||||
else -> false
|
||||
}
|
||||
@ -338,62 +340,77 @@ data class ProxyEntity(
|
||||
type = TYPE_SOCKS
|
||||
socksBean = bean
|
||||
}
|
||||
|
||||
is HttpBean -> {
|
||||
type = TYPE_HTTP
|
||||
httpBean = bean
|
||||
}
|
||||
|
||||
is ShadowsocksBean -> {
|
||||
type = TYPE_SS
|
||||
ssBean = bean
|
||||
}
|
||||
|
||||
is VMessBean -> {
|
||||
type = TYPE_VMESS
|
||||
vmessBean = bean
|
||||
}
|
||||
|
||||
is TrojanBean -> {
|
||||
type = TYPE_TROJAN
|
||||
trojanBean = bean
|
||||
}
|
||||
|
||||
is TrojanGoBean -> {
|
||||
type = TYPE_TROJAN_GO
|
||||
trojanGoBean = bean
|
||||
}
|
||||
|
||||
is NaiveBean -> {
|
||||
type = TYPE_NAIVE
|
||||
naiveBean = bean
|
||||
}
|
||||
|
||||
is HysteriaBean -> {
|
||||
type = TYPE_HYSTERIA
|
||||
hysteriaBean = bean
|
||||
}
|
||||
|
||||
is SSHBean -> {
|
||||
type = TYPE_SSH
|
||||
sshBean = bean
|
||||
}
|
||||
|
||||
is WireGuardBean -> {
|
||||
type = TYPE_WG
|
||||
wgBean = bean
|
||||
}
|
||||
|
||||
is TuicBean -> {
|
||||
type = TYPE_TUIC
|
||||
tuicBean = bean
|
||||
}
|
||||
|
||||
is ShadowTLSBean -> {
|
||||
type = TYPE_SHADOWTLS
|
||||
shadowTLSBean = bean
|
||||
}
|
||||
|
||||
is ChainBean -> {
|
||||
type = TYPE_CHAIN
|
||||
chainBean = bean
|
||||
}
|
||||
|
||||
is NekoBean -> {
|
||||
type = TYPE_NEKO
|
||||
nekoBean = bean
|
||||
}
|
||||
|
||||
is ConfigBean -> {
|
||||
type = TYPE_CONFIG
|
||||
configBean = bean
|
||||
}
|
||||
|
||||
else -> error("Undefined type $type")
|
||||
}
|
||||
return this
|
||||
|
||||
@ -5,6 +5,8 @@ import io.nekohasekai.sagernet.R
|
||||
import io.nekohasekai.sagernet.database.DataStore
|
||||
import io.nekohasekai.sagernet.database.ProxyEntity.Companion.TYPE_NEKO
|
||||
import io.nekohasekai.sagernet.fmt.AbstractBean
|
||||
import io.nekohasekai.sagernet.fmt.v2ray.StandardV2RayBean
|
||||
import io.nekohasekai.sagernet.fmt.v2ray.isTLS
|
||||
import io.nekohasekai.sagernet.ktx.app
|
||||
import io.nekohasekai.sagernet.ktx.getColorAttr
|
||||
import moe.matsuri.nb4a.plugin.NekoPluginManager
|
||||
@ -13,13 +15,21 @@ import moe.matsuri.nb4a.plugin.NekoPluginManager
|
||||
object Protocols {
|
||||
// Mux
|
||||
|
||||
fun isProfileNeedMux(bean: StandardV2RayBean): Boolean {
|
||||
return when (bean.type) {
|
||||
"tcp", "ws" -> true
|
||||
"http" -> !bean.isTLS()
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldEnableMux(protocol: String): Boolean {
|
||||
return DataStore.muxProtocols.contains(protocol)
|
||||
}
|
||||
|
||||
fun getCanMuxList(): List<String> {
|
||||
// built-in and support mux
|
||||
// sing-box support ss & vmess & trojan smux
|
||||
// TODO support vless mux in sing-box 1.3.x
|
||||
val list = mutableListOf("vmess", "trojan", "trojan-go", "shadowsocks")
|
||||
|
||||
NekoPluginManager.getProtocols().forEach {
|
||||
@ -73,9 +83,11 @@ object Protocols {
|
||||
msgL.contains("timeout") || msgL.contains("deadline") -> {
|
||||
app.getString(R.string.connection_test_timeout)
|
||||
}
|
||||
|
||||
msgL.contains("refused") || msgL.contains("closed pipe") -> {
|
||||
app.getString(R.string.connection_test_refused)
|
||||
}
|
||||
|
||||
else -> msg
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user