Commit 823633a8 authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Also use static rules when user has not enabled DNS rules

#285
parent e1ec8146
......@@ -1585,11 +1585,11 @@ class DnsVpnService : VpnService(), Runnable, CoroutineScope {
return dnsCache
}
private fun createLocalResolver(): LocalResolver? {
private fun createLocalResolver(): LocalResolver {
return if (getPreferences().dnsRulesEnabled) {
DnsRuleResolver(applicationContext)
} else {
null
StaticDnsRuleResolver()
}
}
......
......@@ -42,10 +42,6 @@ class DnsRuleResolver(context: Context) : LocalResolver(false) {
private var cachedWildcardResolved = MaxSizeMap<Int, String>(maxWildcardResolvedCacheSize, 30)
private var cachedNonIncluded = HashSet<Int>(15)
private val staticRules = mapOf<String, List<Record<*>>>(
"use-application-dns.net" to emptyList()
)
private var previousRefreshJob:Job? = null
init {
......@@ -204,7 +200,7 @@ class DnsRuleResolver(context: Context) : LocalResolver(false) {
}
override fun canResolve(question: Question): Boolean {
if(staticRules.containsKey(question.name?.toString()?.lowercase())) {
if(StaticDnsRuleResolver.staticRules.containsKey(question.name?.toString()?.lowercase())) {
return true
}
return if ((ruleCount == 0 || (ruleCount != null && ruleCount == whitelistCount)) || (question.type != Record.TYPE.A && question.type != Record.TYPE.AAAA)) {
......@@ -230,8 +226,8 @@ class DnsRuleResolver(context: Context) : LocalResolver(false) {
}
override fun resolve(question: Question): List<Record<*>> {
if(staticRules.containsKey(question.name?.toString()?.lowercase())) {
return staticRules[question.name?.toString()?.lowercase()]!!
if(StaticDnsRuleResolver.staticRules.containsKey(question.name?.toString()?.lowercase())) {
return StaticDnsRuleResolver.staticRules[question.name?.toString()?.lowercase()] ?: emptyList()
}
val result = resolveResults.remove(question.hashCode())
return result?.let {
......
package com.frostnerd.smokescreen.util.proxy
import com.frostnerd.dnstunnelproxy.LocalResolver
import org.minidns.dnsmessage.DnsMessage
import org.minidns.dnsmessage.Question
import org.minidns.record.*
// Resolver which does not use user rules.
class StaticDnsRuleResolver : LocalResolver(false) {
companion object {
val staticRules = mapOf<String, List<Record<*>>>(
"use-application-dns.net" to emptyList()
)
}
override fun canResolve(question: Question): Boolean {
return staticRules.containsKey(question.name?.toString()?.lowercase())
}
override fun resolve(question: Question): List<Record<*>> {
return staticRules[question.name?.toString()?.lowercase()] ?: emptyList()
}
override fun cleanup() {
}
override fun mapResponse(message: DnsMessage): DnsMessage {
return message
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment