📄 trtrackerserverprocessortcp.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: TRTrackerServerProcessorTCP.java
package org.gudy.azureus2.core3.tracker.server.impl.tcp;
import com.aelitis.azureus.core.dht.netcoords.DHTNetworkPositionManager;
import com.aelitis.azureus.core.util.HTTPUtils;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.GZIPOutputStream;
import org.bouncycastle.util.encoders.Base64;
import org.gudy.azureus2.core3.tracker.server.TRTrackerServerException;
import org.gudy.azureus2.core3.tracker.server.impl.*;
import org.gudy.azureus2.core3.util.*;
// Referenced classes of package org.gudy.azureus2.core3.tracker.server.impl.tcp:
// TRTrackerServerTCP
public abstract class TRTrackerServerProcessorTCP extends TRTrackerServerProcessor
{
protected static final int SOCKET_TIMEOUT = 5000;
protected static final char CR = 13;
protected static final char FF = 10;
protected static final String NL = "\r\n";
private static final String lc_azureus_name = "Azureus".toLowerCase();
protected static final byte HTTP_RESPONSE_START[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nServer: Azureus 4.2.0.0\r\nConnection: close\r\nContent-Length: ".getBytes();
protected static final byte HTTP_RESPONSE_XML_START[] = "HTTP/1.1 200 OK\r\nContent-Type: text/xml; charset=\"utf-8\"\r\nServer: Azureus 4.2.0.0\r\nConnection: close\r\nContent-Length: ".getBytes();
protected static final byte HTTP_RESPONSE_END_GZIP[] = "\r\nContent-Encoding: gzip\r\n\r\n".getBytes();
protected static final byte HTTP_RESPONSE_END_NOGZIP[] = "\r\n\r\n".getBytes();
private TRTrackerServerTCP server;
private String server_url;
private boolean disable_timeouts;
protected TRTrackerServerProcessorTCP(TRTrackerServerTCP _server)
{
disable_timeouts = false;
server = _server;
server_url = (new StringBuilder()).append(server.isSSL() ? "https" : "http").append("://").append(UrlUtils.convertIPV6Host(server.getHost())).append(":").append(server.getPort()).toString();
}
protected boolean areTimeoutsDisabled()
{
return disable_timeouts;
}
protected void setTimeoutsDisabled(boolean d)
{
disable_timeouts = d;
}
protected TRTrackerServerTCP getServer()
{
return server;
}
protected void processRequest(String input_header, String lowercase_input_header, String url_path, InetSocketAddress client_address, boolean announce_and_scrape_only, InputStream is, OutputStream os,
AsyncController async)
throws IOException
{
String str;
int request_type;
str = url_path;
request_type = -1;
Map root;
TRTrackerServerTorrentImpl specific_torrent;
boolean gzip_reply;
boolean xml_output;
root = null;
specific_torrent = null;
gzip_reply = false;
xml_output = false;
String redirect;
String user;
if (str.startsWith("/announce?"))
{
request_type = 1;
str = str.substring(10);
break MISSING_BLOCK_LABEL_288;
}
if (str.startsWith("/scrape?"))
{
request_type = 2;
str = str.substring(8);
break MISSING_BLOCK_LABEL_288;
}
if (str.equals("/scrape"))
{
request_type = 3;
str = "";
break MISSING_BLOCK_LABEL_288;
}
if (str.startsWith("/query?"))
{
request_type = 4;
str = str.substring(7);
break MISSING_BLOCK_LABEL_288;
}
redirect = TRTrackerServerImpl.redirect_on_not_found;
if (announce_and_scrape_only)
{
if (redirect.length() == 0)
throw new Exception("Tracker only supports announce and scrape functions");
break MISSING_BLOCK_LABEL_212;
}
setTaskState("external request");
disable_timeouts = true;
user = doAuthentication(url_path, input_header, os, false);
if (user == null)
{
setTaskState("final os flush");
os.flush();
return;
}
if (handleExternalRequest(client_address, user, str, input_header, is, os, async))
{
setTaskState("final os flush");
os.flush();
return;
}
if (redirect.length() > 0)
os.write((new StringBuilder()).append("HTTP/1.1 301 Moved Permanently\r\nLocation: ").append(redirect).append("\r\n").append("\r\n").toString().getBytes());
else
os.write("HTTP/1.1 404 Not Found\r\n\r\nPage not found.\r\n".getBytes());
os.flush();
setTaskState("final os flush");
os.flush();
return;
if (doAuthentication(url_path, input_header, os, true) == null)
{
setTaskState("final os flush");
os.flush();
return;
}
int enc_pos = lowercase_input_header.indexOf("accept-encoding:");
if (enc_pos != -1)
{
int e_pos = input_header.indexOf("\r\n", enc_pos);
if (e_pos != -1)
{
if (enc_pos > 0)
{
char c = lowercase_input_header.charAt(enc_pos - 1);
if (c != '\n' && c != ' ')
enc_pos = -1;
}
if (enc_pos != -1)
{
String accept_encoding = lowercase_input_header.substring(enc_pos + 16, e_pos);
gzip_reply = HTTPUtils.canGZIP(accept_encoding);
}
}
}
setTaskState("decoding announce/scrape");
int pos = 0;
byte hash[] = null;
List hash_list = null;
String link = null;
HashWrapper peer_id = null;
int tcp_port = 0;
String event = null;
long uploaded = 0L;
long downloaded = 0L;
long left = 0L;
int num_want = -1;
boolean no_peer_id = false;
byte compact_mode = 0;
String key = null;
byte crypto_level = 0;
int crypto_port = 0;
int udp_port = 0;
int http_port = 0;
int az_ver = 0;
boolean stop_to_queue = false;
String scrape_flags = null;
int up_speed = 0;
boolean hide = false;
com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition network_position = null;
String real_ip_address = client_address.getAddress().getHostAddress();
String client_ip_address = real_ip_address;
int p1;
do
{
if (pos >= str.length())
break;
p1 = str.indexOf('&', pos);
String token;
if (p1 == -1)
{
token = str.substring(pos);
} else
{
token = str.substring(pos, p1);
pos = p1 + 1;
}
int p2 = token.indexOf('=');
if (p2 == -1)
throw new Exception("format invalid");
String lhs = token.substring(0, p2).toLowerCase();
String rhs = URLDecoder.decode(token.substring(p2 + 1), "ISO-8859-1");
if (lhs.equals("info_hash"))
{
byte b[] = rhs.getBytes("ISO-8859-1");
if (hash == null)
{
hash = b;
} else
{
if (hash_list == null)
{
hash_list = new ArrayList();
hash_list.add(hash);
}
hash_list.add(b);
}
} else
if (lhs.equals("peer_id"))
peer_id = new HashWrapper(rhs.getBytes("ISO-8859-1"));
else
if (lhs.equals("no_peer_id"))
no_peer_id = rhs.equals("1");
else
if (lhs.equals("compact"))
{
if (server.isCompactEnabled() && rhs.equals("1") && compact_mode == 0)
compact_mode = 1;
} else
if (lhs.equals("key"))
{
if (server.isKeyEnabled())
key = rhs;
} else
if (lhs.equals("port"))
tcp_port = Integer.parseInt(rhs);
else
if (lhs.equals("event"))
event = rhs;
else
if (lhs.equals("ip"))
{
if (!HostNameToIPResolver.isNonDNSName(rhs))
{
for (int i = 0; i < rhs.length(); i++)
{
char c = rhs.charAt(i);
if (c != '.' && c != ':' && !Character.isDigit(c))
throw new Exception("IP override address must be resolved by the client");
}
try
{
rhs = HostNameToIPResolver.syncResolve(rhs).getHostAddress();
}
catch (UnknownHostException e)
{
throw new Exception("IP override address must be resolved by the client");
}
}
client_ip_address = rhs;
} else
if (lhs.equals("uploaded"))
uploaded = Long.parseLong(rhs);
else
if (lhs.equals("downloaded"))
downloaded = Long.parseLong(rhs);
else
if (lhs.equals("left"))
left = Long.parseLong(rhs);
else
if (lhs.equals("numwant"))
num_want = Integer.parseInt(rhs);
else
if (lhs.equals("azudp"))
{
udp_port = Integer.parseInt(rhs);
compact_mode = 2;
} else
if (lhs.equals("azhttp"))
http_port = Integer.parseInt(rhs);
else
if (lhs.equals("azver"))
az_ver = Integer.parseInt(rhs);
else
if (lhs.equals("supportcrypto"))
{
if (crypto_level == 0)
crypto_level = 1;
} else
if (lhs.equals("requirecrypto"))
crypto_level = 2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -