mirror of
https://github.com/DrKLO/Telegram.git
synced 2024-12-22 14:35:03 +01:00
Update ConnectionsManager.java to improve proxy domain resolving
1- www.google.com with -H header does not resolve to dns.google.com and is causing unnecessary 200ms+ loss when resolving proxy hostnames 2- TTL of 5 minutes for caching is unnecessarily high and causes late refreshing of IPs, causing downtime.
This commit is contained in:
parent
d494ea8cb5
commit
dae9761e1a
1 changed files with 2 additions and 3 deletions
|
@ -833,7 +833,7 @@ public class ConnectionsManager extends BaseController {
|
||||||
public static void getHostByName(String hostName, long address) {
|
public static void getHostByName(String hostName, long address) {
|
||||||
AndroidUtilities.runOnUIThread(() -> {
|
AndroidUtilities.runOnUIThread(() -> {
|
||||||
ResolvedDomain resolvedDomain = dnsCache.get(hostName);
|
ResolvedDomain resolvedDomain = dnsCache.get(hostName);
|
||||||
if (resolvedDomain != null && SystemClock.elapsedRealtime() - resolvedDomain.ttl < 5 * 60 * 1000) {
|
if (resolvedDomain != null && SystemClock.elapsedRealtime() - resolvedDomain.ttl < 1 * 60 * 1000) {
|
||||||
native_onHostNameResolved(hostName, address, resolvedDomain.getAddress());
|
native_onHostNameResolved(hostName, address, resolvedDomain.getAddress());
|
||||||
} else {
|
} else {
|
||||||
ResolveHostByNameTask task = resolvingHostnameTasks.get(hostName);
|
ResolveHostByNameTask task = resolvingHostnameTasks.get(hostName);
|
||||||
|
@ -1060,10 +1060,9 @@ public class ConnectionsManager extends BaseController {
|
||||||
InputStream httpConnectionStream = null;
|
InputStream httpConnectionStream = null;
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
try {
|
try {
|
||||||
URL downloadUrl = new URL("https://www.google.com/resolve?name=" + currentHostName + "&type=A");
|
URL downloadUrl = new URL("https://dns.google.com/resolve?name=" + currentHostName + "&type=A");
|
||||||
URLConnection httpConnection = downloadUrl.openConnection();
|
URLConnection httpConnection = downloadUrl.openConnection();
|
||||||
httpConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1");
|
httpConnection.addRequestProperty("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A5297c Safari/602.1");
|
||||||
httpConnection.addRequestProperty("Host", "dns.google.com");
|
|
||||||
httpConnection.setConnectTimeout(1000);
|
httpConnection.setConnectTimeout(1000);
|
||||||
httpConnection.setReadTimeout(2000);
|
httpConnection.setReadTimeout(2000);
|
||||||
httpConnection.connect();
|
httpConnection.connect();
|
||||||
|
|
Loading…
Reference in a new issue