diff --git a/mobile/build.gradle b/mobile/build.gradle index ff587789..b013b4a5 100644 --- a/mobile/build.gradle +++ b/mobile/build.gradle @@ -74,7 +74,6 @@ dependencies { implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation "com.takisoft.fix:preference-v7-simplemenu:$takisoftFixVersion" implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.2' - implementation 'dnsjava:dnsjava:2.1.8' implementation 'eu.chainfire:libsuperuser:1.0.0.201704021214' implementation 'net.glxn.qrgen:android:2.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt index 13bb20d8..fbc335b1 100644 --- a/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt +++ b/mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt @@ -50,7 +50,7 @@ import okhttp3.Request import org.json.JSONObject import java.io.File import java.io.IOException -import java.net.UnknownHostException +import java.net.* import java.security.MessageDigest import java.util.* import java.util.concurrent.TimeUnit @@ -364,10 +364,6 @@ object BaseService { try { if (profile.host == "198.199.101.152") { val client = OkHttpClient.Builder() - .dns { - listOf((Dns.resolve(it, false) ?: throw UnknownHostException()) - .parseNumericAddress()) - } .connectTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) @@ -402,7 +398,7 @@ object BaseService { killProcesses() if (!profile.host.isNumericAddress()) - profile.host = Dns.resolve(profile.host, true) ?: throw UnknownHostException() + profile.host = InetAddress.getByName(profile.host).hostAddress ?: throw UnknownHostException() startNativeProcesses() diff --git a/mobile/src/main/java/com/github/shadowsocks/bg/Dns.kt b/mobile/src/main/java/com/github/shadowsocks/bg/Dns.kt deleted file mode 100644 index 9bb52093..00000000 --- a/mobile/src/main/java/com/github/shadowsocks/bg/Dns.kt +++ /dev/null @@ -1,72 +0,0 @@ -/******************************************************************************* - * * - * Copyright (C) 2017 by Max Lv * - * Copyright (C) 2017 by Mygod Studio * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - * * - *******************************************************************************/ - -package com.github.shadowsocks.bg - -import android.util.Log -import com.github.shadowsocks.App.Companion.app -import com.github.shadowsocks.BuildConfig -import org.xbill.DNS.* -import java.io.IOException -import java.net.* - -object Dns { - private const val TAG = "Dns" - - private val hasIPv6Support get() = try { - val result = NetworkInterface.getNetworkInterfaces().asSequence().flatMap { it.inetAddresses.asSequence() } - .any { it is Inet6Address && !it.isLoopbackAddress && !it.isLinkLocalAddress } - if (result && BuildConfig.DEBUG) Log.d(TAG, "IPv6 address detected") - result - } catch (ex: SocketException) { - Log.e(TAG, "Failed to get interfaces' addresses.", ex) - app.track(ex) - false - } - - private fun resolve(host: String, addrType: Int): String? { - try { - val lookup = Lookup(host, addrType) - val resolver = SimpleResolver("208.67.220.220") - resolver.setTCP(true) - resolver.setPort(443) - resolver.setTimeout(5) - lookup.setResolver(resolver) - val records = (lookup.run() ?: return null).toMutableList() - records.shuffle() - for (r in records) { - when (addrType) { - Type.A -> return (r as ARecord).address.hostAddress - Type.AAAA -> return (r as AAAARecord).address.hostAddress - } - } - } catch (_: IOException) { } - return null - } - private fun resolve(host: String): String? = try { - InetAddress.getByName(host).hostAddress - } catch (_: UnknownHostException) { - null - } - fun resolve(host: String, enableIPv6: Boolean): String? = - (if (enableIPv6 && hasIPv6Support) resolve(host, Type.AAAA) else null) - ?: resolve(host, Type.A) - ?: resolve(host) -}