mirror of https://github.com/NekoX-Dev/NekoX.git
内部http请求走DOH
This commit is contained in:
parent
097950c720
commit
4cdee72d6c
|
@ -787,7 +787,7 @@ public class ConnectionsManager extends BaseController {
|
|||
|
||||
protected ResolvedDomain doInBackground(Void... voids) {
|
||||
|
||||
InetAddress[] result = DnsFactory.Companion.lookUp(currentHostName);
|
||||
InetAddress[] result = DnsFactory.Companion.lookup(currentHostName).toArray(new InetAddress[0]);
|
||||
|
||||
return new ResolvedDomain(result, 10 * 60 * 1000L);
|
||||
|
||||
|
|
|
@ -140,7 +140,6 @@ import java.util.HashMap;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
import tw.nekomimi.nekogram.NekoXConfig;
|
||||
import tw.nekomimi.nekogram.utils.ProxyUtil;
|
||||
|
||||
public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, DialogsActivity.DialogsActivityDelegate, SharedMediaLayout.SharedMediaPreloaderDelegate {
|
||||
|
@ -2077,8 +2076,10 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
|
|||
if (!MessagesController.getInstance(currentAccount).checkCanOpenChat(args, ProfileActivity.this)) {
|
||||
return;
|
||||
}
|
||||
NotificationCenter.getInstance(currentAccount).removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
|
||||
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
|
||||
if (!AndroidUtilities.isTablet()) {
|
||||
NotificationCenter.getInstance(currentAccount).removeObserver(ProfileActivity.this, NotificationCenter.closeChats);
|
||||
NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.closeChats);
|
||||
}
|
||||
presentFragment(new ChatActivity(args), true);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -111,13 +111,13 @@ public class SubInfo implements Mappable {
|
|||
|
||||
errors.append(e.getKey()).append(": ");
|
||||
|
||||
if (StrUtil.isBlank(e.getValue().getMessage())) {
|
||||
errors.append(e.getValue().getClass().getSimpleName());
|
||||
|
||||
if (!StrUtil.isBlank(e.getValue().getMessage())) {
|
||||
|
||||
errors.append(" ( ");
|
||||
errors.append(e.getValue().getMessage());
|
||||
|
||||
} else {
|
||||
|
||||
errors.append(e.getValue().getClass().getSimpleName());
|
||||
errors.append(" )");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ object AlertUtil {
|
|||
|
||||
@JvmOverloads
|
||||
@JvmStatic
|
||||
fun showProgress(ctx: Context,text: String = LocaleController.getString("",R.string.Loading)): AlertDialog {
|
||||
fun showProgress(ctx: Context,text: String = LocaleController.getString("Loading",R.string.Loading)): AlertDialog {
|
||||
|
||||
return AlertDialog.Builder(ctx,1).apply {
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package tw.nekomimi.nekogram.utils
|
||||
|
||||
import okhttp3.Dns
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.dnsoverhttps.DnsOverHttps
|
||||
import org.telegram.tgnet.ConnectionsManager
|
||||
import org.xbill.DNS.DohResolver
|
||||
|
@ -9,54 +11,55 @@ import org.xbill.DNS.TXTRecord
|
|||
import org.xbill.DNS.Type
|
||||
import java.net.InetAddress
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
open class DnsFactory {
|
||||
open class DnsFactory : Dns {
|
||||
|
||||
companion object : DnsFactory() {
|
||||
|
||||
init {
|
||||
|
||||
addProvider("https://mozilla.cloudflare-dns.com/dns-query")
|
||||
addProvider("https://cloudflare-dns.com/dns-query")
|
||||
addProvider("https://dns.google/dns-query")
|
||||
addProvider("https://dns.twnic.tw/dns-query")
|
||||
addProvider("https://dns.adguard.com/dns-query")
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val providers = LinkedList<DnsOverHttps>()
|
||||
val dnsJavaProviders = LinkedList<DohResolver>()
|
||||
val dnsJavaProviders = LinkedList<DohResolver>()
|
||||
|
||||
val client = OkHttpClient.Builder().connectTimeout(3,TimeUnit.SECONDS).build()
|
||||
|
||||
fun addProvider(url: String) {
|
||||
|
||||
providers.add(DnsOverHttps.Builder()
|
||||
.client(HttpUtil.okHttpClient)
|
||||
.client(client)
|
||||
.url(url.toHttpUrl())
|
||||
.includeIPv6(ConnectionsManager.useIpv6Address())
|
||||
.build())
|
||||
|
||||
}
|
||||
|
||||
fun lookUp(host: String) : Array<InetAddress> {
|
||||
override fun lookup(hostname: String): List<InetAddress> {
|
||||
|
||||
providers.forEach {
|
||||
|
||||
runCatching {
|
||||
|
||||
return it.lookup(host).toTypedArray()
|
||||
return it.lookup(hostname)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return arrayOf()
|
||||
return Dns.SYSTEM.lookup(hostname)
|
||||
|
||||
}
|
||||
|
||||
fun getTxts(domain: String) : ArrayList<String> {
|
||||
fun getTxts(domain: String): ArrayList<String> {
|
||||
|
||||
val results = ArrayList<String>()
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ fun Request.Builder.applyUserAgent(): Request.Builder {
|
|||
object HttpUtil {
|
||||
|
||||
@JvmField
|
||||
val okHttpClient = OkHttpClient().newBuilder().connectTimeout(5, TimeUnit.SECONDS).build()
|
||||
val okHttpClient = OkHttpClient().newBuilder().dns(DnsFactory).connectTimeout(5, TimeUnit.SECONDS).build()
|
||||
|
||||
@JvmStatic
|
||||
val okHttpClientWithCurrProxy: OkHttpClient
|
||||
|
|
Loading…
Reference in New Issue