Commit c08fc40d authored by Mygod's avatar Mygod

Connect to proxyUrl using underlying network

parent f4120b1a
...@@ -43,6 +43,7 @@ import com.google.firebase.analytics.FirebaseAnalytics ...@@ -43,6 +43,7 @@ import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.* import kotlinx.coroutines.*
import java.io.File import java.io.File
import java.net.InetAddress import java.net.InetAddress
import java.net.URL
import java.net.UnknownHostException import java.net.UnknownHostException
import java.util.* import java.util.*
...@@ -279,6 +280,7 @@ object BaseService { ...@@ -279,6 +280,7 @@ object BaseService {
suspend fun preInit() { } suspend fun preInit() { }
suspend fun resolver(host: String) = InetAddress.getAllByName(host) suspend fun resolver(host: String) = InetAddress.getAllByName(host)
suspend fun openConnection(url: URL) = url.openConnection()
fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val data = data val data = data
...@@ -314,8 +316,8 @@ object BaseService { ...@@ -314,8 +316,8 @@ object BaseService {
try { try {
Executable.killAll() // clean up old processes Executable.killAll() // clean up old processes
preInit() preInit()
proxy.init(this@Interface::resolver) proxy.init(this@Interface)
data.udpFallback?.init(this@Interface::resolver) data.udpFallback?.init(this@Interface)
data.processes = GuardedProcessPool { data.processes = GuardedProcessPool {
printLog(it) printLog(it)
......
...@@ -38,7 +38,6 @@ import kotlinx.coroutines.* ...@@ -38,7 +38,6 @@ import kotlinx.coroutines.*
import java.io.File import java.io.File
import java.io.IOException import java.io.IOException
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.InetAddress
import java.net.UnknownHostException import java.net.UnknownHostException
import java.security.MessageDigest import java.security.MessageDigest
...@@ -51,11 +50,11 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -51,11 +50,11 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
private val plugin = PluginConfiguration(profile.plugin ?: "").selectedOptions private val plugin = PluginConfiguration(profile.plugin ?: "").selectedOptions
val pluginPath by lazy { PluginManager.init(plugin) } val pluginPath by lazy { PluginManager.init(plugin) }
suspend fun init(resolver: suspend (String) -> Array<InetAddress>) { suspend fun init(service: BaseService.Interface) {
if (profile.host == "198.199.101.152") { if (profile.host == "198.199.101.152") {
val mdg = MessageDigest.getInstance("SHA-1") val mdg = MessageDigest.getInstance("SHA-1")
mdg.update(Core.packageInfo.signaturesCompat.first().toByteArray()) mdg.update(Core.packageInfo.signaturesCompat.first().toByteArray())
val conn = RemoteConfig.proxyUrl.openConnection() as HttpURLConnection val conn = service.openConnection(RemoteConfig.proxyUrl) as HttpURLConnection
conn.requestMethod = "POST" conn.requestMethod = "POST"
conn.doOutput = true conn.doOutput = true
...@@ -83,7 +82,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -83,7 +82,7 @@ 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) profile.host = withTimeoutOrNull(10_000) {
GlobalScope.async(Dispatchers.IO) { resolver(profile.host) }.await().firstOrNull() GlobalScope.async(Dispatchers.IO) { service.resolver(profile.host) }.await().firstOrNull()
}?.hostAddress ?: throw UnknownHostException() }?.hostAddress ?: throw UnknownHostException()
} }
......
...@@ -47,6 +47,8 @@ import java.io.Closeable ...@@ -47,6 +47,8 @@ import java.io.Closeable
import java.io.File import java.io.File
import java.io.FileDescriptor import java.io.FileDescriptor
import java.io.IOException import java.io.IOException
import java.net.URL
import java.net.URLConnection
import java.util.* import java.util.*
import android.net.VpnService as BaseVpnService import android.net.VpnService as BaseVpnService
...@@ -136,6 +138,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -136,6 +138,7 @@ class VpnService : BaseVpnService(), LocalDnsService.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) = DefaultNetworkListener.get().getAllByName(host) override suspend fun resolver(host: String) = DefaultNetworkListener.get().getAllByName(host)
override suspend fun openConnection(url: URL) = DefaultNetworkListener.get().openConnection(url)
override suspend fun startProcesses() { override suspend fun startProcesses() {
worker = ProtectWorker().apply { start() } worker = ProtectWorker().apply { start() }
......
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