Skip to content

Commit

Permalink
Remove unused
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Aug 28, 2023
1 parent fe8248b commit ff52efa
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 85 deletions.
4 changes: 0 additions & 4 deletions app/src/main/java/io/nekohasekai/sagernet/bg/VpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
72 changes: 1 addition & 71 deletions app/src/main/java/moe/matsuri/nb4a/net/LocalResolverImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -203,5 +134,4 @@ object LocalResolverImpl : LocalResolver, LocalDNSTransport {
}
}


}
10 changes: 0 additions & 10 deletions libcore/platform_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff52efa

Please sign in to comment.