Unverified Commit 009dcb11 authored by Mygod's avatar Mygod Committed by GitHub

Resolve server name dynamically always (#2731)

Fixes #2722.
parent 7b3e4cec
...@@ -50,7 +50,6 @@ import timber.log.Timber ...@@ -50,7 +50,6 @@ import timber.log.Timber
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.net.URL import java.net.URL
import java.net.UnknownHostException
/** /**
* This object uses WeakMap to simulate the effects of multi-inheritance. * This object uses WeakMap to simulate the effects of multi-inheritance.
...@@ -316,7 +315,6 @@ object BaseService { ...@@ -316,7 +315,6 @@ object BaseService {
listOfNotNull(data.proxy, data.udpFallback).forEach { it.trafficMonitor?.persistStats(it.profile.id) } listOfNotNull(data.proxy, data.udpFallback).forEach { it.trafficMonitor?.persistStats(it.profile.id) }
suspend fun preInit() { } suspend fun preInit() { }
suspend fun resolver(host: String) = DnsResolverCompat.resolveOnActiveNetwork(host)
suspend fun rawResolver(query: ByteArray) = DnsResolverCompat.resolveRawOnActiveNetwork(query) suspend fun rawResolver(query: ByteArray) = DnsResolverCompat.resolveRawOnActiveNetwork(query)
suspend fun openConnection(url: URL) = url.openConnection() suspend fun openConnection(url: URL) = url.openConnection()
...@@ -355,8 +353,6 @@ object BaseService { ...@@ -355,8 +353,6 @@ object BaseService {
try { try {
Executable.killAll() // clean up old processes Executable.killAll() // clean up old processes
preInit() preInit()
proxy.init(this@Interface)
data.udpFallback?.init(this@Interface)
if (profile.route == Acl.CUSTOM_RULES) try { if (profile.route == Acl.CUSTOM_RULES) try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
Acl.customRules.flatten(10, this@Interface::openConnection).also { Acl.customRules.flatten(10, this@Interface::openConnection).also {
...@@ -379,8 +375,6 @@ object BaseService { ...@@ -379,8 +375,6 @@ object BaseService {
data.changeState(State.Connected) data.changeState(State.Connected)
} catch (_: CancellationException) { } catch (_: CancellationException) {
// if the job was cancelled, it is canceller's responsibility to call stopRunner // if the job was cancelled, it is canceller's responsibility to call stopRunner
} catch (_: UnknownHostException) {
stopRunner(false, getString(R.string.invalid_server))
} catch (exc: Throwable) { } catch (exc: Throwable) {
if (exc is ExpectedException) Timber.d(exc) else Timber.w(exc) if (exc is ExpectedException) Timber.d(exc) else Timber.w(exc)
stopRunner(false, "${getString(R.string.service_failed)}: ${exc.readableMessage}") stopRunner(false, "${getString(R.string.service_failed)}: ${exc.readableMessage}")
......
...@@ -27,15 +27,12 @@ import com.github.shadowsocks.database.Profile ...@@ -27,15 +27,12 @@ import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.plugin.PluginManager import com.github.shadowsocks.plugin.PluginManager
import com.github.shadowsocks.preference.DataStore import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.parseNumericAddress
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONObject import org.json.JSONObject
import java.io.File import java.io.File
import java.io.IOException
import java.net.URI import java.net.URI
import java.net.URISyntaxException import java.net.URISyntaxException
import java.net.UnknownHostException
/** /**
* This class sets up environment for ss-local. * This class sets up environment for ss-local.
...@@ -51,17 +48,6 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -51,17 +48,6 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
var trafficMonitor: TrafficMonitor? = null var trafficMonitor: TrafficMonitor? = null
val plugin by lazy { PluginManager.init(PluginConfiguration(profile.plugin ?: "")) } val plugin by lazy { PluginManager.init(PluginConfiguration(profile.plugin ?: "")) }
suspend fun init(service: BaseService.Interface) {
// it's hard to resolve DNS on a specific interface so we'll do it here
if (plugin != null && profile.host.parseNumericAddress() == null) {
profile.host = try {
service.resolver(profile.host).firstOrNull()
} catch (e: IOException) {
throw UnknownHostException().initCause(e)
}?.hostAddress ?: throw UnknownHostException()
}
}
/** /**
* Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or * Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or
* device storage, depending on which is currently available. * device storage, depending on which is currently available.
......
...@@ -146,7 +146,6 @@ class VpnService : BaseVpnService(), BaseService.Interface { ...@@ -146,7 +146,6 @@ class VpnService : BaseVpnService(), BaseService.Interface {
} }
override suspend fun preInit() = DefaultNetworkListener.start(this) { underlyingNetwork = it } override suspend fun preInit() = DefaultNetworkListener.start(this) { underlyingNetwork = it }
override suspend fun resolver(host: String) = DnsResolverCompat.resolve(DefaultNetworkListener.get(), host)
override suspend fun rawResolver(query: ByteArray) = override suspend fun rawResolver(query: ByteArray) =
// no need to listen for network here as this is only used for forwarding local DNS queries. // no need to listen for network here as this is only used for forwarding local DNS queries.
// retries should be attempted by client. // retries should be attempted by client.
......
...@@ -69,7 +69,6 @@ ...@@ -69,7 +69,6 @@
<string name="service_proxy">Proxy Service</string> <string name="service_proxy">Proxy Service</string>
<string name="service_transproxy">Transproxy Service</string> <string name="service_transproxy">Transproxy Service</string>
<string name="forward_success">Shadowsocks started.</string> <string name="forward_success">Shadowsocks started.</string>
<string name="invalid_server">Invalid server name</string>
<string name="service_failed">Failed to connect the remote server</string> <string name="service_failed">Failed to connect the remote server</string>
<string name="stop">Stop</string> <string name="stop">Stop</string>
<string name="stopping">Shutting down…</string> <string name="stopping">Shutting down…</string>
......
Subproject commit 9977eb724e6d257e6a570b788d91d70b432a49e0 Subproject commit 7342501a737115c32c2f2eaa516a4e7b3a3385d9
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