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
f8142a6f
Commit
f8142a6f
authored
Feb 08, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine code style
parent
38c78a90
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
...rc/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
+2
-2
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+30
-30
No files found.
core/src/main/java/com/github/shadowsocks/net/ChannelMonitor.kt
View file @
f8142a6f
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
f8142a6f
...
...
@@ -70,14 +70,16 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
suspend
fun
start
(
listen
:
SocketAddress
)
=
DatagramChannel
.
open
().
apply
{
configureBlocking
(
false
)
socket
().
bind
(
listen
)
monitor
.
register
(
this
,
SelectionKey
.
OP_READ
)
{
monitor
.
register
(
this
,
SelectionKey
.
OP_READ
)
{
handlePacket
(
this
)
}
}
private
fun
handlePacket
(
channel
:
DatagramChannel
)
{
val
buffer
=
ByteBuffer
.
allocateDirect
(
UDP_PACKET_SIZE
)
val
source
=
receive
(
buffer
)
!!
val
source
=
channel
.
receive
(
buffer
)
!!
buffer
.
flip
()
this
@LocalDnsServer
.
launch
{
launch
{
val
reply
=
resolve
(
buffer
)
while
(
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
while
(
channel
.
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
channel
,
SelectionKey
.
OP_WRITE
)
}
}
...
...
@@ -89,7 +91,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
return
forward
(
packet
)
}
return
coroutineScope
{
val
remote
=
async
{
forward
(
packet
)
}
val
remote
=
async
{
withTimeout
(
TIMEOUT
)
{
forward
(
packet
)
}
}
try
{
if
(
forwardOnly
||
request
.
header
.
opcode
!=
Opcode
.
QUERY
)
return
@coroutineScope
remote
.
await
()
val
question
=
request
.
question
...
...
@@ -135,8 +137,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private
suspend
fun
forward
(
packet
:
ByteBuffer
):
ByteBuffer
{
packet
.
position
(
0
)
// the packet might have been parsed, reset to beginning
return
withTimeout
(
TIMEOUT
)
{
if
(
tcp
)
SocketChannel
.
open
().
use
{
channel
->
return
if
(
tcp
)
SocketChannel
.
open
().
use
{
channel
->
channel
.
configureBlocking
(
false
)
channel
.
connect
(
proxy
)
val
wrapped
=
remoteDns
.
tcpWrap
(
packet
)
...
...
@@ -159,7 +160,6 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
result
}
}
}
fun
shutdown
(
scope
:
CoroutineScope
)
{
job
.
cancel
()
...
...
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