4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1
以下内容为反编译后的 a.java 源代码,内容仅作参考
package com.m4399.gamecenter.plugin.main.manager.stnu;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.MessageAttributeException;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.MessageAttributeInterface;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.MessageAttributeParsingException;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.b;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.d;
import com.m4399.gamecenter.plugin.main.manager.stnu.attribute.e;
import com.m4399.gamecenter.plugin.main.manager.stnu.header.MessageHeaderInterface;
import com.m4399.gamecenter.plugin.main.manager.stnu.header.MessageHeaderParsingException;
import com.m4399.gamecenter.plugin.main.manager.stnu.util.UtilityException;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import rx.Observable;
import rx.Subscriber;
import rx.schedulers.Schedulers;
import timber.log.Timber;
public class a {
private InetAddress dgl;
private String dgm = "42.62.3.168";
private int Br = 3478;
private int dgn = 300;
private e dgo = null;
private b dgp = null;
private boolean dgq = true;
private DatagramSocket dgr = null;
private com.m4399.gamecenter.plugin.main.manager.stnu.a.b dgs = null;
public void doDiscovery() {
Observable.create(new Observable.OnSubscribe<com.m4399.gamecenter.plugin.main.manager.stnu.a.b>() {
@Override
public void call(Subscriber<? super com.m4399.gamecenter.plugin.main.manager.stnu.a.b> subscriber) {
try {
a.this.dgl = InetAddress.getByName("0.0.0.0");
subscriber.onNext(a.this.Ra());
subscriber.onCompleted();
} catch (UnknownHostException e) {
subscriber.onError(e);
} catch (Exception e2) {
subscriber.onError(e2);
}
}
}).subscribeOn(Schedulers.newThread()).subscribe((Subscriber) new Subscriber<com.m4399.gamecenter.plugin.main.manager.stnu.a.b>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable th) {
Timber.d("discovery error " + ("Discovery error: " + th.getMessage()), new Object[0]);
}
@Override
public void onNext(com.m4399.gamecenter.plugin.main.manager.stnu.a.b bVar) {
com.m4399.gamecenter.plugin.main.manager.stnu.b.a aVar = new com.m4399.gamecenter.plugin.main.manager.stnu.b.a();
aVar.setDiscoveryInfo(bVar);
aVar.loadData();
}
});
}
public com.m4399.gamecenter.plugin.main.manager.stnu.a.b Ra() throws UtilityException, IOException, MessageAttributeException, MessageHeaderParsingException {
this.dgo = null;
this.dgp = null;
this.dgq = true;
this.dgr = null;
this.dgs = new com.m4399.gamecenter.plugin.main.manager.stnu.a.b(this.dgl);
if (Rb() && Rc() && Rd()) {
Re();
}
this.dgr.close();
return this.dgs;
}
private boolean Rb() throws UtilityException, IOException, MessageAttributeParsingException {
int i = this.dgn;
int i2 = 0;
while (true) {
try {
this.dgr = new DatagramSocket(new InetSocketAddress(this.dgl, 0));
this.dgr.setReuseAddress(true);
this.dgr.connect(InetAddress.getByName(this.dgm), this.Br);
this.dgr.setSoTimeout(i);
if (this.dgr.getLocalSocketAddress() instanceof InetSocketAddress) {
this.dgs.setLocalIP(((InetSocketAddress) this.dgr.getLocalSocketAddress()).getAddress());
}
Timber.d("!!!!! SocketAddress: " + this.dgr.getLocalSocketAddress(), new Object[0]);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a(MessageHeaderInterface.MessageHeaderType.BindingRequest);
aVar.generateTransactionID();
aVar.addMessageAttribute(new com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a());
byte[] bytes = aVar.getBytes();
this.dgr.send(new DatagramPacket(bytes, bytes.length));
Timber.d("Test 1: Binding Request sent.", new Object[0]);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar2 = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a();
while (!aVar2.equalTransactionID(aVar)) {
DatagramPacket datagramPacket = new DatagramPacket(new byte[200], 200);
this.dgr.receive(datagramPacket);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a parseHeader = com.m4399.gamecenter.plugin.main.manager.stnu.header.a.parseHeader(datagramPacket.getData());
parseHeader.parseAttributes(datagramPacket.getData());
aVar2 = parseHeader;
}
this.dgo = (e) aVar2.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.MappedAddress);
this.dgp = (b) aVar2.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.ChangedAddress);
d dVar = (d) aVar2.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.ErrorCode);
if (dVar != null) {
this.dgs.setError(dVar.getResponseCode(), dVar.getReason());
Timber.d("Message header contains an Errorcode message attribute.", new Object[0]);
return false;
}
if (this.dgo != null && this.dgp != null) {
this.dgs.setPublicIP(this.dgo.getAddress().getInetAddress());
if (this.dgo.getPort() == this.dgr.getLocalPort() && this.dgo.getAddress().getInetAddress().equals(this.dgr.getLocalAddress())) {
Timber.d("Node is not natted.", new Object[0]);
this.dgq = false;
} else {
Timber.d("Node is natted.", new Object[0]);
}
return true;
}
this.dgs.setError(700, "The server is sending an incomplete response (Mapped Address and Changed Address message attributes are missing). The client should not retry.");
Timber.d("Response does not contain a Mapped Address or Changed Address message attribute.", new Object[0]);
return false;
} catch (MessageHeaderParsingException e) {
e.printStackTrace();
} catch (SocketTimeoutException unused) {
if (i2 < 7900) {
Timber.d("Test 1: Socket timeout while receiving the response.", new Object[0]);
i2 += i;
i = i2 * 2;
if (i > 1600) {
i = 1600;
}
} else {
Timber.d("Test 1: Socket timeout while receiving the response. Maximum retry limit exceed. Give up.", new Object[0]);
this.dgs.setBlockedUDP();
Timber.d("Node is not capable of UDP communication.", new Object[0]);
return false;
}
}
}
}
private boolean Rc() throws UtilityException, IOException, MessageAttributeException, MessageHeaderParsingException {
int i = this.dgn;
int i2 = 0;
while (true) {
try {
DatagramSocket datagramSocket = new DatagramSocket(new InetSocketAddress(this.dgl, 0));
datagramSocket.connect(InetAddress.getByName(this.dgm), this.Br);
datagramSocket.setSoTimeout(i);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a(MessageHeaderInterface.MessageHeaderType.BindingRequest);
aVar.generateTransactionID();
com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a aVar2 = new com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a();
aVar2.setChangeIP();
aVar2.setChangePort();
aVar.addMessageAttribute(aVar2);
byte[] bytes = aVar.getBytes();
datagramSocket.send(new DatagramPacket(bytes, bytes.length));
Timber.d("Test 2: Binding Request sent.", new Object[0]);
int localPort = datagramSocket.getLocalPort();
InetAddress localAddress = datagramSocket.getLocalAddress();
datagramSocket.close();
DatagramSocket datagramSocket2 = new DatagramSocket(localPort, localAddress);
datagramSocket2.connect(this.dgp.getAddress().getInetAddress(), this.dgp.getPort());
datagramSocket2.setSoTimeout(i);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar3 = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a();
while (!aVar3.equalTransactionID(aVar)) {
DatagramPacket datagramPacket = new DatagramPacket(new byte[200], 200);
datagramSocket2.receive(datagramPacket);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a parseHeader = com.m4399.gamecenter.plugin.main.manager.stnu.header.a.parseHeader(datagramPacket.getData());
parseHeader.parseAttributes(datagramPacket.getData());
aVar3 = parseHeader;
}
d dVar = (d) aVar3.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.ErrorCode);
if (dVar != null) {
this.dgs.setError(dVar.getResponseCode(), dVar.getReason());
Timber.d("Message header contains an Errorcode message attribute.", new Object[0]);
return false;
}
if (!this.dgq) {
this.dgs.setOpenAccess();
Timber.d("Node has open access to the Internet (or, at least the node is behind a full-cone NAT without translation).", new Object[0]);
} else {
this.dgs.setFullCone();
Timber.d("Node is behind a full-cone NAT.", new Object[0]);
}
return false;
} catch (SocketTimeoutException unused) {
if (i2 < 7900) {
Timber.d("Test 2: Socket timeout while receiving the response.", new Object[0]);
i2 += i;
i = i2 * 2;
if (i > 1600) {
i = 1600;
}
} else {
Timber.d("Test 2: Socket timeout while receiving the response. Maximum retry limit exceed. Give up.", new Object[0]);
if (this.dgq) {
return true;
}
this.dgs.setSymmetricUDPFirewall();
Timber.d("Node is behind a symmetric UDP firewall.", new Object[0]);
return false;
}
}
}
}
private boolean Rd() throws UtilityException, IOException, MessageAttributeParsingException, MessageHeaderParsingException {
int i = this.dgn;
int i2 = 0;
while (true) {
try {
this.dgr.connect(this.dgp.getAddress().getInetAddress(), this.dgp.getPort());
this.dgr.setSoTimeout(i);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a(MessageHeaderInterface.MessageHeaderType.BindingRequest);
aVar.generateTransactionID();
aVar.addMessageAttribute(new com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a());
byte[] bytes = aVar.getBytes();
this.dgr.send(new DatagramPacket(bytes, bytes.length));
Timber.d("Test 1 redo with changed address: Binding Request sent.", new Object[0]);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar2 = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a();
while (!aVar2.equalTransactionID(aVar)) {
DatagramPacket datagramPacket = new DatagramPacket(new byte[200], 200);
this.dgr.receive(datagramPacket);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a parseHeader = com.m4399.gamecenter.plugin.main.manager.stnu.header.a.parseHeader(datagramPacket.getData());
parseHeader.parseAttributes(datagramPacket.getData());
aVar2 = parseHeader;
}
e eVar = (e) aVar2.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.MappedAddress);
d dVar = (d) aVar2.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.ErrorCode);
if (dVar != null) {
this.dgs.setError(dVar.getResponseCode(), dVar.getReason());
Timber.d("Message header contains an Errorcode message attribute.", new Object[0]);
return false;
}
if (eVar == null) {
this.dgs.setError(700, "The server is sending an incomplete response (Mapped Address message attribute is missing). The client should not retry.");
Timber.d("Response does not contain a Mapped Address message attribute.", new Object[0]);
return false;
}
if (this.dgo.getPort() == eVar.getPort() && this.dgo.getAddress().getInetAddress().equals(eVar.getAddress().getInetAddress())) {
return true;
}
this.dgs.setSymmetric();
Timber.d("Node is behind a symmetric NAT.", new Object[0]);
return false;
} catch (SocketTimeoutException unused) {
if (i2 < 7900) {
Timber.d("Test 1 redo with changed address: Socket timeout while receiving the response.", new Object[0]);
i2 += i;
i = i2 * 2;
if (i > 1600) {
i = 1600;
}
} else {
Timber.d("Test 1 redo with changed address: Socket timeout while receiving the response. Maximum retry limit exceed. Give up.", new Object[0]);
return false;
}
}
}
}
private void Re() throws UtilityException, IOException, MessageAttributeException, MessageHeaderParsingException {
d dVar;
int i = this.dgn;
int i2 = 0;
while (true) {
try {
DatagramSocket datagramSocket = new DatagramSocket(new InetSocketAddress(this.dgl, 0));
datagramSocket.connect(InetAddress.getByName(this.dgm), this.Br);
datagramSocket.setSoTimeout(i);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a(MessageHeaderInterface.MessageHeaderType.BindingRequest);
aVar.generateTransactionID();
com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a aVar2 = new com.m4399.gamecenter.plugin.main.manager.stnu.attribute.a();
aVar2.setChangePort();
aVar.addMessageAttribute(aVar2);
byte[] bytes = aVar.getBytes();
datagramSocket.send(new DatagramPacket(bytes, bytes.length));
Timber.d("Test 3: Binding Request sent.", new Object[0]);
int localPort = datagramSocket.getLocalPort();
InetAddress localAddress = datagramSocket.getLocalAddress();
datagramSocket.close();
DatagramSocket datagramSocket2 = new DatagramSocket(localPort, localAddress);
datagramSocket2.connect(InetAddress.getByName(this.dgm), this.dgp.getPort());
datagramSocket2.setSoTimeout(i);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a aVar3 = new com.m4399.gamecenter.plugin.main.manager.stnu.header.a();
while (!aVar3.equalTransactionID(aVar)) {
DatagramPacket datagramPacket = new DatagramPacket(new byte[200], 200);
datagramSocket2.receive(datagramPacket);
com.m4399.gamecenter.plugin.main.manager.stnu.header.a parseHeader = com.m4399.gamecenter.plugin.main.manager.stnu.header.a.parseHeader(datagramPacket.getData());
parseHeader.parseAttributes(datagramPacket.getData());
aVar3 = parseHeader;
}
dVar = (d) aVar3.getMessageAttribute(MessageAttributeInterface.MessageAttributeType.ErrorCode);
} catch (SocketTimeoutException unused) {
if (i2 < 7900) {
Timber.d("Test 3: Socket timeout while receiving the response.", new Object[0]);
i2 += i;
i = i2 * 2;
if (i > 1600) {
i = 1600;
}
} else {
Timber.d("Test 3: Socket timeout while receiving the response. Maximum retry limit exceed. Give up.", new Object[0]);
this.dgs.setPortRestrictedCone();
Timber.d("Node is behind a port restricted NAT.", new Object[0]);
return;
}
}
if (dVar != null) {
this.dgs.setError(dVar.getResponseCode(), dVar.getReason());
Timber.d("Message header contains an Errorcode message attribute.", new Object[0]);
return;
} else if (this.dgq) {
this.dgs.setRestrictedCone();
Timber.d("Node is behind a restricted NAT.", new Object[0]);
return;
}
}
}
}