Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Projects
Groups
Snippets
Sign up now
Login
Sign in / Register
Toggle navigation
Menu
Open sidebar
Frank Tobin
Nebulo
Commits
dd3c6dba
Commit
dd3c6dba
authored
Jun 28, 2020
by
Daniel Wolf
Browse files
Use non-IP proxy in non-vpn mode
parent
e6b00cc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/DnsVpnService.kt
View file @
dd3c6dba
...
...
@@ -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
)
...
...
app/src/main/java/com/frostnerd/smokescreen/util/proxy/SmokeProxy.kt
View file @
dd3c6dba
...
...
@@ -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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment