速狼加速器 v1.3.05版本的 MD5 值为:16b5e8af5c3774d85c1aa8bd4f624d0b

以下内容为反编译后的 TestWAN.java 源代码,内容仅作参考


package com.lzz.youtu.network;

import com.lzz.youtu.NetworkMonitor.NetWorkMonitorManager;
import com.lzz.youtu.NetworkMonitor.NetworkChangeNotification;
import com.lzz.youtu.VpnService.ConnectBase;
import com.lzz.youtu.data.LogUtils;
import com.lzz.youtu.network.Connection;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestWAN extends ConnectBase implements Runnable, NetWorkMonitorManager.NetWorkStatusChange {
    private static String TAG = "TestWAN";
    private static TestWAN instance = new TestWAN();
    private long lastTime;
    private Thread mThread;
    private NetworkChangeNotification.NetWorkState netWorkState;
    private long stateUpdateTime;
    private boolean isUnobstructed = false;
    private Object resultEvent = new Object();
    private List<DoMainInfo> domain = initialize();
    private AtomicBoolean bTesting = new AtomicBoolean(false);

    @Override
    public void onAvailable(int i) {
    }

    @Override
    public void onCapabilitiesChanged(int i, int i2) {
    }

    @Override
    public void onLost(int i) {
    }

    private List<DoMainInfo> initialize() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new DoMainInfo("www.baidu.com"));
        arrayList.add(new DoMainInfo("www.google.com"));
        return arrayList;
    }

    public void setNetWorkState(int i, boolean z) {
        LogUtils.eLog(TAG, "[setNetWorkState]: [netType]:" + i);
        if (i == 0) {
            this.netWorkState = NetworkChangeNotification.NetWorkState.NONE;
        } else if (i == 1) {
            this.netWorkState = NetworkChangeNotification.NetWorkState.WIFI;
        } else {
            this.netWorkState = NetworkChangeNotification.NetWorkState.CELLULAR;
        }
        if (z) {
            this.stateUpdateTime = System.currentTimeMillis();
        }
        if (this.netWorkState == NetworkChangeNotification.NetWorkState.NONE) {
            this.isUnobstructed = false;
        }
    }

    public void release() {
        Thread thread = this.mThread;
        if (thread != null && thread.isAlive()) {
            this.mThread.interrupt();
        }
        NetWorkMonitorManager.getInstance().unregister(this);
    }

    public static TestWAN getInstance() {
        return instance;
    }

    public void go() {
        NetWorkMonitorManager.getInstance().register(this);
        setNetWorkState(NetWorkMonitorManager.getCurrentNetworkState(), false);
    }

    public boolean GetNetworkState(boolean z) {
        if (z) {
            return GetNetworkState();
        }
        return this.netWorkState != NetworkChangeNotification.NetWorkState.NONE;
    }

    public boolean GetNetworkState() {
        if (this.netWorkState == NetworkChangeNotification.NetWorkState.NONE) {
            return false;
        }
        if (this.bTesting.compareAndSet(false, true)) {
            LogUtils.dLog(TAG, "[GetNetworkState]");
            testWANConnectionWithTCP();
        }
        try {
            synchronized (this.resultEvent) {
                this.resultEvent.wait(3000L);
                this.bTesting.compareAndSet(true, false);
            }
        } catch (InterruptedException unused) {
            this.bTesting.compareAndSet(true, false);
        }
        return this.isUnobstructed;
    }

    @Override
    public void onConnectFinishCallback(Connection.HostInfo hostInfo) {
        ParamContext paramContext = (ParamContext) hostInfo.getContext();
        synchronized (TestWAN.class) {
            this.isUnobstructed = true;
            this.lastTime = paramContext.connectTime;
        }
        hostInfo.close();
        synchronized (this.resultEvent) {
            this.resultEvent.notifyAll();
        }
        LogUtils.eLog(TAG, "[onConnectFinishCallback]: [host]:" + hostInfo.getHost() + "[invalter time]:" + (System.currentTimeMillis() - paramContext.connectTime));
    }

    @Override
    public void onConnectFailCallback(Connection.HostInfo hostInfo, Connection.ConnectionState connectionState) {
        synchronized (TestWAN.class) {
            ParamContext paramContext = (ParamContext) hostInfo.getContext();
            if (paramContext.connectTime > this.lastTime) {
                this.isUnobstructed = false;
                this.lastTime = paramContext.connectTime;
            }
        }
        hostInfo.close();
        LogUtils.eLog(TAG, "[onConnectFailCallback]: [host]:" + hostInfo.getHost() + "[state]:" + connectionState);
    }

    @Override
    public void run() {
        long currentTimeMillis = System.currentTimeMillis();
        Iterator<DoMainInfo> it2 = this.domain.iterator();
        while (it2.hasNext()) {
            testConnection(it2.next(), currentTimeMillis);
        }
    }

    @Override
    public void onNetworkStatusChange(int i) {
        setNetWorkState(i, true);
    }

    public static class DoMainInfo {
        String domain;
        String ip;

        public DoMainInfo(String str) {
            this.domain = str;
        }
    }

    private void testWANConnectionWithTCP() {
        Thread thread = new Thread(this);
        this.mThread = thread;
        thread.start();
    }

    private static void testConnection(final DoMainInfo doMainInfo, long j) {
        if (doMainInfo.ip == null) {
            try {
                Thread thread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            DoMainInfo.this.ip = InetAddress.getByName(DoMainInfo.this.domain).getHostAddress();
                        } catch (UnknownHostException unused) {
                            LogUtils.eLog(TestWAN.TAG, "[testConnection]:  failed ");
                        }
                    }
                });
                thread.start();
                thread.join(1000L);
                thread.interrupt();
            } catch (Exception unused) {
                LogUtils.eLog(TAG, "[testConnection]:  join failed ");
            }
        }
        if (doMainInfo.ip != null) {
            Connection.getInstance().doConnection(doMainInfo.ip, 80, new ParamContext(j), instance);
        }
    }

    private static boolean testWANConnection(List<String> list) {
        Iterator<String> it2 = list.iterator();
        boolean z = false;
        while (it2.hasNext() && !(z = ping(it2.next()))) {
        }
        return z;
    }

    private static boolean ping(String str) {
        boolean z = true;
        try {
            InputStream inputStream = Runtime.getRuntime().exec("ping " + str).getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            Pattern compile = Pattern.compile("\\d+\\.\\d+\\.\\d+\\.\\d+");
            int i = 0;
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null || i >= 3) {
                    break;
                }
                Matcher matcher = compile.matcher(readLine);
                if (matcher.find()) {
                    LogUtils.dLog("TcpCoreService", "[ping]: domain:" + str + ":" + matcher.group(0));
                    break;
                }
                try {
                    i++;
                } catch (Exception unused) {
                    return z;
                }
            }
            z = false;
            inputStream.close();
            inputStreamReader.close();
            bufferedReader.close();
            return z;
        } catch (Exception unused2) {
            return false;
        }
    }

    public static class ParamContext extends ContextBase {
        boolean bSuccess = false;
        long connectTime;

        public ParamContext(long j) {
            this.connectTime = j;
        }
    }
}