Commit dd3c6dba authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Use non-IP proxy in non-vpn mode

parent e6b00cc2
......@@ -1010,6 +1010,7 @@ class DnsVpnService : VpnService(), Runnable {
override fun run() {
log("run() called")
log("Starting with config: $serverConfig")
log("Running in non-vpn mode: $runInNonVpnMode")
log("Creating handle.")
var defaultHandle: DnsHandle? = null
......@@ -1063,44 +1064,52 @@ class DnsVpnService : VpnService(), Runnable {
dnsCache = createDnsCache()
localResolver = createLocalResolver()
dnsProxy = SmokeProxy(
defaultHandle!!,
handles + createProxyBypassHandlers(),
dnsCache,
createQueryLogger(),
localResolver
)
log("DnsProxy created, creating VPN proxy")
vpnProxy = if(runInNonVpnMode) {
RetryingVPNTunnelProxy(dnsProxy!!, socketProtector = object:Proxy.SocketProtector {
override fun protectDatagramSocket(socket: DatagramSocket) {}
override fun protectSocket(socket: Socket) {}
override fun protectSocket(socket: Int) {}
}, coroutineScope = CoroutineScope(
newFixedThreadPoolContext(2, "proxy-pool")
), logger = VpnLogger(applicationContext))
if(runInNonVpnMode) {
log("Running in non-VPN mode, starting async")
GlobalScope.launch {
dnsProxy = NonIPSmokeProxy(
defaultHandle!!,
handles + createProxyBypassHandlers(),
dnsCache,
createQueryLogger(),
localResolver,
InetAddress.getLocalHost(),
getPreferences().dnsServerModePort
)
vpnProxy = RetryingVPNTunnelProxy(dnsProxy!!, socketProtector = object:Proxy.SocketProtector {
override fun protectDatagramSocket(socket: DatagramSocket) {}
override fun protectSocket(socket: Socket) {}
override fun protectSocket(socket: Int) {}
}, coroutineScope = CoroutineScope(
newFixedThreadPoolContext(2, "proxy-pool")
), logger = VpnLogger(applicationContext))
vpnProxy?.maxRetries = 15
dnsServerProxy = DnsServerPacketProxy(vpnProxy!!, InetAddress.getLocalHost(), getPreferences().dnsServerModePort)
dnsServerProxy!!.startServer()
log("Non-VPN proxy started.")
}
} else {
RetryingVPNTunnelProxy(dnsProxy!!, vpnService = this, coroutineScope = CoroutineScope(
dnsProxy = SmokeProxy(
defaultHandle!!,
handles + createProxyBypassHandlers(),
dnsCache,
createQueryLogger(),
localResolver
)
vpnProxy = RetryingVPNTunnelProxy(dnsProxy!!, vpnService = this, coroutineScope = CoroutineScope(
newFixedThreadPoolContext(2, "proxy-pool")
), logger = VpnLogger(applicationContext))
vpnProxy?.maxRetries = 15
log("VPN proxy creating, trying to run...")
fileDescriptor?.let {
vpnProxy?.runProxyWithRetry(it, it)
} ?: run {
recreateVpn(false, null)
return
}
log("VPN proxy started.")
}
vpnProxy?.maxRetries = 15
if(runInNonVpnMode) {
GlobalScope.launch {
dnsServerProxy = DnsServerPacketProxy(vpnProxy!!, InetAddress.getLocalHost(), getPreferences().dnsServerModePort)
dnsServerProxy!!.startServer()
}
} else {
log("VPN proxy creating, trying to run...")
fileDescriptor?.let {
vpnProxy?.runProxyWithRetry(it, it)
} ?: run {
recreateVpn(false, null)
return
}
}
log("VPN proxy started.")
currentTrafficStats = vpnProxy?.trafficStats
LocalBroadcastManager.getInstance(this).sendBroadcast(Intent(BROADCAST_VPN_ACTIVE))
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).cancel(Notifications.ID_SERVICE_REVOKED)
......
......@@ -2,6 +2,7 @@ package com.frostnerd.smokescreen.util.proxy
import com.frostnerd.dnstunnelproxy.*
import com.frostnerd.dnstunnelproxy.QueryListener
import java.net.InetAddress
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
......@@ -38,4 +39,26 @@ class SmokeProxy(
cache,
queryListener = queryListener,
localResolver = localResolver
)
class NonIPSmokeProxy(
dnsHandle: DnsHandle,
proxyBypassHandles: List<DnsHandle>,
val cache: SimpleDnsCache?,
queryListener: QueryListener?,
localResolver: LocalResolver?,
bindAddress:InetAddress,
bindPort:Int
) :
NonIPDnsPacketProxy(
proxyBypassHandles.toMutableList().let {
it.add(dnsHandle)
it
}.toList(),
null,
cache,
queryListener = queryListener,
localResolver = localResolver,
localAddress = bindAddress,
localPort = bindPort
)
\ No newline at end of file
Supports Markdown
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