From f8e8d089f7c7008288668f4f4cb053ea48d5df2f Mon Sep 17 00:00:00 2001 From: DrKLO Date: Fri, 22 May 2015 04:45:27 +0300 Subject: [PATCH] Bug fixes --- TMessagesProj/build.gradle | 2 +- .../org/telegram/messenger/BuildVars.java | 2 +- .../messenger/ConnectionsManager.java | 30 +++++++++++++++++-- .../org/telegram/messenger/TcpConnection.java | 23 +++++++------- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 1b53792de..13f028064 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -81,7 +81,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 22 - versionCode 541 + versionCode 542 versionName "2.9.1" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java index 93df93753..38c0e7ca0 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/BuildVars.java @@ -10,7 +10,7 @@ package org.telegram.messenger; public class BuildVars { public static boolean DEBUG_VERSION = false; - public static int BUILD_VERSION = 541; + public static int BUILD_VERSION = 542; public static int APP_ID = 0; //obtain your own APP_ID at https://core.telegram.org/api/obtaining_api_id public static String APP_HASH = ""; //obtain your own APP_HASH at https://core.telegram.org/api/obtaining_api_id public static String HOCKEY_APP_HASH = "your-hockeyapp-api-key-here"; diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java index e18873d8b..658896f07 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/ConnectionsManager.java @@ -526,12 +526,38 @@ public class ConnectionsManager implements Action.ActionDelegate, TcpConnection. @SuppressLint("NewApi") protected static boolean useIpv6Address() { - if (Build.VERSION.SDK_INT < 19) { + if (BuildVars.DEBUG_VERSION && Build.VERSION.SDK_INT >= 19) { + try { + NetworkInterface networkInterface; + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + networkInterface = networkInterfaces.nextElement(); + if (!networkInterface.isUp() || networkInterface.isLoopback() || networkInterface.getInterfaceAddresses().isEmpty()) { + continue; + } + FileLog.e("tmessages", "valid interface: " + networkInterface); + for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) { + InetAddress inetAddress = address.getAddress(); + if (BuildVars.DEBUG_VERSION) { + FileLog.e("tmessages", "address: " + inetAddress.getHostAddress()); + } + if (inetAddress.isLinkLocalAddress() || inetAddress.isLoopbackAddress() || inetAddress.isMulticastAddress()) { + continue; + } + if (BuildVars.DEBUG_VERSION) { + FileLog.e("tmessages", "address is good"); + } + } + } + } catch (Throwable e) { + FileLog.e("tmessages", e); + } + } + if (Build.VERSION.SDK_INT < 50) { return false; } try { NetworkInterface networkInterface; - Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { networkInterface = networkInterfaces.nextElement(); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java b/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java index 8901c1750..217e63fb1 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/TcpConnection.java @@ -107,25 +107,28 @@ public class TcpConnection extends ConnectionContext { connectionState = TcpConnectionState.TcpConnectionStageConnecting; try { Datacenter datacenter = ConnectionsManager.getInstance().datacenterWithId(datacenterId); + boolean isIpv6 = ConnectionsManager.useIpv6Address(); if (transportRequestClass == RPCRequest.RPCRequestClassDownloadMedia) { currentAddressFlag = 2; - if (ConnectionsManager.useIpv6Address()) { - currentAddressFlag |= 1; - } - hostAddress = datacenter.getCurrentAddress(currentAddressFlag); + hostAddress = datacenter.getCurrentAddress(currentAddressFlag | (isIpv6 ? 1 : 0)); if (hostAddress == null) { currentAddressFlag = 0; - if (ConnectionsManager.useIpv6Address()) { - currentAddressFlag |= 1; - } + hostAddress = datacenter.getCurrentAddress(currentAddressFlag | (isIpv6 ? 1 : 0)); + } + if (hostAddress == null && isIpv6) { + currentAddressFlag = 2; hostAddress = datacenter.getCurrentAddress(currentAddressFlag); + if (hostAddress == null) { + currentAddressFlag = 0; + hostAddress = datacenter.getCurrentAddress(currentAddressFlag); + } } } else { currentAddressFlag = 0; - if (ConnectionsManager.useIpv6Address()) { - currentAddressFlag |= 1; + hostAddress = datacenter.getCurrentAddress(currentAddressFlag | (isIpv6 ? 1 : 0)); + if (isIpv6 && hostAddress == null) { + hostAddress = datacenter.getCurrentAddress(currentAddressFlag); } - hostAddress = datacenter.getCurrentAddress(currentAddressFlag); } hostPort = datacenter.getCurrentPort(currentAddressFlag);