📄 trtrackerbtannouncerimpl.java
字号:
autoUDPprobeEvery <<= 1;
else
TRTrackerUtils.setUDPProbeResult(reqUrl, false);
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, 0, (new StringBuilder()).append("redirection of http announce [").append(tracker_url[0]).append("] to udp failed, will retry in ").append(autoUDPprobeEvery).append(" announces").toString()));
} else
if (failure_reason == null && udp_probe)
{
TRTrackerUtils.setUDPProbeResult(reqUrl, true);
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, 0, (new StringBuilder()).append("redirection of http announce [").append(tracker_url[0]).append("] to udp successful").toString()));
autoUDPprobeEvery = 1;
}
}
announceCount++;
if (udpAnnounceURL == null)
failure_reason = announceHTTP(tracker_url, reqUrl, message);
if (message.size() <= 0)
break MISSING_BLOCK_LABEL_458;
abyte0 = message.toByteArray();
TorrentUtils.setTLSTorrentHash(null);
return abyte0;
label0:
{
try
{
if (failure_reason == null)
failure_reason = "No data received from tracker";
}
catch (SSLException e)
{
if (i == 0)
{
if (SESecurityManager.installServerCertificates(reqUrl) != null)
break label0;
failure_reason = exceptionToString(e);
} else
{
failure_reason = exceptionToString(e);
}
}
catch (Exception e)
{
failure_reason = exceptionToString(e);
}
if (failure_reason != null && failure_reason.indexOf("401") != -1)
failure_reason = "Tracker authentication failed";
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, 3, (new StringBuilder()).append("Exception while processing the Tracker Request for ").append(reqUrl).append(": ").append(failure_reason).toString()));
throw new Exception(failure_reason);
}
i++;
goto _L1
throw new Exception("Internal Error: should never get here");
Exception exception;
exception;
TorrentUtils.setTLSTorrentHash(null);
throw exception;
}
protected String announceHTTP(URL tracker_url[], URL reqUrl, ByteArrayOutputStream message)
throws IOException
{
String failure_reason;
HttpURLConnection con;
TRTrackerUtils.checkForBlacklistedURLs(reqUrl);
reqUrl = TRTrackerUtils.adjustURLForHosting(reqUrl);
reqUrl = AddressUtils.adjustURL(reqUrl);
failure_reason = null;
Properties http_properties = new Properties();
http_properties.put("URL", reqUrl);
try
{
ClientIDManagerImpl.getSingleton().generateHTTPProperties(http_properties);
}
catch (ClientIDException e)
{
throw new IOException(e.getMessage());
}
reqUrl = (URL)http_properties.get("URL");
if (reqUrl.getProtocol().equalsIgnoreCase("https"))
{
HttpsURLConnection ssl_con = (HttpsURLConnection)reqUrl.openConnection();
ssl_con.setHostnameVerifier(new HostnameVerifier() {
final TRTrackerBTAnnouncerImpl this$0;
public boolean verify(String host, SSLSession session)
{
return true;
}
{
this$0 = TRTrackerBTAnnouncerImpl.this;
super();
}
});
con = ssl_con;
} else
{
con = (HttpURLConnection)reqUrl.openConnection();
}
String user_agent = (String)http_properties.get("User-Agent");
if (user_agent != null)
con.setRequestProperty("User-Agent", user_agent);
con.setRequestProperty("Connection", "close");
con.addRequestProperty("Accept-Encoding", "gzip");
InputStream is;
con.connect();
is = null;
int content_length;
byte data[];
int num_read;
is = con.getInputStream();
String resulting_url_str = con.getURL().toString();
if (!reqUrl.toString().equals(resulting_url_str))
{
String marker = "permredirect=1";
int pos = resulting_url_str.indexOf(marker);
if (pos != -1)
{
pos--;
try
{
URL redirect_url = new URL(resulting_url_str.substring(0, pos));
tracker_url[0] = redirect_url;
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
}
String encoding = con.getHeaderField("content-encoding");
boolean gzip = encoding != null && encoding.equalsIgnoreCase("gzip");
if (gzip)
is = new GZIPInputStream(is);
content_length = -1;
data = new byte[1024];
num_read = 0;
_L2:
if (content_length > 0 && num_read >= content_length)
break MISSING_BLOCK_LABEL_494;
int len = is.read(data);
if (len > 0)
{
message.write(data, 0, len);
num_read += len;
if (num_read > 0x20000)
{
message.reset();
throw new Exception("Tracker response invalid (too large)");
}
} else
{
if (len != 0)
break MISSING_BLOCK_LABEL_494;
Thread.sleep(20L);
}
if (true) goto _L2; else goto _L1
_L1:
Exception e;
e;
if (Logger.isEnabled())
{
Logger.log(new LogEvent(torrent, LOGID, "Exception while Requesting Tracker", e));
Logger.log(new LogEvent(torrent, LOGID, 3, (new StringBuilder()).append("Message Received was : ").append(message).toString()));
}
failure_reason = exceptionToString(e);
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, (new StringBuilder()).append("Tracker Announcer [").append(lastUsedUrl).append("] has received : ").append(message).toString()));
Exception e;
if (is != null)
{
try
{
is.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
is = null;
}
break MISSING_BLOCK_LABEL_625;
e;
failure_reason = exceptionToString(e);
if (is != null)
{
try
{
is.close();
}
// Misplaced declaration of an exception variable
catch (Exception e) { }
is = null;
}
break MISSING_BLOCK_LABEL_625;
Exception exception;
exception;
if (is != null)
{
try
{
is.close();
}
catch (Exception e) { }
is = null;
}
throw exception;
con.disconnect();
break MISSING_BLOCK_LABEL_643;
Exception exception1;
exception1;
con.disconnect();
throw exception1;
return failure_reason;
}
protected String announceUDP(URL reqUrl, ByteArrayOutputStream message, boolean is_probe)
throws IOException
{
long timeout;
String failure_reason;
java.net.PasswordAuthentication auth;
timeout = is_probe ? 10000L : 30000L;
reqUrl = TRTrackerUtils.adjustURLForHosting(reqUrl);
failure_reason = null;
auth = null;
PRUDPPacketHandler handler;
InetSocketAddress destination;
int retry_loop;
if (!is_probe && UrlUtils.queryHasParameter(reqUrl.getQuery(), "auth", false))
auth = SESecurityManager.getPasswordAuthentication(UDP_REALM, reqUrl);
handler = PRUDPPacketHandlerFactory.getHandler(UDPNetworkManager.getSingleton().getUDPNonDataListeningPortNumber());
destination = new InetSocketAddress(reqUrl.getHost(), reqUrl.getPort() != -1 ? reqUrl.getPort() : 80);
retry_loop = 0;
_L7:
if (retry_loop >= 1)
break MISSING_BLOCK_LABEL_1076;
PRUDPPacket reply;
PRUDPPacket connect_request = new PRUDPPacketRequestConnect();
reply = handler.sendAndReceive(auth, connect_request, destination, timeout);
if (reply.getAction() != 0) goto _L2; else goto _L1
_L1:
PRUDPPacketReplyConnect connect_reply = (PRUDPPacketReplyConnect)reply;
long my_connection = connect_reply.getConnectionId();
com.aelitis.net.udp.uc.PRUDPPacketRequest request;
if (PRUDPPacketTracker.VERSION == 1)
{
PRUDPPacketRequestAnnounce announce_request = new PRUDPPacketRequestAnnounce(my_connection);
request = announce_request;
String url_str = reqUrl.toString();
int p_pos = url_str.indexOf("?");
url_str = url_str.substring(p_pos + 1);
String event_str = getURLParam(url_str, "event");
int event = 0;
if (event_str != null)
if (event_str.equals("started"))
event = 2;
else
if (event_str.equals("stopped"))
event = 3;
else
if (event_str.equals("completed"))
event = 1;
String ip_str = getURLParam(url_str, "ip");
int ip = 0;
if (ip_str != null)
ip = PRHelpers.addressToInt(ip_str);
announce_request.setDetails(torrent_hash.getBytes(), tracker_peer_id, getLongURLParam(url_str, "downloaded"), event, ip, (int)getLongURLParam(url_str, "numwant"), getLongURLParam(url_str, "left"), (short)(int)getLongURLParam(url_str, "port"), getLongURLParam(url_str, "uploaded"));
} else
{
PRUDPPacketRequestAnnounce2 announce_request = new PRUDPPacketRequestAnnounce2(my_connection);
request = announce_request;
String url_str = reqUrl.toString();
int p_pos = url_str.indexOf("?");
url_str = url_str.substring(p_pos + 1);
String event_str = getURLParam(url_str, "event");
int event = 0;
if (event_str != null)
if (event_str.equals("started"))
event = 2;
else
if (event_str.equals("stopped"))
event = 3;
else
if (event_str.equals("completed"))
event = 1;
String ip_str = getURLParam(url_str, "ip");
int ip = 0;
if (ip_str != null)
ip = PRHelpers.addressToInt(ip_str);
announce_request.setDetails(torrent_hash.getBytes(), tracker_peer_id, getLongURLParam(url_str, "downloaded"), event, ip, key_udp, (int)getLongURLParam(url_str, "numwant"), getLongURLParam(url_str, "left"), (short)(int)getLongURLParam(url_str, "port"), getLongURLParam(url_str, "uploaded"));
}
reply = handler.sendAndReceive(auth, request, destination);
if (reply.getAction() != 1) goto _L4; else goto _L3
_L3:
if (auth != null)
SESecurityManager.setPasswordAuthenticationOutcome(UDP_REALM, reqUrl, true);
if (PRUDPPacketTracker.VERSION != 1) goto _L6; else goto _L5
_L5:
PRUDPPacketReplyAnnounce announce_reply = (PRUDPPacketReplyAnnounce)reply;
Map map = new HashMap();
map.put("interval", new Long(announce_reply.getInterval()));
int addresses[] = announce_reply.getAddresses();
short ports[] = announce_reply.getPorts();
List peers = new ArrayList();
map.put("peers", peers);
for (int i = 0; i < addresses.length; i++)
{
Map peer = new HashMap();
peers.add(peer);
peer.put("ip", PRHelpers.intToAddress(addresses[i]).getBytes());
peer.put("port", new Long(ports[i]));
}
byte data[] = BEncoder.encode(map);
message.write(data);
return null;
_L6:
PRUDPPacketReplyAnnounce2 announce_reply = (PRUDPPacketReplyAnnounce2)reply;
Map map = new HashMap();
map.put("interval", new Long(announce_reply.getInterval()));
int addresses[] = announce_reply.getAddresses();
short ports[] = announce_reply.getPorts();
map.put("complete", new Long(announce_reply.getSeeders()));
map.put("incomplete", new Long(announce_reply.getLeechers()));
List peers = new ArrayList();
map.put("peers", peers);
for (int i = 0; i < addresses.length; i++)
{
Map peer = new HashMap();
peers.add(peer);
peer.put("ip", PRHelpers.intToAddress(addresses[i]).getBytes());
peer.put("port", new Long(ports[i]));
}
byte data[] = BEncoder.encode(map);
message.write(data);
return null;
_L4:
failure_reason = ((PRUDPPacketReplyError)reply).getMessage();
break MISSING_BLOCK_LABEL_1057;
_L2:
failure_reason = ((PRUDPPacketReplyError)reply).getMessage();
break MISSING_BLOCK_LABEL_1057;
PRUDPPacketHandlerException e;
e;
if (e.getMessage() == null || e.getMessage().indexOf("timed out") == -1)
throw e;
retry_loop++;
goto _L7
Throwable e;
e;
failure_reason = exceptionToString(e);
if (auth != null)
SESecurityManager.setPasswordAuthenticationOutcome(UDP_REALM, reqUrl, false);
return failure_reason;
}
protected long getLongURLParam(String url, String param)
{
String val = getURLParam(url, param);
if (val == null)
return 0L;
else
return Long.parseLong(val);
}
protected String getURLParam(String url, String param)
{
int p1 = url.indexOf((new StringBuilder()).append(param).append("=").toString());
if (p1 == -1)
return null;
int p2 = url.indexOf("&", p1);
if (p2 == -1)
return url.substring(p1 + param.length() + 1);
else
return url.substring(p1 + param.length() + 1, p2);
}
protected String exceptionToString(Throwable e)
{
String class_name = e.getClass().getName();
int pos = class_name.lastIndexOf('.');
if (pos != -1)
class_name = class_name.substring(pos + 1);
String str = (new StringBuilder()).append(class_name).append(":").append(e.getMessage()).toString();
if (str.indexOf("timed out") != -1)
str = "timeout";
return str;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -