DNS improvements

This commit is contained in:
M66B 2024-01-31 07:50:46 +01:00
parent ab02df1106
commit aca987277e
1 changed files with 18 additions and 11 deletions

View File

@ -199,19 +199,19 @@ public class DnsHelper {
client.setDataSource(new AuthoritiveDataSource(client.getDataSource())); client.setDataSource(new AuthoritiveDataSource(client.getDataSource()));
// https://github.com/MiniDNS/minidns/issues/102 // https://github.com/MiniDNS/minidns/issues/102
if (client instanceof DnssecClient && dns_custom) if (client instanceof DnssecClient)
((DnssecClient) client).setUseHardcodedDnsServers(false); ((DnssecClient) client).setUseHardcodedDnsServers(false);
Log.i("DNS query name=" + type + ":" + name); ResolverResult<? extends Data> data;
ResolverResult<? extends Data> data = resolver.resolve(name, clazz);
Log.i("DNS resolved name=" + type + ":" + name +
" success=" + data.wasSuccessful() +
" rcode=" + data.getResponseCode());
try { try {
Log.i("DNS query name=" + type + ":" + name);
data = resolver.resolve(name, clazz);
Log.i("DNS resolved name=" + type + ":" + name +
" success=" + data.wasSuccessful() +
" rcode=" + data.getResponseCode());
data.throwIfErrorResponse(); data.throwIfErrorResponse();
} catch (Throwable ex) { } catch (Throwable ex) {
Log.i("DNS error message=" + ex.getMessage()); Log.w("DNS error message=" + ex.getMessage());
throw ex; throw ex;
} }
@ -275,7 +275,9 @@ public class DnsHelper {
} else if (answer instanceof AAAA) { } else if (answer instanceof AAAA) {
AAAA aaaa = (AAAA) answer; AAAA aaaa = (AAAA) answer;
result.add(new DnsRecord(aaaa.getInetAddress())); result.add(new DnsRecord(aaaa.getInetAddress()));
} } else
Log.e("DNS unexpected record=" +
(answer == null ? null : answer.getClass().getName()));
} }
} }
@ -391,10 +393,15 @@ public class DnsHelper {
} }
static List<String> getDnsServers(Context context) { static List<String> getDnsServers(Context context) {
List<String> result = new ArrayList<>(_getDnsServers(context));
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean dns_custom = prefs.getBoolean("dns_custom", false);
String dns_extra = prefs.getString("dns_extra", null); String dns_extra = prefs.getString("dns_extra", null);
List<String> result = new ArrayList<>();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || dns_custom)
result.addAll(_getDnsServers(context));
if (!TextUtils.isEmpty(dns_extra)) { if (!TextUtils.isEmpty(dns_extra)) {
String[] extras = dns_extra.replaceAll("\\s+", "").split(","); String[] extras = dns_extra.replaceAll("\\s+", "").split(",");
for (String extra : extras) for (String extra : extras)