Blocklist: small improvements

This commit is contained in:
M66B 2021-06-19 19:06:29 +02:00
parent 7018723618
commit 0c9b6baf5a
1 changed files with 13 additions and 10 deletions

View File

@ -48,6 +48,9 @@ public class DnsBlockList {
// https://www.spamcop.net/fom-serve/cache/291.html // https://www.spamcop.net/fom-serve/cache/291.html
"127.0.0.2" "127.0.0.2"
}) })
//new BlockList("b.barracudacentral.org", new String[]{
// // https://www.barracudacentral.org/rbl/how-to-use
//})
)); ));
private static final long CACHE_EXPIRY_AFTER = 3600 * 1000L; // milliseconds private static final long CACHE_EXPIRY_AFTER = 3600 * 1000L; // milliseconds
@ -87,10 +90,10 @@ public class DnsBlockList {
private static boolean isJunk(String domain, BlockList blocklist) { private static boolean isJunk(String domain, BlockList blocklist) {
try { try {
long before = new Date().getTime(); long start = new Date().getTime();
InetAddress[] addresses = InetAddress.getAllByName(domain); InetAddress[] addresses = InetAddress.getAllByName(domain);
Log.i("isJunk resolved=" + domain + long elapsed = new Date().getTime() - start;
" elapse=" + (new Date().getTime() - before) + " ms"); Log.i("isJunk resolved=" + domain + " elapse=" + elapsed + " ms");
for (InetAddress addr : addresses) for (InetAddress addr : addresses)
try { try {
StringBuilder lookup = new StringBuilder(); StringBuilder lookup = new StringBuilder();
@ -109,7 +112,7 @@ public class DnsBlockList {
lookup.append(blocklist.address); lookup.append(blocklist.address);
long start = new Date().getTime(); start = new Date().getTime();
InetAddress result; InetAddress result;
try { try {
// Possibly blocked // Possibly blocked
@ -118,22 +121,22 @@ public class DnsBlockList {
// Not blocked // Not blocked
result = null; result = null;
} }
long elapsed = new Date().getTime() - start; elapsed = new Date().getTime() - start;
if (result != null) { if (result != null && blocklist.responses.length > 0) {
boolean found = false; boolean blocked = false;
for (InetAddress response : blocklist.responses) for (InetAddress response : blocklist.responses)
if (response.equals(result)) { if (response.equals(result)) {
found = true; blocked = true;
break; break;
} }
if (!found) { if (!blocked) {
result = null;
Log.w("isJunk" + Log.w("isJunk" +
" addr=" + addr + " addr=" + addr +
" lookup=" + lookup + " lookup=" + lookup +
" result=" + result + " result=" + result +
" elapsed=" + elapsed); " elapsed=" + elapsed);
result = null;
} }
} }