blob: 92f70492ff8a63b2029363cca9718f56b5e63d20 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package se.leap.bitmaskclient;
import org.jetbrains.annotations.NotNull;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Dns;
import se.leap.bitmaskclient.utils.IPAddress;
class DnsResolver implements Dns {
@Override
public List<InetAddress> lookup(@NotNull String hostname) throws UnknownHostException {
try {
return Dns.SYSTEM.lookup(hostname);
} catch (UnknownHostException e) {
ProviderObservable observable = ProviderObservable.getInstance();
Provider currentProvider;
if (observable.getProviderForDns() != null) {
currentProvider = observable.getProviderForDns();
} else {
currentProvider = observable.getCurrentProvider();
}
String ip = currentProvider.getIpForHostname(hostname);
if (!ip.isEmpty()) {
ArrayList<InetAddress> addresses = new ArrayList<>();
addresses.add(InetAddress.getByAddress(hostname, IPAddress.asBytes(ip)));
return addresses;
} else {
throw new UnknownHostException("Hostname " + hostname + " not found");
}
}
}
}
|