必贏亚洲 v2.5.14版本的 MD5 值为:1cbf75cf2fbc8fc1c58914009bfdab8f
以下内容为反编译后的 CloudflareDns.java 源代码,内容仅作参考
package com.weinet.cashap.pluslibrary.utils;
import android.util.Log;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.ibm.icu.impl.number.Padder;
import com.weinet.cashap.pluslibrary.models.AppSettingModel;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
import okhttp3.Dns;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class CloudflareDns implements Dns {
private static final String API_URL_FORMAT = "https://cloudflare-dns.com/dns-query?name=%s&type=A";
private static final Integer MAX_RETRY_TIMES = 5;
private static final String TAG = "CloudflareDns";
private final OkHttpClient client = new OkHttpClient.Builder().connectTimeout(2, TimeUnit.SECONDS).readTimeout(2, TimeUnit.SECONDS).writeTimeout(2, TimeUnit.SECONDS).build();
private final Map<String, List<InetAddress>> cache = new HashMap();
@Override
public List<InetAddress> lookup(final String str) {
if (this.cache.containsKey(str)) {
Log.i(TAG, "CloudflareDNS lookup " + str + " with cache");
return this.cache.get(str);
}
Log.i(TAG, "CloudflareDNS lookup " + str);
final HttpUrl parse = HttpUrl.parse(String.format(API_URL_FORMAT, str));
final int[] iArr = {0};
final ArrayList arrayList = new ArrayList();
final boolean[] zArr = {false};
final Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
if (iArr[0] >= CloudflareDns.MAX_RETRY_TIMES.intValue() || zArr[0]) {
timer.cancel();
return;
}
try {
Response execute = CloudflareDns.this.client.newCall(new Request.Builder().url(parse).addHeader("Accept", "application/dns-json").build()).execute();
if (execute.isSuccessful()) {
try {
Iterator<JsonElement> it = JsonParser.parseString(execute.body().string()).getAsJsonObject().getAsJsonArray("Answer").iterator();
while (it.hasNext()) {
arrayList.add(InetAddress.getByName(it.next().getAsJsonObject().get("data").getAsString()));
}
zArr[0] = true;
CloudflareDns.this.cache.put(str, arrayList);
} catch (Exception e) {
Log.i(CloudflareDns.TAG, "CloudflareDNS Json Exception " + str + " ||| " + e.getMessage());
}
}
} catch (IOException e2) {
Log.i(CloudflareDns.TAG, "CloudflareDNS IOException " + e2.getMessage());
}
int[] iArr2 = iArr;
iArr2[0] = iArr2[0] + 1;
}
};
timerTask.run();
if (!zArr[0]) {
timer.schedule(timerTask, 1000L, 1000L);
}
if (arrayList.isEmpty() && AppSettingModel.getInstance().getIpList().length > 0) {
String[] ipList = AppSettingModel.getInstance().getIpList();
Log.i(TAG, "Use Backup Ip Node " + APIDns$$ExternalSyntheticBackport0.m(Padder.FALLBACK_PADDING_STRING, ipList) + " retryTimes " + iArr[0]);
for (String str2 : ipList) {
try {
arrayList.add(InetAddress.getByName(str2));
this.cache.put(str, arrayList);
} catch (UnknownHostException e) {
Log.i(TAG, "CloudflareDNS UnknownHostException " + e.getMessage());
}
}
}
return arrayList;
}
}