Commit 82b6635b authored by Mygod's avatar Mygod

Remove timeout as cancelling connect request is now available

parent dca0da09
...@@ -61,14 +61,12 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -61,14 +61,12 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
conn.doOutput = true conn.doOutput = true
val proxies = try { val proxies = try {
withTimeoutOrNull(10_000) { withContext(Dispatchers.IO) {
withContext(Dispatchers.IO) { conn.outputStream.bufferedWriter().use {
conn.outputStream.bufferedWriter().use { it.write("sig=" + Base64.encodeToString(mdg.digest(), Base64.DEFAULT))
it.write("sig=" + Base64.encodeToString(mdg.digest(), Base64.DEFAULT))
}
conn.inputStream.bufferedReader().readText()
} }
} ?: throw UnknownHostException() conn.inputStream.bufferedReader().readText()
}
} finally { } finally {
conn.disconnectFromMain() conn.disconnectFromMain()
}.split('|').toMutableList() }.split('|').toMutableList()
...@@ -85,19 +83,19 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -85,19 +83,19 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
} }
// it's hard to resolve DNS on a specific interface so we'll do it here // it's hard to resolve DNS on a specific interface so we'll do it here
if (profile.host.parseNumericAddress() == null) profile.host = withTimeoutOrNull(10_000) { if (profile.host.parseNumericAddress() == null) {
var retries = 0 var retries = 0
while (isActive) try { while (true) try {
val io = GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) } val io = GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) }
return@withTimeoutOrNull io.await().firstOrNull() profile.host = io.await().firstOrNull()?.hostAddress ?: throw UnknownHostException()
return
} catch (e: UnknownHostException) { } catch (e: UnknownHostException) {
// retries are only needed on Chrome OS where arc0 is brought up/down during VPN changes // retries are only needed on Chrome OS where arc0 is brought up/down during VPN changes
if (!DataStore.hasArc0) throw e if (!DataStore.hasArc0) throw e
Thread.yield() Thread.yield()
Crashlytics.log(Log.WARN, "ProxyInstance-resolver", "Retry resolving attempt #${++retries}") Crashlytics.log(Log.WARN, "ProxyInstance-resolver", "Retry resolving attempt #${++retries}")
} }
null // only here for type resolving }
}?.hostAddress ?: throw UnknownHostException()
} }
/** /**
......
...@@ -108,7 +108,8 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref ...@@ -108,7 +108,8 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
// service // service
var state = BaseService.State.Idle var state = BaseService.State.Idle
override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) = changeState(state, msg, true) override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) =
changeState(state, msg, true)
override fun trafficUpdated(profileId: Long, stats: TrafficStats) { override fun trafficUpdated(profileId: Long, stats: TrafficStats) {
if (profileId == 0L) this@MainActivity.stats.updateTraffic( if (profileId == 0L) this@MainActivity.stats.updateTraffic(
stats.txRate, stats.rxRate, stats.txTotal, stats.rxTotal) stats.txRate, stats.rxRate, stats.txTotal, stats.rxTotal)
......
...@@ -41,7 +41,8 @@ class TileService : BaseTileService(), ShadowsocksConnection.Callback { ...@@ -41,7 +41,8 @@ class TileService : BaseTileService(), ShadowsocksConnection.Callback {
private var tapPending = false private var tapPending = false
private val connection = ShadowsocksConnection() private val connection = ShadowsocksConnection()
override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) = updateTile(state) { profileName } override fun stateChanged(state: BaseService.State, profileName: String?, msg: String?) =
updateTile(state) { profileName }
override fun onServiceConnected(service: IShadowsocksService) { override fun onServiceConnected(service: IShadowsocksService) {
updateTile(BaseService.State.values()[service.state]) { service.profileName } updateTile(BaseService.State.values()[service.state]) { service.profileName }
if (tapPending) { if (tapPending) {
......
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