Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
AndroidUtils
VPNTunnelProxy
Commits
ba10c1c0
Commit
ba10c1c0
authored
Jan 24, 2021
by
Daniel Wolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use lock to prevent clearing early
parent
b686e108
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
library/build.gradle
library/build.gradle
+1
-1
library/src/main/java/com/frostnerd/vpntunnelproxy/VPNTunnelProxy.kt
.../main/java/com/frostnerd/vpntunnelproxy/VPNTunnelProxy.kt
+23
-10
No files found.
library/build.gradle
View file @
ba10c1c0
...
...
@@ -7,7 +7,7 @@ group = 'com.frostnerd.utilskt'
ext
{
libraryGroupId
=
group
libraryArtifactId
=
rootProject
.
name
libraryVersion
=
'3.1.1
1
'
libraryVersion
=
'3.1.1
2
'
}
android
{
...
...
library/src/main/java/com/frostnerd/vpntunnelproxy/VPNTunnelProxy.kt
View file @
ba10c1c0
...
...
@@ -14,7 +14,10 @@ import java.io.*
import
java.net.DatagramSocket
import
java.net.Socket
import
java.util.concurrent.locks.ReentrantLock
import
java.util.concurrent.locks.ReentrantReadWriteLock
import
kotlin.concurrent.read
import
kotlin.concurrent.withLock
import
kotlin.concurrent.write
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
...
...
@@ -66,6 +69,7 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
var
forwardingMode
:
ForwardingMode
=
ForwardingMode
.
MIXED
private
var
proxyThreadActive
:
Boolean
=
false
private
var
cleanupFinalized
:
Boolean
=
false
private
val
clearLock
=
ReentrantReadWriteLock
()
constructor
(
packetProxy
:
PacketProxy
,
trafficStats
:
TrafficStats
=
TrafficStats
(
0
,
0
),
...
...
@@ -141,6 +145,8 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
proxyThread
=
Thread
{
proxyThreadActive
=
true
logger
?.
info
(
"Proxy started on thread "
+
Thread
.
currentThread
().
name
)
val
lock
=
clearLock
.
readLock
()
lock
.
lock
()
try
{
try
{
while
(
shouldRun
)
{
...
...
@@ -193,11 +199,14 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
}
finally
{
logger
?.
info
(
"Proxy thread ended."
)
proxyThreadActive
=
false
lock
.
unlock
()
finalizeCleanup
()
}
}
if
(
forwardingMode
!=
ForwardingMode
.
ONLY_POLLABLE
)
nonPollableProxyThread
=
Thread
{
logger
?.
info
(
"Non-pollable proxy started on thread "
+
Thread
.
currentThread
().
name
)
val
lock
=
clearLock
.
readLock
()
lock
.
lock
()
try
{
while
(
shouldRun
)
{
forwardedPacketStore
?.
processNewAnswers
(
false
)
...
...
@@ -217,6 +226,8 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
}
catch
(
ex
:
java
.
lang
.
Exception
)
{
if
(
exceptionCallbacks
.
isEmpty
())
throw
ex
else
errorOccurred
(
ex
)
}
finally
{
lock
.
unlock
()
}
logger
?.
info
(
"Non-pollable proxy ended. Should run: $shouldRun"
)
}
...
...
@@ -274,17 +285,19 @@ open class VPNTunnelProxy(val packetProxy: PacketProxy,
}
private
fun
finalizeCleanup
()
{
proxyThread
=
null
nonPollableProxyThread
=
null
for
(
fileDescriptor
in
pipesToClose
)
{
fileDescriptor
.
tryClosing
()
clearLock
.
write
{
proxyThread
=
null
nonPollableProxyThread
=
null
for
(
fileDescriptor
in
pipesToClose
)
{
fileDescriptor
.
tryClosing
()
}
pipesToClose
.
clear
()
forwardedPacketStore
?.
clear
(
proxyStopped
)
tunnelHandle
?.
clear
(
false
)
cleanupFinalized
=
true
cleanupCallbacks
.
forEach
{
it
()
}
cleanupCallbacks
.
clear
()
}
pipesToClose
.
clear
()
forwardedPacketStore
?.
clear
(
proxyStopped
)
tunnelHandle
?.
clear
(
false
)
cleanupFinalized
=
true
cleanupCallbacks
?.
forEach
{
it
()
}
cleanupCallbacks
.
clear
()
}
@Throws
(
ErrnoException
::
class
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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