Skip to content

Commit c765454

Browse files
committed
Resolve server name dynamically always
Fixes #2722.
1 parent 7b3e4ce commit c765454

File tree

5 files changed

+1
-23
lines changed

5 files changed

+1
-23
lines changed

core/src/main/java/com/github/shadowsocks/bg/BaseService.kt

-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import timber.log.Timber
5050
import java.io.File
5151
import java.io.IOException
5252
import java.net.URL
53-
import java.net.UnknownHostException
5453

5554
/**
5655
* This object uses WeakMap to simulate the effects of multi-inheritance.
@@ -316,7 +315,6 @@ object BaseService {
316315
listOfNotNull(data.proxy, data.udpFallback).forEach { it.trafficMonitor?.persistStats(it.profile.id) }
317316

318317
suspend fun preInit() { }
319-
suspend fun resolver(host: String) = DnsResolverCompat.resolveOnActiveNetwork(host)
320318
suspend fun rawResolver(query: ByteArray) = DnsResolverCompat.resolveRawOnActiveNetwork(query)
321319
suspend fun openConnection(url: URL) = url.openConnection()
322320

@@ -355,8 +353,6 @@ object BaseService {
355353
try {
356354
Executable.killAll() // clean up old processes
357355
preInit()
358-
proxy.init(this@Interface)
359-
data.udpFallback?.init(this@Interface)
360356
if (profile.route == Acl.CUSTOM_RULES) try {
361357
withContext(Dispatchers.IO) {
362358
Acl.customRules.flatten(10, this@Interface::openConnection).also {
@@ -379,8 +375,6 @@ object BaseService {
379375
data.changeState(State.Connected)
380376
} catch (_: CancellationException) {
381377
// if the job was cancelled, it is canceller's responsibility to call stopRunner
382-
} catch (_: UnknownHostException) {
383-
stopRunner(false, getString(R.string.invalid_server))
384378
} catch (exc: Throwable) {
385379
if (exc is ExpectedException) Timber.d(exc) else Timber.w(exc)
386380
stopRunner(false, "${getString(R.string.service_failed)}: ${exc.readableMessage}")

core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt

-14
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ import com.github.shadowsocks.database.Profile
2727
import com.github.shadowsocks.plugin.PluginConfiguration
2828
import com.github.shadowsocks.plugin.PluginManager
2929
import com.github.shadowsocks.preference.DataStore
30-
import com.github.shadowsocks.utils.parseNumericAddress
3130
import kotlinx.coroutines.CoroutineScope
3231
import org.json.JSONArray
3332
import org.json.JSONObject
3433
import java.io.File
35-
import java.io.IOException
3634
import java.net.URI
3735
import java.net.URISyntaxException
38-
import java.net.UnknownHostException
3936

4037
/**
4138
* This class sets up environment for ss-local.
@@ -51,17 +48,6 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
5148
var trafficMonitor: TrafficMonitor? = null
5249
val plugin by lazy { PluginManager.init(PluginConfiguration(profile.plugin ?: "")) }
5350

54-
suspend fun init(service: BaseService.Interface) {
55-
// it's hard to resolve DNS on a specific interface so we'll do it here
56-
if (plugin != null && profile.host.parseNumericAddress() == null) {
57-
profile.host = try {
58-
service.resolver(profile.host).firstOrNull()
59-
} catch (e: IOException) {
60-
throw UnknownHostException().initCause(e)
61-
}?.hostAddress ?: throw UnknownHostException()
62-
}
63-
}
64-
6551
/**
6652
* Sensitive shadowsocks configuration file requires extra protection. It may be stored in encrypted storage or
6753
* device storage, depending on which is currently available.

core/src/main/java/com/github/shadowsocks/bg/VpnService.kt

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ class VpnService : BaseVpnService(), BaseService.Interface {
146146
}
147147

148148
override suspend fun preInit() = DefaultNetworkListener.start(this) { underlyingNetwork = it }
149-
override suspend fun resolver(host: String) = DnsResolverCompat.resolve(DefaultNetworkListener.get(), host)
150149
override suspend fun rawResolver(query: ByteArray) =
151150
// no need to listen for network here as this is only used for forwarding local DNS queries.
152151
// retries should be attempted by client.

core/src/main/res/values/strings.xml

-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
<string name="service_proxy">Proxy Service</string>
7070
<string name="service_transproxy">Transproxy Service</string>
7171
<string name="forward_success">Shadowsocks started.</string>
72-
<string name="invalid_server">Invalid server name</string>
7372
<string name="service_failed">Failed to connect the remote server</string>
7473
<string name="stop">Stop</string>
7574
<string name="stopping">Shutting down…</string>

core/src/main/rust/shadowsocks-rust

Submodule shadowsocks-rust updated 57 files

0 commit comments

Comments
 (0)