|
|
|
|
@ -4,8 +4,6 @@ import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
import java.net.InetAddress; |
|
|
|
|
import java.net.UnknownHostException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
|
|
|
|
|
@ -14,7 +12,7 @@ import okhttp3.dnsoverhttps.DnsOverHttps; |
|
|
|
|
|
|
|
|
|
public class OkDns implements Dns { |
|
|
|
|
|
|
|
|
|
private final ConcurrentHashMap<String, List<InetAddress>> map; |
|
|
|
|
private final ConcurrentHashMap<String, String> map; |
|
|
|
|
private DnsOverHttps doh; |
|
|
|
|
|
|
|
|
|
public OkDns() { |
|
|
|
|
@ -35,23 +33,14 @@ public class OkDns implements Dns { |
|
|
|
|
String[] splits = host.split("="); |
|
|
|
|
String oldHost = splits[0]; |
|
|
|
|
String newHost = splits[1]; |
|
|
|
|
if (!map.containsKey(oldHost)) map.put(oldHost, new ArrayList<>()); |
|
|
|
|
map.get(oldHost).addAll(getAllByName(newHost)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<InetAddress> getAllByName(String host) { |
|
|
|
|
try { |
|
|
|
|
return Arrays.asList(InetAddress.getAllByName(host)); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return new ArrayList<>(); |
|
|
|
|
map.put(oldHost, newHost); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@NonNull |
|
|
|
|
@Override |
|
|
|
|
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException { |
|
|
|
|
return map.containsKey(hostname) ? map.get(hostname) : (doh != null ? doh : Dns.SYSTEM).lookup(hostname); |
|
|
|
|
return (doh != null ? doh : Dns.SYSTEM).lookup(map.containsKey(hostname) ? map.get(hostname) : hostname); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|