Skip to content

Commit

Permalink
Ensure hosts results are used
Browse files Browse the repository at this point in the history
Fixes #2412.
  • Loading branch information
Mygod committed Jan 19, 2020
1 parent e9dc275 commit 52c87f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 1 addition & 7 deletions core/src/main/java/com/github/shadowsocks/net/HostsFile.kt
Expand Up @@ -21,8 +21,6 @@
package com.github.shadowsocks.net

import com.github.shadowsocks.utils.parseNumericAddress
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress

class HostsFile(input: String = "") {
Expand All @@ -36,9 +34,5 @@ class HostsFile(input: String = "") {
}

val configuredHostnames get() = map.size
fun resolve(hostname: String, isIpv6: Boolean): List<InetAddress> {
return (map[hostname] ?: return emptyList()).run {
if (isIpv6) filterIsInstance<Inet6Address>() else filterIsInstance<Inet4Address>()
}.shuffled()
}
fun resolve(hostname: String) = map[hostname] ?: emptyList<InetAddress>()
}
Expand Up @@ -124,10 +124,12 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
else -> return@supervisorScope remote.await()
}
val host = question.name.canonicalize().toString(true)
val hostsResults = hosts.resolve(host, isIpv6)
val hostsResults = hosts.resolve(host)
if (hostsResults.isNotEmpty()) {
remote.cancel()
return@supervisorScope cookDnsResponse(request, hostsResults)
return@supervisorScope cookDnsResponse(request, hostsResults.run {
if (isIpv6) filterIsInstance<Inet6Address>() else filterIsInstance<Inet4Address>()
}.shuffled())
}
val acl = acl?.await() ?: return@supervisorScope remote.await()
val useLocal = when (acl.shouldBypass(host)) {
Expand Down

0 comments on commit 52c87f4

Please sign in to comment.