速狼加速器 v1.3.05版本的 MD5 值为:16b5e8af5c3774d85c1aa8bd4f624d0b
以下内容为反编译后的 SpeedTestTask.java 源代码,内容仅作参考
package com.lzz.youtu.network;
import com.lzz.youtu.App;
import com.lzz.youtu.CacheStruct.NodeListInfo;
import com.lzz.youtu.NetworkFramework.ConnectionBase;
import com.lzz.youtu.NetworkFramework.ConnectionEvent;
import com.lzz.youtu.NetworkFramework.ConnectionInterface;
import com.lzz.youtu.NetworkFramework.TcpConnectionY;
import com.lzz.youtu.NetworkMonitor.NetworkChangeNotification;
import com.lzz.youtu.PacketManager.Cmd5Packet;
import com.lzz.youtu.PacketManager.DBPacket;
import com.lzz.youtu.ProtocolManager.ProtocolFactory;
import com.lzz.youtu.ResultData.ResultBase;
import com.lzz.youtu.ResultData.ResultInterface;
import com.lzz.youtu.common.TimeoutControlor;
import com.lzz.youtu.data.GsonUtil;
import com.lzz.youtu.data.LogUtils;
import com.lzz.youtu.network.LocalDataManager;
import com.lzz.youtu.network.SocketTypeTimeout;
import com.lzz.youtu.pojo.NodeDynamicData;
import com.lzz.youtu.pojo.Nodes;
import com.lzz.youtu.pojo.UserInfo;
import com.lzz.youtu.pojo2.Cmd;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class SpeedTestTask implements ConnectionInterface, Runnable, NetworkChangeNotification.NetworkChangeNotify, ResultInterface {
private static SpeedTestTask instance = new SpeedTestTask();
private NetworkChangeNotification.NetWorkState m_networkState;
private boolean reCalcNodeDelay;
public static SpeedTestTask getInstance() {
return instance;
}
public void go() {
this.reCalcNodeDelay = false;
this.m_networkState = NetworkChangeNotification.getInstance().getCurNetworkState();
TimerTaskScheduled.getInstance().addTaskWithOnlyOne(this, 2, TimeUnit.SECONDS);
}
private void updateNodeDelay(SpeedTestContext speedTestContext) {
int parseInt = Integer.parseInt(speedTestContext.node.getId().trim());
int minDelay = speedTestContext.getMinDelay();
LogUtils.dLog(getClass().getName(), "[updateNodeDelay] ip:" + speedTestContext.node.getIp() + " delay:" + minDelay + " name:" + speedTestContext.node.getName());
if (minDelay > 0) {
minDelay += Integer.parseInt(speedTestContext.node.getDelay_add().trim());
}
NodeDynamicData.getInstance().setNodeDelay(parseInt, minDelay, System.currentTimeMillis());
NodeDynamicData.getInstance().setPingDelayFlag(parseInt, minDelay > 0);
}
private boolean sendPacket(TcpConnectionY tcpConnectionY, int i, DBPacket dBPacket, String str) {
boolean z;
if (dBPacket == null) {
LogUtils.eLog(getClass().getName(), "[sendPacket] packet is null");
} else if (!ProtocolFactory.getProtocolInterface(i).serialization(dBPacket)) {
LogUtils.eLog(getClass().getName(), "[sendPacket] serialization is failed");
} else {
dBPacket.setSendTime(System.currentTimeMillis());
TimeoutControlor.getInstance().add(str, dBPacket, SocketTypeTimeout.getInstance().getTimeoutFromSocketType(SocketTypeTimeout.SocketType.SocketSpeed), tcpConnectionY);
tcpConnectionY.send(dBPacket.getSerializaData().array(), i);
z = true;
if (!z) {
tcpConnectionY.close();
updateNodeDelay((SpeedTestContext) tcpConnectionY.getContext());
}
return z;
}
z = false;
if (!z) {
}
return z;
}
public void onTest(TcpConnectionY tcpConnectionY) {
sendPacket(tcpConnectionY, Cmd.CMD5.getValue(), (DBPacket) new Cmd5Packet(this).setSpeedType(Cmd5Packet.SpeedType.ST_GETNODE_INFO).setTag(getClass().getSimpleName()).setProtocol(Cmd.CMD5).builder(), tcpConnectionY.buildConnectionContext());
}
private boolean speedAreaNode(Nodes nodes) {
List<Nodes.NodeBean> list;
long currentTimeMillis = System.currentTimeMillis();
boolean z = false;
if (nodes != null && (list = nodes.getList()) != null && list.size() > 0) {
for (Nodes.NodeBean nodeBean : list) {
int parseInt = Integer.parseInt(nodeBean.getId());
long nodeDelayUpdateTime = NodeDynamicData.getInstance().getNodeDelayUpdateTime(parseInt);
int nodeDelay = NodeDynamicData.getInstance().getNodeDelay(parseInt);
if (!nodeBean.getIp().equals("127.0.0.1")) {
String interval_test_delay = UserInfo.getInstance().getInterval_test_delay();
int parseInt2 = (interval_test_delay == null || interval_test_delay.isEmpty()) ? 1800 : Integer.parseInt(interval_test_delay);
if ((nodeDelay == -1 && currentTimeMillis - nodeDelayUpdateTime > 180000) || nodeDelay == -2 || (currentTimeMillis - nodeDelayUpdateTime) / 1000 > parseInt2) {
LogUtils.dLog(getClass().getName(), "[speedAreaNode]: [host]:" + nodeBean.getIp() + "[name]:" + nodeBean.getName() + "[speedTime]:" + nodeDelayUpdateTime + "[time]:" + currentTimeMillis + "[test_delay]:" + parseInt2 + "[node id]:" + nodeBean.getId() + "[delay]:" + nodeDelay);
new TcpConnectionY(this).connect(nodeBean.getIp(), Integer.parseInt(nodeBean.getPort().trim()), new SpeedTestContext(nodeBean));
z = true;
}
}
}
}
return z;
}
@Override
public void run() {
String country = UserInfo.getInstance().getCountry();
if (country != null) {
boolean z = false;
if (this.reCalcNodeDelay) {
LogUtils.dLog(getClass().getName(), "[run]: on calc node delay");
NodeListInfo.getInstance().calcAreaDelay(!country.equals("cn"));
this.reCalcNodeDelay = false;
LocalDataManager.getInstance().setData(LocalDataManager.CacheKey.NODE_DYNAMIC_DATA, NodeDynamicData.getInstance(), GsonUtil.getInstance().toJsonV1(NodeDynamicData.getInstance()));
}
if (App.getInstance().getScreenState() != App.SCREEN_STATE.ScreenOff && this.m_networkState != NetworkChangeNotification.NetWorkState.NONE) {
if (country.equals("cn")) {
z = speedAreaNode(NodeListInfo.getInstance().getNodesWithArea(country));
} else {
List<Nodes> nodesList = NodeListInfo.getInstance().getNodesList();
if (nodesList != null) {
for (Nodes nodes : nodesList) {
if (!nodes.getArea_code().equals("cn") && speedAreaNode(nodes)) {
z = true;
}
}
}
}
if (z) {
this.reCalcNodeDelay = true;
}
}
}
TimerTaskScheduled.getInstance().addTaskWithOnlyOne(this, 10, TimeUnit.SECONDS);
}
private void onTestFailed(SpeedTestContext speedTestContext) {
if (this.m_networkState != NetworkChangeNotification.NetWorkState.NONE) {
updateNodeDelay(speedTestContext);
}
}
static class AnonymousClass1 {
static final int[] $SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent;
static {
int[] iArr = new int[ConnectionEvent.values().length];
$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent = iArr;
try {
iArr[ConnectionEvent.CE_CONNECT_SUCCESS.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent[ConnectionEvent.CE_SEND_TIMEOUT.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent[ConnectionEvent.CE_CONNECT_TIMEOUT.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent[ConnectionEvent.CE_CONNECT_FAIL.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
try {
$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent[ConnectionEvent.CE_CLOSE.ordinal()] = 5;
} catch (NoSuchFieldError unused5) {
}
}
}
@Override
public void onConnectionEvent(ConnectionEvent connectionEvent, ConnectionBase connectionBase, Object obj) {
TcpConnectionY tcpConnectionY = (TcpConnectionY) connectionBase;
int i = AnonymousClass1.$SwitchMap$com$lzz$youtu$NetworkFramework$ConnectionEvent[connectionEvent.ordinal()];
if (i == 1) {
onTest(tcpConnectionY);
return;
}
if (i == 2) {
tcpConnectionY.close();
} else if (i != 3 && i != 4 && i != 5) {
return;
}
LogUtils.eLog(getClass().getName(), "[onConnectionEvent]: event:" + connectionEvent + " ip:" + tcpConnectionY.getHost() + " id:" + tcpConnectionY.getConnectId());
onTestFailed((SpeedTestContext) tcpConnectionY.getContext());
}
@Override
public void onNetworkChange(NetworkChangeNotification.NetWorkState netWorkState) {
this.m_networkState = netWorkState;
}
@Override
public void onResult(ResultBase resultBase, ConnectionBase connectionBase) {
TcpConnectionY tcpConnectionY = (TcpConnectionY) connectionBase;
SpeedTestContext speedTestContext = (SpeedTestContext) tcpConnectionY.getContext();
if (speedTestContext.setDelay((int) (tcpConnectionY.getLastReviceTime() - tcpConnectionY.getLastSendTime())) >= 3) {
LogUtils.dLog(getClass().getName(), "[onResult] complate test! ip:" + tcpConnectionY.getHost() + " id:" + tcpConnectionY.getConnectId());
updateNodeDelay(speedTestContext);
return;
}
LogUtils.dLog(getClass().getName(), "[onResult] test count:" + speedTestContext.getDelayedCount() + " ip:" + tcpConnectionY.getHost() + " id:" + tcpConnectionY.getConnectId());
onTest(tcpConnectionY);
}
public static class SpeedTestContext extends ContextBase {
private List<Integer> delays = new LinkedList();
private Nodes.NodeBean node;
SpeedTestContext(Nodes.NodeBean nodeBean) {
this.node = nodeBean;
}
int setDelay(int i) {
this.delays.add(Integer.valueOf(i));
return this.delays.size();
}
int getDelayedCount() {
return this.delays.size();
}
int getMinDelay() {
int i = -1;
for (Integer num : this.delays) {
if (num.intValue() != -1) {
if (i == -1) {
i = num.intValue();
} else {
i = Math.min(i, num.intValue());
}
}
}
return i;
}
}
}