Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
1def9e69
Commit
1def9e69
authored
Jan 31, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finally we fix cancelling
parent
96dddba3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
12 deletions
+10
-12
core/src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
...src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
+2
-2
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
...rc/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
+3
-3
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+5
-7
No files found.
core/src/main/java/com/github/shadowsocks/bg/TrafficMonitor.kt
View file @
1def9e69
...
...
@@ -31,10 +31,10 @@ import java.nio.ByteOrder
class
TrafficMonitor
(
statFile
:
File
)
:
AutoCloseable
{
private
val
thread
=
object
:
LocalSocketListener
(
"TrafficMonitor"
,
statFile
)
{
private
val
buffer
=
ByteArray
(
16
)
private
val
stat
=
ByteBuffer
.
wrap
(
buffer
).
order
(
ByteOrder
.
LITTLE_ENDIAN
)
override
fun
acceptInternal
(
socket
:
LocalSocket
)
{
val
buffer
=
ByteArray
(
16
)
if
(
socket
.
inputStream
.
read
(
buffer
)
!=
16
)
throw
IOException
(
"Unexpected traffic stat length"
)
val
stat
=
ByteBuffer
.
wrap
(
buffer
).
order
(
ByteOrder
.
LITTLE_ENDIAN
)
val
tx
=
stat
.
getLong
(
0
)
val
rx
=
stat
.
getLong
(
8
)
if
(
current
.
txTotal
!=
tx
)
{
...
...
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
View file @
1def9e69
...
...
@@ -20,6 +20,7 @@
package
com.github.shadowsocks.net
import
kotlinx.coroutines.suspendCancellableCoroutine
import
java.nio.ByteBuffer
import
java.nio.channels.Pipe
import
java.nio.channels.SelectableChannel
...
...
@@ -27,7 +28,6 @@ import java.nio.channels.SelectionKey
import
java.nio.channels.Selector
import
java.util.concurrent.ConcurrentLinkedQueue
import
kotlin.coroutines.resume
import
kotlin.coroutines.suspendCoroutine
class
ChannelMonitor
:
Thread
(
"ChannelMonitor"
),
AutoCloseable
{
private
val
selector
=
Selector
.
open
()
...
...
@@ -60,10 +60,10 @@ class ChannelMonitor : Thread("ChannelMonitor"), AutoCloseable {
while
(
registrationPipe
.
sink
().
write
(
junk
)
==
0
);
}
suspend
fun
wait
(
channel
:
SelectableChannel
,
ops
:
Int
)
=
suspendC
oroutine
<
Unit
>
{
continuation
->
suspend
fun
wait
(
channel
:
SelectableChannel
,
ops
:
Int
)
=
suspendC
ancellableCoroutine
<
Unit
>
{
cont
->
register
(
channel
,
ops
)
{
it
.
interestOps
(
0
)
// stop listening
cont
inuation
.
resume
(
Unit
)
cont
.
resume
(
Unit
)
}
}
...
...
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
1def9e69
...
...
@@ -25,7 +25,6 @@ import com.github.shadowsocks.utils.printLog
import
kotlinx.coroutines.*
import
org.xbill.DNS.*
import
java.io.IOException
import
java.lang.RuntimeException
import
java.net.*
import
java.nio.ByteBuffer
import
java.nio.channels.DatagramChannel
...
...
@@ -63,7 +62,6 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private
const
val
TTL
=
120L
private
const
val
UDP_PACKET_SIZE
=
512
}
private
val
monitor
=
ChannelMonitor
()
private
val
job
=
SupervisorJob
()
...
...
@@ -79,8 +77,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
launch
{
try
{
val
reply
=
resolve
(
buffer
)
while
(
isActive
&&
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
catch
(
e
:
Runtime
Exception
)
{
while
(
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
catch
(
e
:
Exception
)
{
printLog
(
e
)
}
}
...
...
@@ -144,8 +142,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
channel
.
configureBlocking
(
false
)
channel
.
connect
(
proxy
)
val
wrapped
=
remoteDns
.
tcpWrap
(
packet
)
while
(
isActive
&&
!
channel
.
finishConnect
())
monitor
.
wait
(
channel
,
SelectionKey
.
OP_CONNECT
)
while
(
isActive
&&
channel
.
write
(
wrapped
)
>=
0
&&
wrapped
.
hasRemaining
())
{
while
(!
channel
.
finishConnect
())
monitor
.
wait
(
channel
,
SelectionKey
.
OP_CONNECT
)
while
(
channel
.
write
(
wrapped
)
>=
0
&&
wrapped
.
hasRemaining
())
{
monitor
.
wait
(
channel
,
SelectionKey
.
OP_WRITE
)
}
val
result
=
remoteDns
.
tcpReceiveBuffer
(
UDP_PACKET_SIZE
)
...
...
@@ -161,7 +159,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
result
.
flip
()
remoteDns
.
udpUnwrap
(
result
)
result
}
.
also
{
Log
.
d
(
"forward"
,
"completed $it"
)
}
}
}
}
...
...
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