package im.guobwnxjuc.tgnet; import android.text.TextUtils; import com.aliyun.security.yunceng.android.sdk.YunCeng; import com.google.android.exoplayer2.util.Log; import com.king.zxing.util.LogUtils; import im.guobwnxjuc.messenger.BuildVars; import im.guobwnxjuc.messenger.FileLog; import im.guobwnxjuc.ui.utils.AesUtils; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; 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 static final String[] IP_DEFALUT_ONLINE = {"Hong.gz.fwef153reg.com", "11153"}; private static volatile NetworkConfig sInstance = new NetworkConfig(); private ArrayList<NetBean> connInfos = new ArrayList<>(); private boolean inited; private boolean initing; private int sCurrentConnection = -1; @Retention(RetentionPolicy.SOURCE) private @interface EnvNode { } public static NetworkConfig getInstance() { NetworkConfig networkConfig = sInstance; if (networkConfig == null) { synchronized (NetworkConfig.class) { networkConfig = sInstance; if (networkConfig == null) { networkConfig = new NetworkConfig(); sInstance = networkConfig; } } } return networkConfig; } public static void setIpPortDefaultAddress() { String[] strArr; if (BuildVars.RELEASE_VERSION) { strArr = IP_DEFALUT_ONLINE; } else { strArr = getInstance().initNetconfig(1001); } if (BuildVars.DEBUG_VERSION) { StringBuilder sb = new StringBuilder(); sb.append("java NetWorkConfig setIpPortDefaultAddress ===> address = "); sb.append(strArr != null ? Arrays.toString(strArr) : "null"); Log.i("connection", sb.toString()); } if (!(strArr == null || strArr[0] == null || strArr[1] == null)) { for (int i = 0; i < 3; i++) { ConnectionsManager.native_setIpPortDefaultAddress(i, strArr[0], Integer.parseInt(strArr[1])); } } } private NetworkConfig() { } /* access modifiers changed from: package-private */ public void applyNetconfig(int i) { String[] strArr; if (BuildVars.RELEASE_VERSION) { strArr = initNetconfig(1002); } else { strArr = initNetconfig(1002); } if (BuildVars.DEBUG_VERSION) { StringBuilder sb = new StringBuilder(); sb.append("java NetWorkConfig applyNetconfig ===> address = "); sb.append(strArr != null ? Arrays.toString(strArr) : "null"); Log.i("connection", sb.toString()); } if (strArr != null && strArr[0] != null && strArr[1] != null) { ConnectionsManager.getInstance(i).applyDatacenterAddress(2, strArr[0], Integer.parseInt(strArr[1])); ConnectionsManager.getInstance(i).resumeNetworkMaybe(); } } private String[] initNetconfig(int i) { switch (i) { case 1000: return new String[]{"192.200.1.117 ", "4445"}; case 1001: return new String[]{"192.168.1.184", "31443"}; case 1002: String[] initRemoteNetconfig = initRemoteNetconfig(); if (initRemoteNetconfig == null || initRemoteNetconfig.length != 2 || TextUtils.isEmpty(initRemoteNetconfig[0]) || TextUtils.isEmpty(initRemoteNetconfig[1])) { return IP_DEFALUT_ONLINE; } return initRemoteNetconfig; case 1003: return new String[]{"192.168.0.0", "55555"}; case 1004: return new String[]{"36.255.220.245", "31443"}; default: return null; } } private String[] initRemoteNetconfig() { 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); if (this.sCurrentConnection != this.connInfos.size() - 1) { this.sCurrentConnection++; return new String[]{netBean.getdDomain(), netBean.getdPort()}; } this.sCurrentConnection = -1; this.inited = false; return getYuncengConfig(netBean.getdName(), netBean.getdDomain(), netBean.getdPort()); } /* JADX WARNING: Removed duplicated region for block: B:48:0x00cb A[SYNTHETIC, Splitter:B:48:0x00cb] */ /* JADX WARNING: Removed duplicated region for block: B:53:0x00d5 A[SYNTHETIC, Splitter:B:53:0x00d5] */ private synchronized void initRemoteConnInfos() { ByteArrayOutputStream byteArrayOutputStream; Throwable th; this.initing = true; InputStream inputStream = null; try { HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("https://mb8x153i6rfgc.oss-accelerate.aliyuncs.com/3m5frrajvq.txt").openConnection(); httpURLConnection.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"); httpURLConnection.setRequestMethod("GET"); httpURLConnection.setReadTimeout(5000); httpURLConnection.setConnectTimeout(5000); httpURLConnection.connect(); if (httpURLConnection.getResponseCode() == 200) { InputStream inputStream2 = httpURLConnection.getInputStream(); try { byte[] bArr = new byte[1024]; byteArrayOutputStream = new ByteArrayOutputStream(); while (true) { try { int read = inputStream2.read(bArr); if (read == -1) { break; } byteArrayOutputStream.write(bArr, 0, read); } catch (Throwable th2) { th = th2; inputStream = inputStream2; try { FileLog.e(th); this.initing = false; this.sCurrentConnection = -1; if (inputStream != null) { } if (byteArrayOutputStream != null) { } return; } catch (Throwable th3) { FileLog.e(th3); } } } String[] split = new String(AesUtils.decryptYunceng(new String(byteArrayOutputStream.toByteArray()))).split(",", 3); for (int i = 0; i < split.length; i++) { String str = split[i]; if (i != split.length - 1) { String[] split2 = str.split(LogUtils.COLON, 2); this.connInfos.add(new NetBean(null, split2[0], split2[1])); } else { String[] split3 = str.split("#", 3); this.connInfos.add(new NetBean(split3[0], split3[1], split3[2])); } } this.inited = true; inputStream = inputStream2; } catch (Throwable th4) { th = th4; byteArrayOutputStream = null; inputStream = inputStream2; FileLog.e(th); this.initing = false; this.sCurrentConnection = -1; if (inputStream != null) { } if (byteArrayOutputStream != null) { } return; } } else { byteArrayOutputStream = null; } this.initing = false; this.sCurrentConnection = -1; if (inputStream != null) { try { inputStream.close(); } catch (Throwable th5) { FileLog.e(th5); } } if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (IOException e) { e = e; } } } catch (Throwable th6) { th = th6; byteArrayOutputStream = null; FileLog.e(th); this.initing = false; this.sCurrentConnection = -1; if (inputStream != null) { try { inputStream.close(); } catch (Throwable th7) { FileLog.e(th7); } } if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (IOException e2) { e = e2; } } return; } return; throw th; FileLog.e(e); return; if (byteArrayOutputStream != null) { try { byteArrayOutputStream.close(); } catch (IOException e3) { FileLog.e(e3); } } throw th; } private String[] getYuncengConfig(String str, String str2, String str3) { StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer2 = new StringBuffer(); int proxyTcpByDomain = YunCeng.getProxyTcpByDomain("Default", str, str2, str3, stringBuffer, stringBuffer2); if (proxyTcpByDomain == 0) { return new String[]{stringBuffer.toString(), stringBuffer2.toString()}; } FileLog.e("YunCeng get next ip failed: " + proxyTcpByDomain); return null; } }