📄 trhostimpl.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: TRHostImpl.java
package org.gudy.azureus2.core3.tracker.host.impl;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentException;
import org.gudy.azureus2.core3.tracker.client.*;
import org.gudy.azureus2.core3.tracker.host.*;
import org.gudy.azureus2.core3.tracker.server.*;
import org.gudy.azureus2.core3.tracker.util.TRTrackerUtils;
import org.gudy.azureus2.core3.util.*;
// Referenced classes of package org.gudy.azureus2.core3.tracker.host.impl:
// TRHostConfigImpl, TRHostExternalTorrent, TRHostPeerHostImpl, TRHostTorrentHostImpl,
// TRHostTorrentPublishImpl, TRHostTorrentRequestImpl
public class TRHostImpl
implements TRHost, TRTrackerAnnouncerFactoryListener, TRTrackerServerListener, TRTrackerServerFactoryListener, TRTrackerServerRequestListener, TRTrackerServerAuthenticationListener
{
private static final LogIDs LOGID;
private static final int URL_DEFAULT_PORT = 80;
private static final int URL_DEFAULT_PORT_SSL = 443;
public static final int STATS_PERIOD_SECS = 60;
private static final int TICK_PERIOD_SECS = 10;
private static final int TICKS_PER_STATS_PERIOD = 6;
private static TRHostImpl singleton;
private static AEMonitor class_mon = new AEMonitor("TRHost:class");
private TRHostConfigImpl config;
private Hashtable server_map;
private List host_torrents;
private Map host_torrent_hash_map;
private Map host_torrent_map;
private Map tracker_client_map;
private static final int LDT_TORRENT_ADDED = 1;
private static final int LDT_TORRENT_REMOVED = 2;
private static final int LDT_TORRENT_CHANGED = 3;
private ListenerManager listeners;
private static boolean host_add_announce_urls;
private List auth_listeners;
private boolean server_factory_listener_added;
protected AEMonitor this_mon;
private volatile boolean closed;
public static TRHost create()
{
TRHostImpl trhostimpl;
class_mon.enter();
if (singleton == null)
singleton = new TRHostImpl();
trhostimpl = singleton;
class_mon.exit();
return trhostimpl;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
protected TRHostImpl()
{
server_map = new Hashtable();
host_torrents = new ArrayList();
host_torrent_hash_map = new HashMap();
host_torrent_map = new HashMap();
tracker_client_map = new HashMap();
listeners = ListenerManager.createAsyncManager("TRHost:ListenDispatcher", new ListenerManagerDispatcher() {
final TRHostImpl this$0;
public void dispatch(Object _listener, int type, Object value)
{
TRHostListener target = (TRHostListener)_listener;
if (type == 1)
target.torrentAdded((TRHostTorrent)value);
else
if (type == 2)
target.torrentRemoved((TRHostTorrent)value);
else
if (type == 3)
target.torrentChanged((TRHostTorrent)value);
}
{
this$0 = TRHostImpl.this;
super();
}
});
auth_listeners = new ArrayList();
this_mon = new AEMonitor("TRHost");
this_mon.enter();
config = new TRHostConfigImpl(this);
TRTrackerAnnouncerFactory.addListener(this);
Thread t = new AEThread("TRHost::stats.loop") {
private int tick_count;
private Set failed_ports;
final TRHostImpl this$0;
public void runSupport()
{
_L2:
URL url_sets[][] = TRTrackerUtils.getAnnounceURLs();
for (int i = 0; i < url_sets.length; i++)
{
URL urls[] = url_sets[i];
for (int j = 0; j < urls.length;)
{
URL url = urls[j];
int port = url.getPort();
if (port == -1)
port = url.getDefaultPort();
String protocol = url.getProtocol().toLowerCase();
try
{
if (protocol.equals("http"))
{
startServer(1, port, false);
continue;
}
if (protocol.equals("udp"))
{
startServer(2, port, false);
continue;
}
if (protocol.equals("https"))
startServer(1, port, true);
else
Debug.out((new StringBuilder()).append("Unknown protocol '").append(protocol).append("'").toString());
continue;
}
catch (Throwable e)
{
Integer port_i = new Integer(port);
if (!failed_ports.contains(port_i))
{
failed_ports.add(port_i);
Logger.log(new LogEvent(TRHostImpl.LOGID, "Tracker Host: failed to start server", e));
}
j++;
}
}
}
Thread.sleep(10000L);
if (closed)
{
tick_count++;
break; /* Loop/switch isn't completed */
}
if (tick_count % 6 != 0)
break MISSING_BLOCK_LABEL_392;
this_mon.enter();
for (int i = 0; i < host_torrents.size(); i++)
{
TRHostTorrent ht = (TRHostTorrent)host_torrents.get(i);
if (ht instanceof TRHostTorrentHostImpl)
((TRHostTorrentHostImpl)ht).updateStats();
else
((TRHostTorrentPublishImpl)ht).updateStats();
}
this_mon.exit();
break MISSING_BLOCK_LABEL_378;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
config.saveConfig(true);
break MISSING_BLOCK_LABEL_403;
config.saveConfig(false);
tick_count++;
if (true) goto _L2; else goto _L1
InterruptedException e;
e;
Debug.printStackTrace(e);
tick_count++;
goto _L1
Exception exception2;
exception2;
tick_count++;
throw exception2;
_L1:
}
{
this$0 = TRHostImpl.this;
super(x0);
tick_count = 0;
failed_ports = new HashSet();
}
};
t.setDaemon(true);
t.setPriority(9);
t.start();
this_mon.exit();
break MISSING_BLOCK_LABEL_169;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void initialise(TRHostTorrentFinder finder)
{
config.loadConfig(finder);
}
public String getName()
{
return "Azureus";
}
public TRHostTorrent hostTorrent(TOTorrent torrent, boolean persistent, boolean passive)
throws TRHostException
{
return addTorrent(torrent, 2, persistent, passive, SystemTime.getCurrentTime());
}
public TRHostTorrent publishTorrent(TOTorrent torrent)
throws TRHostException
{
return addTorrent(torrent, 3, true, false, SystemTime.getCurrentTime());
}
protected TRHostTorrent addTorrent(TOTorrent torrent, int state, boolean persistent, boolean passive, long date_added)
throws TRHostException
{
TRHostTorrent trhosttorrent;
this_mon.enter();
if (persistent && state != 3 && host_add_announce_urls)
addTrackerAnnounce(torrent);
TRHostTorrent ht = lookupHostTorrent(torrent);
if (ht == null)
break MISSING_BLOCK_LABEL_173;
try
{
ht = lookupHostTorrentViaHash(torrent.getHash());
if (ht instanceof TRHostTorrentHostImpl)
{
TRHostTorrentHostImpl hti = (TRHostTorrentHostImpl)ht;
if (hti.getTorrent() != torrent)
{
hti.setTorrent(torrent);
if (persistent && !hti.isPersistent())
hti.setPersistent(true);
if (passive && !hti.isPassive())
hti.setPassive(true);
if (state != 3)
{
startHosting(hti);
if (state == 2)
hti.start();
}
listeners.dispatch(3, ht);
}
}
}
catch (TOTorrentException e)
{
Debug.printStackTrace(e);
}
trhosttorrent = ht;
this_mon.exit();
return trhosttorrent;
TRHostTorrent trhosttorrent1;
int protocol = 1;
int port;
boolean ssl;
if (state == 3)
{
port = COConfigurationManager.getIntParameter("Tracker Port", 6969);
ssl = false;
} else
{
URL announce_url = torrent.getAnnounceURL();
String protocol_str = announce_url.getProtocol();
ssl = protocol_str.equalsIgnoreCase("https");
if (protocol_str.equalsIgnoreCase("udp"))
protocol = 2;
else
if (TorrentUtils.isDecentralised(torrent))
protocol = 3;
boolean force_external = COConfigurationManager.getBooleanParameter("Tracker Port Force External");
port = announce_url.getPort();
if (force_external)
{
String tracker_ip = COConfigurationManager.getStringParameter("Tracker IP", "");
if (tracker_ip.length() > 0 && !announce_url.getHost().equalsIgnoreCase(tracker_ip))
if (ssl)
port = COConfigurationManager.getIntParameter("Tracker Port SSL", 7000);
else
port = COConfigurationManager.getIntParameter("Tracker Port", 6969);
}
if (port == -1)
port = ssl ? 443 : 80;
}
TRTrackerServer server = startServer(protocol, port, ssl);
TRHostTorrent host_torrent;
if (state == 3)
{
TRHostTorrentPublishImpl new_torrent = new TRHostTorrentPublishImpl(this, torrent, date_added);
new_torrent.setPersistent(persistent);
host_torrent = new_torrent;
} else
{
TRHostTorrentHostImpl new_torrent = new TRHostTorrentHostImpl(this, server, torrent, port, date_added);
new_torrent.setPersistent(persistent);
new_torrent.setPassive(passive);
host_torrent = new_torrent;
}
host_torrents.add(host_torrent);
try
{
host_torrent_hash_map.put(new HashWrapper(torrent.getHash()), host_torrent);
}
catch (TOTorrentException e)
{
Debug.printStackTrace(e);
}
host_torrent_map.put(torrent, host_torrent);
if (state != 3)
{
startHosting((TRHostTorrentHostImpl)host_torrent);
if (state == 2)
host_torrent.start();
if (!persistent)
config.recoverStats((TRHostTorrentHostImpl)host_torrent);
}
listeners.dispatch(1, host_torrent);
config.saveRequired();
trhosttorrent1 = host_torrent;
this_mon.exit();
return trhosttorrent1;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
protected TRTrackerServer startServer(int protocol, int port, boolean ssl)
throws TRHostException
{
TRTrackerServer trtrackerserver;
this_mon.enter();
String key = (new StringBuilder()).append("").append(protocol).append(":").append(port).toString();
TRTrackerServer server = (TRTrackerServer)server_map.get(key);
if (server == null)
try
{
if (ssl)
server = TRTrackerServerFactory.createSSL("tracker", protocol, port, true, true);
else
server = TRTrackerServerFactory.create("tracker", protocol, port, true, true);
server_map.put(key, server);
if (auth_listeners.size() > 0)
server.addAuthenticationListener(this);
server.addListener(this);
}
catch (TRTrackerServerException e)
{
throw new TRHostException("startServer failed", e);
}
trtrackerserver = server;
this_mon.exit();
return trtrackerserver;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
protected TRHostTorrent lookupHostTorrent(TOTorrent torrent)
{
if (torrent == null)
return null;
return (TRHostTorrent)host_torrent_hash_map.get(torrent.getHashWrapper());
TOTorrentException e;
e;
Debug.printStackTrace(e);
return null;
}
protected void startHosting(TRHostTorrentHostImpl host_torrent)
{
TOTorrent torrent = host_torrent.getTorrent();
TRTrackerAnnouncer tc = (TRTrackerAnnouncer)tracker_client_map.get(torrent);
if (tc != null)
startHosting(host_torrent, tc);
}
protected void startHosting(TRTrackerAnnouncer tracker_client)
{
TRHostTorrent host_torrent = (TRHostTorrent)host_torrent_map.get(tracker_client.getTorrent());
if (host_torrent instanceof TRHostTorrentHostImpl)
startHosting((TRHostTorrentHostImpl)host_torrent, tracker_client);
}
protected void startHosting(TRHostTorrentHostImpl host_torrent, final TRTrackerAnnouncer tracker_client)
{
final TOTorrent torrent = host_torrent.getTorrent();
URL announce = torrent.getAnnounceURL();
if (host_add_announce_urls)
tracker_client.setIPOverride(announce.getHost());
else
if (TRTrackerUtils.isHosting(announce))
tracker_client.setIPOverride(announce.getHost());
TRTrackerAnnouncerListener listener = new TRTrackerAnnouncerListener() {
final TOTorrent val$torrent;
final TRTrackerAnnouncer val$tracker_client;
final TRHostImpl this$0;
public void receivedTrackerResponse(TRTrackerAnnouncerResponse response)
{
TRTrackerScraperFactory.getSingleton().scrape(torrent, true);
tracker_client.removeListener(this);
break MISSING_BLOCK_LABEL_40;
Exception exception;
exception;
tracker_client.removeListener(this);
throw exception;
}
public void urlChanged(TRTrackerAnnouncer trtrackerannouncer, URL url, URL url1, boolean flag)
{
}
public void urlRefresh()
{
}
{
this$0 = TRHostImpl.this;
torrent = totorrent;
tracker_client = trtrackerannouncer;
super();
}
};
tracker_client.addListener(listener);
tracker_client.refreshListeners();
}
protected void remove(TRHostTorrent host_torrent)
{
this_mon.enter();
if (!host_torrents.contains(host_torrent))
{
this_mon.exit();
return;
}
host_torrents.remove(host_torrent);
TOTorrent torrent = host_torrent.getTorrent();
try
{
host_torrent_hash_map.remove(new HashWrapper(torrent.getHash()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -