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
96dddba3
Commit
96dddba3
authored
Jan 31, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do local and remote DNS resolving simultaneously
parent
32e3d7ab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+10
-7
No files found.
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
96dddba3
...
...
@@ -94,22 +94,24 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
printLog
(
e
)
return
forward
(
packet
)
}
val
remote
=
coroutineScope
{
async
{
forward
(
packet
)
}
}
try
{
if
(
forwardOnly
||
request
.
header
.
opcode
!=
Opcode
.
QUERY
)
return
forward
(
packet
)
if
(
forwardOnly
||
request
.
header
.
opcode
!=
Opcode
.
QUERY
)
return
remote
.
await
(
)
val
question
=
request
.
question
if
(
question
?.
type
!=
Type
.
A
)
return
forward
(
packet
)
if
(
question
?.
type
!=
Type
.
A
)
return
remote
.
await
(
)
val
host
=
question
.
name
.
toString
(
true
)
if
(
remoteDomainMatcher
?.
containsMatchIn
(
host
)
==
true
)
return
forward
(
packet
)
if
(
remoteDomainMatcher
?.
containsMatchIn
(
host
)
==
true
)
return
remote
.
await
(
)
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
)
return
remote
.
await
(
)
}
catch
(
_
:
UnknownHostException
)
{
return
forward
(
packet
)
return
remote
.
await
(
)
}
if
(
localResults
.
isEmpty
())
return
forward
(
packet
)
if
(
localResults
.
isEmpty
())
return
remote
.
await
(
)
if
(
localIpMatcher
.
isEmpty
()
||
localIpMatcher
.
any
{
subnet
->
localResults
.
any
(
subnet
::
matches
)
})
{
remote
.
cancel
()
val
response
=
Message
(
request
.
header
.
id
)
response
.
header
.
setFlag
(
Flags
.
QR
.
toInt
())
// this is a response
if
(
request
.
header
.
getFlag
(
Flags
.
RD
.
toInt
()))
response
.
header
.
setFlag
(
Flags
.
RD
.
toInt
())
...
...
@@ -122,8 +124,9 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
},
Section
.
ANSWER
)
return
ByteBuffer
.
wrap
(
response
.
toWire
())
}
return
forward
(
packet
)
return
remote
.
await
(
)
}
catch
(
e
:
IOException
)
{
remote
.
cancel
()
printLog
(
e
)
val
response
=
Message
(
request
.
header
.
id
)
response
.
header
.
rcode
=
Rcode
.
SERVFAIL
...
...
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