⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trhosttorrenthostimpl.java

📁 java 文件下载器。可自定义
💻 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:   TRHostTorrentHostImpl.java

package org.gudy.azureus2.core3.tracker.host.impl;

import java.util.*;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentException;
import org.gudy.azureus2.core3.tracker.host.*;
import org.gudy.azureus2.core3.tracker.server.*;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.tracker.host.impl:
//			TRHostImpl, TRHostPeerHostImpl

public class TRHostTorrentHostImpl
	implements TRHostTorrent
{

	private TRHostImpl host;
	private TRTrackerServer server;
	private TRTrackerServerTorrent server_torrent;
	private TOTorrent torrent;
	private long date_added;
	private int port;
	private List listeners_cow;
	private List removal_listeners;
	private int status;
	private boolean persistent;
	private boolean passive;
	private long sos_uploaded;
	private long sos_downloaded;
	private long sos_bytes_in;
	private long sos_bytes_out;
	private long sos_announce;
	private long sos_scrape;
	private long sos_complete;
	private long last_uploaded;
	private long last_downloaded;
	private long last_bytes_in;
	private long last_bytes_out;
	private long last_announce;
	private long last_scrape;
	private Average average_uploaded;
	private Average average_downloaded;
	private Average average_bytes_in;
	private Average average_bytes_out;
	private Average average_announce;
	private Average average_scrape;
	private boolean disable_reply_caching;
	private HashMap data;
	protected AEMonitor this_mon;

	protected TRHostTorrentHostImpl(TRHostImpl _host, TRTrackerServer _server, TOTorrent _torrent, int _port, long _date_added)
	{
		listeners_cow = new ArrayList();
		removal_listeners = new ArrayList();
		status = 1;
		average_uploaded = Average.getInstance(60000, 600);
		average_downloaded = Average.getInstance(60000, 600);
		average_bytes_in = Average.getInstance(60000, 600);
		average_bytes_out = Average.getInstance(60000, 600);
		average_announce = Average.getInstance(60000, 600);
		average_scrape = Average.getInstance(60000, 600);
		this_mon = new AEMonitor("TRHostTorrentHost");
		host = _host;
		server = _server;
		torrent = _torrent;
		port = _port;
		date_added = _date_added;
	}

	public int getPort()
	{
		return port;
	}

	public void start()
	{
		host.startTorrent(this);
	}

	protected void startSupport()
	{
		this_mon.enter();
		status = 2;
		server_torrent = server.permit("", torrent.getHash(), true);
		if (disable_reply_caching)
			server_torrent.disableCaching();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_88;
		Throwable e;
		e;
		Debug.printStackTrace(e);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_88;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		host.hostTorrentStateChange(this);
		return;
	}

	public void stop()
	{
		host.stopTorrent(this);
	}

	protected void stopSupport()
	{
		this_mon.enter();
		status = 1;
		server.deny(torrent.getHash(), true);
		TRTrackerServerTorrent st = server_torrent;
		TRTrackerServerTorrentStats torrent_stats = st != null ? st.getStats() : null;
		if (torrent_stats != null)
		{
			sos_uploaded = sos_uploaded + torrent_stats.getUploaded();
			sos_downloaded = sos_downloaded + torrent_stats.getDownloaded();
			sos_bytes_in = sos_bytes_in + torrent_stats.getBytesIn();
			sos_bytes_out = sos_bytes_out + torrent_stats.getBytesOut();
			sos_announce = sos_announce + torrent_stats.getAnnounceCount();
			sos_scrape = sos_scrape + torrent_stats.getScrapeCount();
			sos_complete = sos_complete + torrent_stats.getCompletedCount();
			torrent_stats = null;
		}
		last_uploaded = 0L;
		last_downloaded = 0L;
		last_bytes_in = 0L;
		last_bytes_out = 0L;
		last_announce = 0L;
		last_scrape = 0L;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_227;
		Throwable e;
		e;
		Debug.printStackTrace(e);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_227;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		host.hostTorrentStateChange(this);
		return;
	}

	public void remove()
		throws TRHostTorrentRemovalVetoException
	{
		canBeRemoved();
		stop();
		host.remove(this);
	}

	public boolean canBeRemoved()
		throws TRHostTorrentRemovalVetoException
	{
		ArrayList listeners_copy;
		this_mon.enter();
		listeners_copy = new ArrayList(removal_listeners);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_39;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		for (int i = 0; i < listeners_copy.size(); i++)
			((TRHostTorrentWillBeRemovedListener)listeners_copy.get(i)).torrentWillBeRemoved(this);

		return true;
	}

	public int getStatus()
	{
		return status;
	}

	public boolean isPersistent()
	{
		return persistent;
	}

	protected void setPersistent(boolean _persistent)
	{
		persistent = _persistent;
	}

	public boolean isPassive()
	{
		return passive;
	}

	public void setPassive(boolean b)
	{
		passive = b;
	}

	public long getDateAdded()
	{
		return date_added;
	}

	public TOTorrent getTorrent()
	{
		return torrent;
	}

	protected void setTorrent(TOTorrent _torrent)
	{
		torrent = _torrent;
	}

	public TRTrackerServerTorrent getTrackerTorrent()
	{
		return server_torrent;
	}

	public TRHostPeer[] getPeers()
	{
		TRHostPeer res[];
		org.gudy.azureus2.core3.tracker.server.TRTrackerServerPeer peers[] = server.getPeers(torrent.getHash());
		if (peers == null)
			break MISSING_BLOCK_LABEL_66;
		res = new TRHostPeer[peers.length];
		for (int i = 0; i < peers.length; i++)
			res[i] = new TRHostPeerHostImpl(peers[i]);

		return res;
		TOTorrentException e;
		e;
		Debug.printStackTrace(e);
		return new TRHostPeer[0];
	}

	protected TRTrackerServerTorrentStats getStats()
	{
		TRTrackerServerTorrent st = server_torrent;
		if (st != null)
			return st.getStats();
		else
			return null;
	}

	protected void setStartOfDayValues(long _date_added, long completed, long announces, long scrapes, long uploaded, long downloaded, long bytes_in, 
			long bytes_out)
	{
		date_added = _date_added;
		sos_complete = completed;
		sos_announce = announces;
		sos_scrape = scrapes;
		sos_uploaded = uploaded;
		sos_downloaded = downloaded;
		sos_bytes_in = bytes_in;
		sos_bytes_out = bytes_out;
	}

	public int getSeedCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return stats.getSeedCount();
		else
			return 0;
	}

	public int getLeecherCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return stats.getLeecherCount();
		else
			return 0;
	}

	public int getBadNATCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return stats.getBadNATPeerCount();
		else
			return 0;
	}

	protected void updateStats()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
		{
			long current_uploaded = stats.getUploaded();
			long ul_diff = current_uploaded - last_uploaded;
			if (ul_diff < 0L)
				ul_diff = 0L;
			average_uploaded.addValue(ul_diff);
			last_uploaded = current_uploaded;
			long current_downloaded = stats.getDownloaded();
			long dl_diff = current_downloaded - last_downloaded;
			if (dl_diff < 0L)
				dl_diff = 0L;
			average_downloaded.addValue(dl_diff);
			last_downloaded = current_downloaded;
			long current_bytes_in = stats.getBytesIn();
			long bi_diff = current_bytes_in - last_bytes_in;
			if (bi_diff < 0L)
				bi_diff = 0L;
			average_bytes_in.addValue(bi_diff);
			last_bytes_in = current_bytes_in;
			long current_bytes_out = stats.getBytesOut();
			long bo_diff = current_bytes_out - last_bytes_out;
			if (bo_diff < 0L)
				bo_diff = 0L;
			average_bytes_out.addValue(bo_diff);
			last_bytes_out = current_bytes_out;
			long current_announce = stats.getAnnounceCount();
			long an_diff = current_announce - last_announce;
			if (an_diff < 0L)
				an_diff = 0L;
			average_announce.addValue(an_diff);
			last_announce = current_announce;
			long current_scrape = stats.getScrapeCount();
			long sc_diff = current_scrape - last_scrape;
			if (sc_diff < 0L)
				sc_diff = 0L;
			average_scrape.addValue(sc_diff);
			last_scrape = current_scrape;
		}
	}

	protected TRTrackerServer getServer()
	{
		return server;
	}

	public long getTotalUploaded()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_uploaded + stats.getUploaded();
		else
			return sos_uploaded;
	}

	public long getTotalDownloaded()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_downloaded + stats.getDownloaded();
		else
			return sos_downloaded;
	}

	public long getTotalLeft()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return stats.getAmountLeft();
		else
			return 0L;
	}

	public long getTotalBytesIn()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_bytes_in + stats.getBytesIn();
		else
			return sos_bytes_in;
	}

	public long getTotalBytesOut()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_bytes_out + stats.getBytesOut();
		else
			return sos_bytes_out;
	}

	public long getAnnounceCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_announce + stats.getAnnounceCount();
		else
			return sos_announce;
	}

	public long getScrapeCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_scrape + stats.getScrapeCount();
		else
			return sos_scrape;
	}

	public long getCompletedCount()
	{
		TRTrackerServerTorrentStats stats = getStats();
		if (stats != null)
			return sos_complete + stats.getCompletedCount();
		else
			return sos_complete;
	}

	public long getAverageBytesIn()
	{
		return average_bytes_in.getAverage();
	}

	public long getAverageBytesOut()
	{
		return average_bytes_out.getAverage();
	}

	public long getAverageUploaded()
	{
		return average_uploaded.getAverage();
	}

	public long getAverageDownloaded()
	{
		return average_downloaded.getAverage();
	}

	public long getAverageAnnounceCount()
	{
		return average_announce.getAverage();
	}

	public long getAverageScrapeCount()
	{
		return average_scrape.getAverage();
	}

	public void disableReplyCaching()
	{
		TRTrackerServerTorrent st = server_torrent;
		disable_reply_caching = true;
		if (st != null)
			st.disableCaching();
	}

	protected void preProcess(TRHostTorrentRequest req)
		throws TRHostException
	{
		List listeners_ref = listeners_cow;
		for (int i = 0; i < listeners_ref.size(); i++)
			try
			{
				((TRHostTorrentListener)listeners_ref.get(i)).preProcess(req);
			}
			catch (TRHostException e)
			{
				throw e;
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

	}

	protected void postProcess(TRHostTorrentRequest req)
		throws TRHostException
	{
		List listeners_ref = listeners_cow;
		for (int i = 0; i < listeners_ref.size(); i++)
			try
			{
				((TRHostTorrentListener)listeners_ref.get(i)).postProcess(req);
			}
			catch (TRHostException e)
			{
				throw e;
			}
			catch (Throwable e)
			{
				Debug.printStackTrace(e);
			}

	}

	public void addListener(TRHostTorrentListener l)
	{
		this_mon.enter();
		List new_listeners = new ArrayList(listeners_cow);
		new_listeners.add(l);
		listeners_cow = new_listeners;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_52;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
		host.torrentListenerRegistered();
		return;
	}

	public void removeListener(TRHostTorrentListener l)
	{
		this_mon.enter();
		List new_listeners = new ArrayList(listeners_cow);
		new_listeners.remove(l);
		listeners_cow = new_listeners;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_52;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void addRemovalListener(TRHostTorrentWillBeRemovedListener l)
	{
		this_mon.enter();
		removal_listeners.add(l);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_38;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void removeRemovalListener(TRHostTorrentWillBeRemovedListener l)
	{
		this_mon.enter();
		removal_listeners.remove(l);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_38;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public Object getData(String key)
	{
		if (data == null)
			return null;
		else
			return data.get(key);
	}

	public void setData(String key, Object value)
	{
		this_mon.enter();
		if (data == null)
			data = new HashMap();
		if (value == null)
		{
			if (data.containsKey(key))
				data.remove(key);
		} else
		{
			data.put(key, value);
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_82;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -