Add built-in hosts
This commit is contained in:
1 parent
b95892d3b6
commit
bc5479fa96
8 files changed
+57
-6
No files matched your search
@@ -142,7 +142,7 @@ public class Hosts {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static InetAddress toInetAddress(String host, String ip) {
|
||||
public static InetAddress toInetAddress(String host, String ip) {
|
||||
if (!isValidHost(host)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -952,6 +952,17 @@ public class Settings {
|
||||
return getIntFromStr(KEY_READ_CACHE_SIZE, DEFAULT_READ_CACHE_SIZE);
|
||||
}
|
||||
|
||||
public static final String KEY_BUILT_IN_HOSTS = "built_in_hosts";
|
||||
private static final boolean DEFAULT_BUILT_IN_HOSTS = false;
|
||||
|
||||
public static boolean getBuiltInHosts() {
|
||||
return getBoolean(KEY_BUILT_IN_HOSTS, DEFAULT_BUILT_IN_HOSTS);
|
||||
}
|
||||
|
||||
public static void putBuiltInHosts(boolean value) {
|
||||
putBoolean(KEY_BUILT_IN_HOSTS, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Guide
|
||||
********************/
|
||||
|
||||
@@ -23,15 +23,34 @@ package com.hippo.ehviewer.client;
|
||||
import android.content.Context;
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.Hosts;
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import okhttp3.Dns;
|
||||
|
||||
public class EhDns implements Dns {
|
||||
|
||||
private static final Map<String, InetAddress> builtInHosts;
|
||||
|
||||
static {
|
||||
Map<String, InetAddress> map = new HashMap<>();
|
||||
put(map, "e-hentai.org", "104.24.255.11");
|
||||
put(map, "forums.e-hentai.org", "94.100.18.243");
|
||||
builtInHosts = map;
|
||||
}
|
||||
|
||||
private static void put(Map<String, InetAddress> map, String host, String ip) {
|
||||
InetAddress address = Hosts.toInetAddress(host, ip);
|
||||
if (address != null) {
|
||||
map.put(host, address);
|
||||
}
|
||||
}
|
||||
|
||||
private final Hosts hosts;
|
||||
|
||||
public EhDns(Context context) {
|
||||
@@ -47,6 +66,13 @@ public class EhDns implements Dns {
|
||||
return Collections.singletonList(inetAddress);
|
||||
}
|
||||
|
||||
if (Settings.getBuiltInHosts()) {
|
||||
inetAddress = builtInHosts.get(hostname);
|
||||
if (inetAddress != null) {
|
||||
return Collections.singletonList(inetAddress);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return Arrays.asList(InetAddress.getAllByName(hostname));
|
||||
} catch (NullPointerException e) {
|
||||
|
||||
Reference in new issue
Block a user