Commit d3bedfb5 authored by Mygod's avatar Mygod

Wrap DnsException to simplify handling logic

parent fee883d9
......@@ -30,6 +30,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.suspendCancellableCoroutine
import java.io.IOException
import java.net.InetAddress
import java.util.concurrent.Executor
import kotlin.coroutines.resume
......@@ -69,7 +70,7 @@ sealed class DnsResolverCompat {
signal, object : DnsResolver.Callback<Collection<InetAddress>> {
override fun onAnswer(answer: Collection<InetAddress>, rcode: Int) =
cont.resume(answer.toTypedArray())
override fun onError(error: DnsResolver.DnsException) = cont.resumeWithException(error)
override fun onError(error: DnsResolver.DnsException) = cont.resumeWithException(IOException(error))
})
}
}
......
......@@ -20,8 +20,6 @@
package com.github.shadowsocks.net
import android.net.DnsResolver
import android.os.Build
import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.utils.printLog
......@@ -144,9 +142,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
when (e) {
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out")
is CancellationException -> { } // ignore
else -> if (e is IOException || Build.VERSION.SDK_INT >= 29 && e is DnsResolver.DnsException) {
Crashlytics.log(Log.WARN, TAG, e.message)
} else printLog(e)
is IOException -> Crashlytics.log(Log.WARN, TAG, e.message)
else -> printLog(e)
}
ByteBuffer.wrap(prepareDnsResponse(request).apply {
header.rcode = Rcode.SERVFAIL
......
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