Remove unused

This commit is contained in:
arm64v8a 2023-08-28 17:57:51 +09:00
parent fe8248bea8
commit ff52eface2
3 changed files with 1 additions and 85 deletions

View File

@ -199,9 +199,6 @@ class VpnService : BaseVpnService(),
if (Build.VERSION.SDK_INT >= 29) builder.setMetered(metered)
conn = builder.establish() ?: throw NullConnectionException()
// post setup
Libcore.setLocalResolver(LocalResolverImpl)
return conn!!.fd
}
@ -217,7 +214,6 @@ class VpnService : BaseVpnService(),
override fun onRevoke() = stopRunner()
override fun onDestroy() {
Libcore.setLocalResolver(null)
DataStore.vpnService = null
super.onDestroy()
data.binder.close()

View File

@ -6,87 +6,18 @@ import android.os.CancellationSignal
import android.system.ErrnoException
import androidx.annotation.RequiresApi
import io.nekohasekai.sagernet.SagerNet
import io.nekohasekai.sagernet.ktx.tryResume
import io.nekohasekai.sagernet.ktx.tryResumeWithException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
import kotlinx.coroutines.runBlocking
import libcore.ExchangeContext
import libcore.LocalDNSTransport
import libcore.LocalResolver
import java.net.InetAddress
import java.net.UnknownHostException
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
object LocalResolverImpl : LocalResolver, LocalDNSTransport {
// old
override fun lookupIP(network: String, domain: String): String {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
return runBlocking {
suspendCoroutine { continuation ->
val signal = CancellationSignal()
val callback = object : DnsResolver.Callback<Collection<InetAddress>> {
@Suppress("ThrowableNotThrown")
override fun onAnswer(answer: Collection<InetAddress>, rcode: Int) {
// libcore/v2ray.go
when {
answer.isNotEmpty() -> {
continuation.tryResume((answer as Collection<InetAddress?>).mapNotNull { it?.hostAddress }
.joinToString(","))
}
rcode == 0 -> {
// fuck AAAA no record
// features/dns/client.go
continuation.tryResume("")
}
else -> {
// Need return rcode
// proxy/dns/dns.go
continuation.tryResumeWithException(Exception("$rcode"))
}
}
}
override fun onError(error: DnsResolver.DnsException) {
continuation.tryResumeWithException(error)
}
}
val type = when {
network.endsWith("4") -> DnsResolver.TYPE_A
network.endsWith("6") -> DnsResolver.TYPE_AAAA
else -> null
}
if (type != null) {
DnsResolver.getInstance().query(
SagerNet.underlyingNetwork,
domain,
type,
DnsResolver.FLAG_EMPTY,
Dispatchers.IO.asExecutor(),
signal,
callback
)
} else {
DnsResolver.getInstance().query(
SagerNet.underlyingNetwork,
domain,
DnsResolver.FLAG_EMPTY,
Dispatchers.IO.asExecutor(),
signal,
callback
)
}
}
}
} else {
throw Exception("114514")
}
}
object LocalResolverImpl : LocalDNSTransport {
// new local
@ -203,5 +134,4 @@ object LocalResolverImpl : LocalResolver, LocalDNSTransport {
}
}
}

View File

@ -10,16 +10,6 @@ type NB4AInterface interface {
Selector_OnProxySelected(selectorTag string, tag string)
}
type LocalResolver interface {
LookupIP(network string, domain string) (string, error)
}
var localResolver LocalResolver // Android: passed from java (only when VPNService)
func SetLocalResolver(lr LocalResolver) {
localResolver = lr // old "underlyig://0.0.0.0"
}
type BoxPlatformInterface interface {
AutoDetectInterfaceControl(fd int32) error
OpenTun(singTunOptionsJson, tunPlatformOptionsJson string) (int, error)