音动传媒 v1.0.0版本的 MD5 值为:8cd03520875fdd82ead6ec2d7c106791
以下内容为反编译后的 NetworkConfig.java 源代码,内容仅作参考
package im.eamjdbutov.tgnet;
import android.text.TextUtils;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.security.yunceng.android.sdk.YunCeng;
import com.google.android.exoplayer2.util.Log;
import com.google.gson.Gson;
import com.king.zxing.util.LogUtils;
import com.qiniu.android.dns.DnsManager;
import com.qiniu.android.dns.IResolver;
import com.qiniu.android.dns.NetworkInfo;
import com.qiniu.android.dns.Record;
import com.qiniu.android.dns.dns.DohResolver;
import im.eamjdbutov.messenger.AndroidUtilities;
import im.eamjdbutov.messenger.BuildVars;
import im.eamjdbutov.messenger.FileLog;
import im.eamjdbutov.messenger.NotificationCenter;
import im.eamjdbutov.messenger.UserConfig;
import im.eamjdbutov.ui.hui.friendscircle.okhttphelper.MD5Utils;
import im.eamjdbutov.ui.hui.friendscircle_v1.view.expandTextView.model.UUIDUtils;
import im.eamjdbutov.ui.utils.AesUtils;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import org.webrtc.utils.RecvStatsReportCommon;
public class NetworkConfig {
private static final int ENV_LOCAL = 1000;
private static final int ENV_LOCAL_TEST = 1001;
private static final int ENV_NONE = 0;
private static final int ENV_ONLINE = 1002;
private static final int ENV_ONLINE_GREY = 1004;
private static final int ENV_ONLINE_TEST = 1003;
private DnsManager dnsManager;
private boolean inited;
private boolean inited_doh;
private boolean initing;
private boolean initing_doh;
public static final String[] IP_DEFALUT_ONLINE = {"King.gz.ushemoapz.com", "40002"};
public static final String[] HOST = {"https://47.57.5.105/dns-query", "https://8.212.16.14/dns-query"};
private static volatile NetworkConfig sInstance = new NetworkConfig();
public static int serverIndex = 1;
private String dohDomain = "cn.bw516.com";
private ArrayList<NetBean> connInfos = new ArrayList<>();
private int sCurrentConnection = -1;
protected int currentAccount = UserConfig.selectedAccount;
private boolean start = true;
@Retention(RetentionPolicy.SOURCE)
private @interface EnvNode {
}
public static NetworkConfig getInstance() {
NetworkConfig localInstance = sInstance;
if (localInstance == null) {
synchronized (NetworkConfig.class) {
localInstance = sInstance;
if (localInstance == null) {
NetworkConfig networkConfig = new NetworkConfig();
localInstance = networkConfig;
sInstance = networkConfig;
}
}
}
return localInstance;
}
public static void setIpPortDefaultAddress() {
String[] cfg;
if (BuildVars.RELEASE_VERSION) {
cfg = IP_DEFALUT_ONLINE;
} else {
cfg = getInstance().initNetconfig(1001);
}
if (BuildVars.DEBUG_VERSION) {
StringBuilder sb = new StringBuilder();
sb.append("java NetWorkConfig setIpPortDefaultAddress ===> address = ");
sb.append(cfg != null ? Arrays.toString(cfg) : "null");
Log.i("connection", sb.toString());
}
if (cfg != null && cfg[0] != null && cfg[1] != null) {
for (int a = 0; a < 3; a++) {
ConnectionsManager.native_setIpPortDefaultAddress(a, cfg[0], Integer.parseInt(cfg[1]));
}
}
}
private NetworkConfig() {
}
public void applyNetconfig(int instance) {
String[] cfg;
if (BuildVars.RELEASE_VERSION) {
cfg = initNetconfig(1002);
} else {
cfg = initNetconfig(1002);
}
if (BuildVars.DEBUG_VERSION) {
StringBuilder sb = new StringBuilder();
sb.append("java NetWorkConfig applyNetconfig ===> address = ");
sb.append(cfg != null ? Arrays.toString(cfg) : "null");
Log.i("connection", sb.toString());
}
if (cfg != null && cfg[0] != null && cfg[1] != null) {
ConnectionsManager.getInstance(instance).applyDatacenterAddress(2, cfg[0], Integer.parseInt(cfg[1]));
ConnectionsManager.getInstance(instance).resumeNetworkMaybe();
}
}
public void initUrlDOH() {
this.initing_doh = true;
try {
try {
IResolver[] resolvers = {new DohResolver(HOST[0]), new DohResolver(HOST[1])};
DnsManager dnsManager = new DnsManager(NetworkInfo.normal, resolvers);
this.dnsManager = dnsManager;
Record[] records = dnsManager.queryRecords(this.dohDomain);
String recordsStr = JSONObject.toJSONString(records);
LogUtils.e("doh获取成功====" + recordsStr);
if (records != null && records.length > 0) {
for (Record record : records) {
String ipAddress = record.value;
NetBean netBean = new NetBean(null, ipAddress, IP_DEFALUT_ONLINE[1]);
this.connInfos.add(netBean);
}
}
this.inited_doh = true;
this.sCurrentConnection = -1;
setServer2();
} catch (Exception e) {
e.printStackTrace();
}
} finally {
this.initing_doh = false;
}
}
private void setServer2() {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NetworkConfig.this.lambda$setServer2$0$NetworkConfig();
}
});
}
public void lambda$setServer2$0$NetworkConfig() {
String server2 = "server 2";
if (this.inited) {
server2 = "oss+server 2";
}
if (this.inited_doh) {
server2 = "doh+" + server2;
}
if (serverIndex < 3) {
NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.getBackupIpStatus, server2);
}
}
private String[] initNetconfig(int node) {
if (this.start) {
this.start = false;
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public final void run() {
NetworkConfig.this.lambda$initNetconfig$1$NetworkConfig();
}
});
}
switch (node) {
case 1000:
return new String[]{"47.104.243.76", "31537"};
case 1001:
return new String[]{"192.168.1.184", "31443"};
case 1002:
String[] address = initRemoteNetconfig();
if (address == null || address.length != 2 || TextUtils.isEmpty(address[0]) || TextUtils.isEmpty(address[1])) {
return IP_DEFALUT_ONLINE;
}
return address;
case 1003:
return new String[]{"183.230.11.65", "55555"};
case 1004:
return new String[]{"36.255.220.245", "31443"};
default:
return null;
}
}
public void lambda$initNetconfig$1$NetworkConfig() {
NotificationCenter.getInstance(this.currentAccount).postNotificationName(NotificationCenter.getBackupIpStatus, "server 1");
}
private String[] initRemoteNetconfig() {
synchronized (UUIDUtils.getUuid()) {
if (this.inited) {
return selecteRemoteConnInfo();
}
if (this.initing) {
return null;
}
initRemoteConnInfos();
return selecteRemoteConnInfo();
}
}
private synchronized String[] selecteRemoteConnInfo() {
if (this.connInfos.size() == 0) {
return null;
}
if (this.sCurrentConnection == -1) {
this.sCurrentConnection = 0;
}
NetBean netBean = this.connInfos.get(this.sCurrentConnection);
LogUtils.e("连接信息====" + new Gson().toJson(this.connInfos));
if (this.sCurrentConnection != this.connInfos.size() - 1) {
this.sCurrentConnection++;
return new String[]{netBean.getdDomain(), netBean.getdPort()};
}
this.sCurrentConnection = -1;
this.inited = false;
this.inited_doh = false;
this.connInfos = new ArrayList<>();
return null;
}
private synchronized void initRemoteConnInfos() {
getOssUrl(false);
}
private void getOssUrl(Boolean isBei) {
Throwable th;
InputStream httpConnectionStream;
SimpleDateFormat dateFormat;
String format;
this.initing = true;
InputStream httpConnectionStream2 = null;
ByteArrayOutputStream bos = null;
Date date = new Date();
SimpleDateFormat dateFormat2 = new SimpleDateFormat("YYYYMMdd");
String format2 = dateFormat2.format(date);
StringBuilder sb = new StringBuilder();
sb.append(BuildVars.ENABLE_SETTING);
sb.append(format2);
sb.append(isBei.booleanValue() ? "1" : "");
String md5_tong = MD5Utils.getMD5String(sb.toString());
String md5_txt = MD5Utils.getMD5String(BuildVars.ENABLE_SETTING + format2 + RecvStatsReportCommon.sdk_platform);
String md5_url = "https://" + md5_tong + ".oss-accelerate.aliyuncs.com/" + md5_txt + ".txt";
System.out.println("环境时间:" + BuildVars.ENABLE_SETTING + format2 + isBei);
PrintStream printStream = System.out;
StringBuilder sb2 = new StringBuilder();
sb2.append("oss==>:");
sb2.append(md5_url);
printStream.println(sb2.toString());
try {
try {
URL url = new URL(md5_url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.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");
conn.setRequestMethod("GET");
conn.setReadTimeout(5000);
conn.setConnectTimeout(5000);
conn.connect();
if (conn.getResponseCode() == 200) {
httpConnectionStream2 = conn.getInputStream();
int len = 0;
try {
byte[] bytes = new byte[1024];
bos = new ByteArrayOutputStream();
while (true) {
try {
int len2 = httpConnectionStream2.read(bytes);
httpConnectionStream = httpConnectionStream2;
if (len2 == -1) {
break;
}
len = len2;
try {
bos.write(bytes, 0, len);
httpConnectionStream2 = httpConnectionStream;
} catch (Exception e) {
e = e;
httpConnectionStream2 = httpConnectionStream;
FileLog.e(e);
if (!isBei.booleanValue()) {
}
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos == null) {
}
} catch (Throwable th2) {
th = th2;
httpConnectionStream2 = httpConnectionStream;
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos != null) {
}
}
} catch (Exception e2) {
e = e2;
} catch (Throwable th3) {
th = th3;
}
}
try {
String txt = new String(bos.toByteArray());
byte[] rets = AesUtils.decryptYunceng(txt);
String retStr = new String(rets);
StringBuilder sb3 = new StringBuilder();
try {
sb3.append("oss获取成功====");
sb3.append(retStr);
LogUtils.e(sb3.toString());
String[] arrConn = retStr.split(",", 3);
int i = 0;
while (true) {
String retStr2 = retStr;
if (i >= arrConn.length) {
break;
}
String connInfo = arrConn[i];
Date date2 = date;
try {
String[] arrConn2 = arrConn;
if (i != arrConn.length - 1) {
String[] split = connInfo.split(LogUtils.COLON, 2);
dateFormat = dateFormat2;
try {
format = format2;
try {
NetBean netBean = new NetBean(null, split[0], split[1]);
this.connInfos.add(netBean);
} catch (Exception e3) {
e = e3;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
FileLog.e(e);
if (!isBei.booleanValue()) {
}
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos == null) {
}
} catch (Throwable th4) {
th = th4;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos != null) {
}
}
} catch (Exception e4) {
e = e4;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
FileLog.e(e);
if (!isBei.booleanValue()) {
}
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos == null) {
}
} catch (Throwable th5) {
th = th5;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
this.initing = false;
if (httpConnectionStream2 != null) {
}
if (bos != null) {
}
}
} else {
dateFormat = dateFormat2;
format = format2;
String[] split2 = connInfo.split("#", 3);
NetBean netBean2 = new NetBean(split2[0], split2[1], split2[2]);
this.connInfos.add(netBean2);
}
i++;
retStr = retStr2;
date = date2;
arrConn = arrConn2;
dateFormat2 = dateFormat;
format2 = format;
} catch (Exception e5) {
e = e5;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
} catch (Throwable th6) {
th = th6;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
}
}
this.inited = true;
this.sCurrentConnection = -1;
setServer2();
httpConnectionStream2 = httpConnectionStream;
bos = bos;
} catch (Exception e6) {
e = e6;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
} catch (Throwable th7) {
th = th7;
httpConnectionStream2 = httpConnectionStream;
bos = bos;
}
} catch (Exception e7) {
e = e7;
httpConnectionStream2 = httpConnectionStream;
} catch (Throwable th8) {
th = th8;
httpConnectionStream2 = httpConnectionStream;
}
} catch (Exception e8) {
e = e8;
} catch (Throwable th9) {
th = th9;
}
} else {
try {
try {
if (!isBei.booleanValue()) {
getOssUrl(true);
}
} catch (Exception e9) {
e = e9;
FileLog.e(e);
if (!isBei.booleanValue()) {
getOssUrl(true);
}
this.initing = false;
if (httpConnectionStream2 != null) {
try {
httpConnectionStream2.close();
} catch (Exception e10) {
FileLog.e(e10);
}
}
if (bos == null) {
bos.close();
}
return;
}
} catch (Throwable th10) {
th = th10;
this.initing = false;
if (httpConnectionStream2 != null) {
try {
httpConnectionStream2.close();
} catch (Exception e11) {
FileLog.e(e11);
}
}
if (bos != null) {
throw th;
}
try {
bos.close();
throw th;
} catch (Exception e12) {
FileLog.e(e12);
throw th;
}
}
}
this.initing = false;
if (httpConnectionStream2 != null) {
try {
httpConnectionStream2.close();
} catch (Exception e13) {
FileLog.e(e13);
}
}
} catch (Exception e14) {
FileLog.e(e14);
return;
}
} catch (Exception e15) {
e = e15;
} catch (Throwable th11) {
th = th11;
}
if (bos != null) {
bos.close();
}
}
private String[] getYuncengConfig(String groupName, String dDomain, String dPort) {
StringBuffer ip = new StringBuffer();
StringBuffer port = new StringBuffer();
int ret = YunCeng.getProxyTcpByDomain("Default", groupName, dDomain, dPort, ip, port);
if (ret == 0) {
return new String[]{ip.toString(), port.toString()};
}
FileLog.e("YunCeng get next ip failed: " + ret);
return null;
}
}