Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
AndroidUtils
VPNTunnelProxy
Commits
3233ef90
Commit
3233ef90
authored
Jun 06, 2021
by
Daniel Wolf
Browse files
Re-add locking
parent
35793998
Changes
1
Hide whitespace changes
Inline
Side-by-side
library/src/main/java/com/frostnerd/vpntunnelproxy/ForwardedPacketStore.kt
View file @
3233ef90
...
...
@@ -11,7 +11,9 @@ import java.net.DatagramSocket
import
java.net.Socket
import
java.net.SocketException
import
java.util.*
import
java.util.concurrent.locks.ReentrantLock
import
kotlin.collections.ArrayList
import
kotlin.concurrent.withLock
/*
* Copyright (C) 2019 Daniel Wolf (Ch4t4r)
...
...
@@ -41,6 +43,7 @@ class ForwardedPacketStore(var logger: Logger?) {
private
val
_nonPollableForwardedPackets
:
LinkedList
<
FutureAnswer
>
=
LinkedList
()
private
val
newlyForwardedPackets
:
ArrayList
<
FutureAnswer
>
=
ArrayList
()
private
val
newlyForwardedNonPollablePackets
:
ArrayList
<
FutureAnswer
>
=
ArrayList
()
private
val
newPacketsLock
=
ReentrantLock
()
val
nonPollableForwardedPackets
:
List
<
FutureAnswer
>
=
_nonPollableForwardedPackets
val
forwardedPollablePackets
:
List
<
FutureAnswer
>
=
_forwardedPollablePackets
var
hasMixedAnswerType
:
Boolean
=
true
...
...
@@ -63,27 +66,33 @@ class ForwardedPacketStore(var logger: Logger?) {
@Throws
(
IOException
::
class
)
fun
addForwardedQuestion
(
futureAnswer
:
FutureAnswer
)
{
if
(
futureAnswer
.
isPollable
())
newlyForwardedPackets
.
add
(
futureAnswer
)
else
newlyForwardedNonPollablePackets
.
add
(
futureAnswer
)
newPacketsLock
.
withLock
{
if
(
futureAnswer
.
isPollable
())
newlyForwardedPackets
.
add
(
futureAnswer
)
else
newlyForwardedNonPollablePackets
.
add
(
futureAnswer
)
}
}
fun
processNewAnswers
(
pollable
:
Boolean
)
{
if
(
pollable
&&
newlyForwardedPackets
.
isNotEmpty
())
{
hasMixedAnswerType
=
newlyForwardedNonPollablePackets
.
isNotEmpty
()
for
(
packet
in
newlyForwardedPackets
)
{
packet
.
index
=
_forwardedPollablePackets
.
size
if
(
packet
.
isPollable
())
_forwardedPollablePackets
.
add
(
packet
)
else
_forwardedPollablePackets
.
add
(
packet
)
newPacketsLock
.
withLock
{
for
(
packet
in
newlyForwardedPackets
)
{
packet
.
index
=
_forwardedPollablePackets
.
size
if
(
packet
.
isPollable
())
_forwardedPollablePackets
.
add
(
packet
)
else
_forwardedPollablePackets
.
add
(
packet
)
}
newlyForwardedPackets
.
clear
()
}
newlyForwardedPackets
.
clear
()
}
else
if
(!
pollable
&&
newlyForwardedNonPollablePackets
.
isNotEmpty
())
{
hasMixedAnswerType
=
newlyForwardedPackets
.
isNotEmpty
()
for
(
packet
in
newlyForwardedNonPollablePackets
)
{
packet
.
index
=
_nonPollableForwardedPackets
.
size
if
(
packet
.
isPollable
())
_nonPollableForwardedPackets
.
add
(
packet
)
else
_nonPollableForwardedPackets
.
add
(
packet
)
newPacketsLock
.
withLock
{
hasMixedAnswerType
=
newlyForwardedPackets
.
isNotEmpty
()
for
(
packet
in
newlyForwardedNonPollablePackets
)
{
packet
.
index
=
_nonPollableForwardedPackets
.
size
if
(
packet
.
isPollable
())
_nonPollableForwardedPackets
.
add
(
packet
)
else
_nonPollableForwardedPackets
.
add
(
packet
)
}
newlyForwardedNonPollablePackets
.
clear
()
}
newlyForwardedNonPollablePackets
.
clear
()
}
}
...
...
@@ -97,22 +106,24 @@ class ForwardedPacketStore(var logger: Logger?) {
if
(
clearing
)
return
clearing
=
true
logger
?.
fine
(
"Clearing ForwardedPacketStore"
)
newPacketsLock
.
withLock
{
newlyForwardedPackets
.
forEach
{
cleanup
(
it
)
}
newlyForwardedNonPollablePackets
.
forEach
{
cleanup
(
it
)
}
newlyForwardedPackets
.
clear
()
newlyForwardedNonPollablePackets
.
clear
()
}
forwardedPollablePackets
.
forEach
{
cleanup
(
it
)
}
_nonPollableForwardedPackets
.
forEach
{
cleanup
(
it
)
}
newlyForwardedPackets
.
forEach
{
cleanup
(
it
)
}
newlyForwardedNonPollablePackets
.
forEach
{
cleanup
(
it
)
}
_nonPollableForwardedPackets
.
clear
()
_forwardedPollablePackets
.
clear
()
newlyForwardedPackets
.
clear
()
newlyForwardedNonPollablePackets
.
clear
()
clearing
=
false
if
(
completely
)
logger
=
null
}
...
...
Write
Preview
Supports
Markdown
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