Skip to content

Commit

Permalink
Resolve server name dynamically always
Browse files Browse the repository at this point in the history
Fixes #2722.
  • Loading branch information
Mygod committed May 8, 2021
1 parent 7b3e4ce commit c765454
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 23 deletions.
6 changes: 0 additions & 6 deletions core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import timber.log.Timber
import java.io.File
import java.io.IOException
import java.net.URL
import java.net.UnknownHostException

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

suspend fun preInit() { }
suspend fun resolver(host: String) = DnsResolverCompat.resolveOnActiveNetwork(host)
suspend fun rawResolver(query: ByteArray) = DnsResolverCompat.resolveRawOnActiveNetwork(query)
suspend fun openConnection(url: URL) = url.openConnection()

Expand Down Expand Up @@ -355,8 +353,6 @@ object BaseService {
try {
Executable.killAll() // clean up old processes
preInit()
proxy.init(this@Interface)
data.udpFallback?.init(this@Interface)
if (profile.route == Acl.CUSTOM_RULES) try {
withContext(Dispatchers.IO) {
Acl.customRules.flatten(10, this@Interface::openConnection).also {
Expand All @@ -379,8 +375,6 @@ object BaseService {
data.changeState(State.Connected)
} catch (_: CancellationException) {
// 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) {
if (exc is ExpectedException) Timber.d(exc) else Timber.w(exc)
stopRunner(false, "${getString(R.string.service_failed)}: ${exc.readableMessage}")
Expand Down
14 changes: 0 additions & 14 deletions core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.plugin.PluginManager
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.parseNumericAddress
import kotlinx.coroutines.CoroutineScope
import org.json.JSONArray
import org.json.JSONObject
import java.io.File
import java.io.IOException
import java.net.URI
import java.net.URISyntaxException
import java.net.UnknownHostException

/**
* This class sets up environment for ss-local.
Expand All @@ -51,17 +48,6 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
var trafficMonitor: TrafficMonitor? = null
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
* device storage, depending on which is currently available.
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ class VpnService : BaseVpnService(), BaseService.Interface {
}

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) =
// no need to listen for network here as this is only used for forwarding local DNS queries.
// retries should be attempted by client.
Expand Down
1 change: 0 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
<string name="service_proxy">Proxy Service</string>
<string name="service_transproxy">Transproxy Service</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="stop">Stop</string>
<string name="stopping">Shutting down…</string>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/rust/shadowsocks-rust
Submodule shadowsocks-rust updated 57 files
+26 −0 .github/dependabot.yml
+6 −0 .github/workflows/build-and-test.yml
+107 −58 Cargo.lock
+7 −2 Cargo.toml
+14 −5 README.md
+8 −0 bin/common/allocator/mod.rs
+6 −2 bin/sslocal.rs
+7 −3 bin/ssmanager.rs
+7 −2 bin/ssserver.rs
+5 −2 crates/shadowsocks-service/Cargo.toml
+48 −5 crates/shadowsocks-service/src/config.rs
+4 −1 crates/shadowsocks-service/src/local/context.rs
+33 −4 crates/shadowsocks-service/src/local/dns/server.rs
+4 −4 crates/shadowsocks-service/src/local/dns/upstream.rs
+6 −3 crates/shadowsocks-service/src/local/http/client_cache.rs
+6 −1 crates/shadowsocks-service/src/local/http/server.rs
+5 −0 crates/shadowsocks-service/src/local/loadbalancing/ping_balancer.rs
+6 −12 crates/shadowsocks-service/src/local/loadbalancing/server_data.rs
+15 −10 crates/shadowsocks-service/src/local/loadbalancing/server_stat.rs
+5 −3 crates/shadowsocks-service/src/local/mod.rs
+11 −17 crates/shadowsocks-service/src/local/net/tcp/auto_proxy_stream.rs
+59 −30 crates/shadowsocks-service/src/local/net/udp/association.rs
+77 −15 crates/shadowsocks-service/src/local/redir/udprelay/mod.rs
+31 −25 crates/shadowsocks-service/src/local/tunnel/udprelay.rs
+2 −0 crates/shadowsocks-service/src/manager/mod.rs
+5 −3 crates/shadowsocks-service/src/server/mod.rs
+67 −30 crates/shadowsocks-service/src/server/tcprelay.rs
+42 −31 crates/shadowsocks-service/src/server/udprelay.rs
+3 −3 crates/shadowsocks/Cargo.toml
+62 −1 crates/shadowsocks/src/config.rs
+50 −32 crates/shadowsocks/src/dns_resolver/resolver.rs
+1 −0 crates/shadowsocks/src/net/mod.rs
+5 −3 crates/shadowsocks/src/net/option.rs
+54 −0 crates/shadowsocks/src/net/sys/mod.rs
+198 −0 crates/shadowsocks/src/net/sys/unix/bsd/freebsd.rs
+210 −0 crates/shadowsocks/src/net/sys/unix/bsd/macos.rs
+14 −0 crates/shadowsocks/src/net/sys/unix/bsd/mod.rs
+1 −0 crates/shadowsocks/src/net/sys/unix/bsd/others.rs
+366 −0 crates/shadowsocks/src/net/sys/unix/linux/mod.rs
+0 −0 crates/shadowsocks/src/net/sys/unix/linux/uds.rs
+75 −0 crates/shadowsocks/src/net/sys/unix/mod.rs
+90 −0 crates/shadowsocks/src/net/sys/unix/others.rs
+471 −0 crates/shadowsocks/src/net/sys/windows/mod.rs
+41 −40 crates/shadowsocks/src/net/tcp.rs
+6 −9 crates/shadowsocks/src/net/udp.rs
+0 −1 crates/shadowsocks/src/relay/mod.rs
+0 −11 crates/shadowsocks/src/relay/sys/mod.rs
+0 −335 crates/shadowsocks/src/relay/sys/unix/mod.rs
+0 −161 crates/shadowsocks/src/relay/sys/windows/mod.rs
+6 −12 crates/shadowsocks/src/relay/tcprelay/proxy_stream/client.rs
+104 −0 crates/shadowsocks/tests/tcp_tfo.rs
+33 −7 debian/changelog
+1 −1 rust-toolchain
+5 −2 tests/http.rs
+5 −5 tests/socks4.rs
+9 −9 tests/socks5.rs
+28 −17 tests/tunnel.rs

0 comments on commit c765454

Please sign in to comment.