From 8a61ae621da46b7b1cfb355749203d85bb5f5650 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sun, 13 Sep 2020 03:46:06 -0700 Subject: [PATCH] Disable DoH upon failure --- .../java/com/topjohnwu/magisk/di/NetworkingModule.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt index 8168db0ef..4e63e0140 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/NetworkingModule.kt @@ -22,6 +22,7 @@ import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory import java.net.InetAddress +import java.net.UnknownHostException val networkingModule = module { single { createOkHttpClient(get()) } @@ -62,10 +63,16 @@ fun createOkHttpClient(context: Context): OkHttpClient { .resolvePrivateAddresses(true) /* To make PublicSuffixDatabase never used */ .build() + var skipDoH = false builder.dns { hostname -> // Only resolve via DoH for known DNS polluted hostnames - if (hostname == "raw.githubusercontent.com") { - doh.lookup(hostname) + if (!skipDoH && hostname == "raw.githubusercontent.com") { + try { + doh.lookup(hostname) + } catch (e: UnknownHostException) { + skipDoH = true + Dns.SYSTEM.lookup(hostname) + } } else { Dns.SYSTEM.lookup(hostname) }