Commit 262fa41a authored by Mygod's avatar Mygod

Allow Chrome OS host and VMs to connect to local proxies

Sadly, crostini does not support Android VPNs yet, but either way this feature would be useful for people on Chrome OS to use it in proxy-only mode.

To test: (assuming local SOCKS5 port = 1080)
$ curl https://ipinfo.io --socks5 100.115.92.2:1080
parent ca7a5333
...@@ -46,7 +46,7 @@ object LocalDnsService { ...@@ -46,7 +46,7 @@ object LocalDnsService {
put("Timeout", timeout) put("Timeout", timeout)
put("EDNSClientSubnet", JSONObject().put("Policy", "disable")) put("EDNSClientSubnet", JSONObject().put("Policy", "disable"))
put("Protocol", if (edns) { put("Protocol", if (edns) {
put("Socks5Address", "127.0.0.1:" + DataStore.portProxy) put("Socks5Address", "127.0.0.1:${DataStore.portProxy}")
"tcp" "tcp"
} else "udp") } else "udp")
} }
......
...@@ -29,6 +29,8 @@ import com.github.shadowsocks.utils.DirectBoot ...@@ -29,6 +29,8 @@ import com.github.shadowsocks.utils.DirectBoot
import com.github.shadowsocks.utils.Key import com.github.shadowsocks.utils.Key
import com.github.shadowsocks.utils.TcpFastOpen import com.github.shadowsocks.utils.TcpFastOpen
import com.github.shadowsocks.utils.parsePort import com.github.shadowsocks.utils.parsePort
import java.net.NetworkInterface
import java.net.SocketException
object DataStore : OnPreferenceDataStoreChangeListener { object DataStore : OnPreferenceDataStoreChangeListener {
val publicStore = RoomPreferenceDataStore(PublicDatabase.kvPairDao) val publicStore = RoomPreferenceDataStore(PublicDatabase.kvPairDao)
...@@ -62,7 +64,31 @@ object DataStore : OnPreferenceDataStoreChangeListener { ...@@ -62,7 +64,31 @@ object DataStore : OnPreferenceDataStoreChangeListener {
val directBootAware: Boolean get() = Core.directBootSupported && canToggleLocked val directBootAware: Boolean get() = Core.directBootSupported && canToggleLocked
val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && DataStore.publicStore.getBoolean(Key.tfo, true) val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && DataStore.publicStore.getBoolean(Key.tfo, true)
val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeVpn val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeVpn
val listenAddress get() = if (publicStore.getBoolean(Key.shareOverLan, false)) "0.0.0.0" else "127.0.0.1"
/**
* An alternative way to detect this interface could be checking MAC address = 00:ff:aa:00:00:55, but there is no
* reliable way of getting MAC address for now.
*/
private val hasArc0 by lazy {
var retry = 0
while (retry < 5) {
try {
return@lazy NetworkInterface.getByName("arc0") != null
} catch (_: SocketException) { }
retry++
Thread.sleep(100L shl retry)
}
false
}
/**
* We hardcode bogus IP address 100.115.92.2 in Chrome OS as this IP may not be available when the device is not
* connected to any network.
*/
val listenAddress get() = when {
publicStore.getBoolean(Key.shareOverLan, false) -> "0.0.0.0"
hasArc0 -> "100.115.92.2"
else -> "127.0.0.1"
}
var portProxy: Int var portProxy: Int
get() = getLocalPort(Key.portProxy, 1080) get() = getLocalPort(Key.portProxy, 1080)
set(value) = publicStore.putString(Key.portProxy, value.toString()) set(value) = publicStore.putString(Key.portProxy, value.toString())
......
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