Commit 28193596 authored by Mygod's avatar Mygod Committed by Max Lv

Fix local_dns_path blocking

parent 347d00fb
...@@ -94,32 +94,29 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -94,32 +94,29 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
launch { launch {
socket.use { socket.use {
val input = DataInputStream(socket.inputStream) val input = DataInputStream(socket.inputStream)
while (true) { val query = ByteArray(input.readUnsignedShort())
val length = try { input.read(query)
input.readUnsignedShort() try {
} catch (_: EOFException) { DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query)
break } catch (e: Exception) {
when (e) {
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out")
is CancellationException -> { } // ignore
is IOException -> Crashlytics.log(Log.WARN, name, e.message)
else -> printLog(e)
} }
val query = ByteArray(length)
input.read(query)
try { try {
DnsResolverCompat.resolveRaw(underlyingNetwork ?: throw IOException("no network"), query) LocalDnsServer.prepareDnsResponse(Message(query)).apply {
header.rcode = Rcode.SERVFAIL
}.toWire()
} catch (e: Exception) { } catch (e: Exception) {
when (e) { printLog(e)
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, name, "Resolving timed out") null
is CancellationException -> { } // ignore }
is IOException -> Crashlytics.log(Log.WARN, name, e.message) }?.let { response ->
else -> printLog(e) val output = DataOutputStream(socket.outputStream)
} output.writeShort(response.size)
try { output.write(response)
LocalDnsServer.prepareDnsResponse(Message(query)).apply {
header.rcode = Rcode.SERVFAIL
}.toWire()
} catch (e: Exception) {
printLog(e)
null
}
}?.let { response -> socket.outputStream.write(response) }
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment