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
32e3d7ab
Commit
32e3d7ab
authored
Jan 31, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine error logging
parent
ea659848
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
4 deletions
+10
-4
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+10
-4
No files found.
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
32e3d7ab
...
...
@@ -25,6 +25,7 @@ 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
...
...
@@ -65,8 +66,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private
val
monitor
=
ChannelMonitor
()
private
val
job
=
Job
()
override
val
coroutineContext
=
Dispatchers
.
Default
+
job
+
CoroutineExceptionHandler
{
_
,
t
->
printLog
(
t
)
}
private
val
job
=
Supervisor
Job
()
override
val
coroutineContext
=
Dispatchers
.
Default
+
job
fun
start
(
listen
:
SocketAddress
)
=
DatagramChannel
.
open
().
apply
{
configureBlocking
(
false
)
...
...
@@ -76,8 +77,12 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val
source
=
receive
(
buffer
)
!!
buffer
.
flip
()
launch
{
val
reply
=
resolve
(
buffer
)
while
(
isActive
&&
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
try
{
val
reply
=
resolve
(
buffer
)
while
(
isActive
&&
send
(
reply
,
source
)
<=
0
)
monitor
.
wait
(
this
@apply
,
SelectionKey
.
OP_WRITE
)
}
catch
(
e
:
RuntimeException
)
{
printLog
(
e
)
}
}
}
}
...
...
@@ -98,6 +103,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val
localResults
=
try
{
withTimeout
(
TIMEOUT
)
{
withContext
(
Dispatchers
.
IO
)
{
localResolver
(
host
)
}
}
}
catch
(
_
:
TimeoutCancellationException
)
{
Log
.
w
(
"LocalDnsServer"
,
"Local resolving timed out, falling back to remote resolving"
)
return
forward
(
packet
)
}
catch
(
_
:
UnknownHostException
)
{
return
forward
(
packet
)
...
...
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