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

📄 trtrackerserverprocessor.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:   TRTrackerServerProcessor.java

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

import com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition;
import java.io.UnsupportedEncodingException;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.tracker.server.TRTrackerServerException;
import org.gudy.azureus2.core3.tracker.server.TRTrackerServerPeer;
import org.gudy.azureus2.core3.tracker.util.TRTrackerUtils;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.tracker.server.impl:
//			TRTrackerServerImpl, TRTrackerServerTorrentImpl, TRTrackerServerPeerImpl

public abstract class TRTrackerServerProcessor extends ThreadPoolTask
{
	protected static class lightweightPeer
		implements TRTrackerServerPeer
	{

		private String ip;
		private int port;
		private byte peer_id[];

		public long getUploaded()
		{
			return -1L;
		}

		public long getDownloaded()
		{
			return -1L;
		}

		public long getAmountLeft()
		{
			return -1L;
		}

		public String getIP()
		{
			return ip;
		}

		public String getIPRaw()
		{
			return ip;
		}

		public byte getNATStatus()
		{
			return 0;
		}

		public int getTCPPort()
		{
			return port;
		}

		public byte[] getPeerID()
		{
			return peer_id;
		}

		public boolean isBiased()
		{
			return false;
		}

		public void setBiased(boolean flag)
		{
		}

		public void setUserData(Object obj, Object obj1)
		{
		}

		public Object getUserData(Object key)
		{
			return null;
		}

		public int getSecsToLive()
		{
			return -1;
		}

		public Map export()
		{
			return null;
		}

		public lightweightPeer(String _ip, int _port, HashWrapper _peer_id)
		{
			ip = _ip;
			port = _port;
			peer_id = _peer_id != null ? _peer_id.getBytes() : null;
		}
	}


	private static final boolean QUEUE_TEST = false;
	private TRTrackerServerImpl server;
	private long start;
	private int request_type;

	public TRTrackerServerProcessor()
	{
	}

	protected TRTrackerServerTorrentImpl processTrackerRequest(TRTrackerServerImpl _server, String request, Map root_out[], TRTrackerServerPeerImpl peer_out[], int _request_type, byte hashes[][], String link, 
			String scrape_flags, HashWrapper peer_id, boolean no_peer_id, byte compact_mode, String key, String event, boolean stop_to_queue, 
			int port, int udp_port, int http_port, String real_ip_address, String client_ip_address, long downloaded, 
			long uploaded, long left, int num_want, byte crypto_level, byte az_ver, 
			int up_speed, DHTNetworkPosition network_position)
		throws TRTrackerServerException
	{
		server = _server;
		request_type = _request_type;
		if (!server.isReady())
			throw new TRTrackerServerException("Tracker initialising, please wait");
		start = SystemTime.getHighPrecisionCounter();
		boolean ip_override = real_ip_address != client_ip_address;
		boolean loopback = TRTrackerUtils.isLoopback(real_ip_address);
		if (loopback)
			ip_override = false;
		client_ip_address = TRTrackerUtils.adjustHostFromHosting(client_ip_address);
		if (!TRTrackerServerImpl.getAllNetworksSupported())
		{
			String network = AENetworkClassifier.categoriseAddress(client_ip_address);
			String permitted_networks[] = TRTrackerServerImpl.getPermittedNetworks();
			boolean ok = false;
			int i = 0;
			do
			{
				if (i >= permitted_networks.length)
					break;
				if (network == permitted_networks[i])
				{
					ok = true;
					break;
				}
				i++;
			} while (true);
			if (!ok)
				throw new TRTrackerServerException((new StringBuilder()).append("Network '").append(network).append("' not supported").toString());
		}
		TRTrackerServerTorrentImpl torrent = null;
		if (request_type != 3)
		{
			if (request_type == 1)
			{
				if (hashes == null || hashes.length == 0)
					throw new TRTrackerServerException("Hash missing from request ");
				if (hashes.length != 1)
					throw new TRTrackerServerException("Too many hashes for announce");
				byte hash[] = hashes[0];
				torrent = server.getTorrent(hash);
				if (torrent == null)
				{
					if (!COConfigurationManager.getBooleanParameter("Tracker Public Enable"))
						throw new TRTrackerServerException("Torrent unauthorised");
					try
					{
						torrent = (TRTrackerServerTorrentImpl)server.permit(real_ip_address, hash, false);
					}
					catch (Throwable e)
					{
						throw new TRTrackerServerException("Torrent unauthorised", e);
					}
				}
				if (peer_id == null)
					throw new TRTrackerServerException("peer_id missing from request");
				boolean queue_it = stop_to_queue;
				if (queue_it)
				{
					Set biased = server.getBiasedPeers();
					if ((biased == null || !biased.contains(real_ip_address)) && (loopback || ip_override))
						queue_it = false;
				}
				long interval;
				long min_interval;
				if (queue_it)
				{
					interval = server.getScrapeRetryInterval(torrent);
					min_interval = server.getMinScrapeRetryInterval();
				} else
				{
					interval = server.getAnnounceRetryInterval(torrent);
					min_interval = server.getMinAnnounceRetryInterval();
					if (left == 0L)
					{
						long mult = server.getSeedAnnounceIntervalMultiplier();
						interval *= mult;
						min_interval *= mult;
					}
				}
				TRTrackerServerPeerImpl peer = torrent.peerContact(request, event, peer_id, port, udp_port, http_port, crypto_level, az_ver, real_ip_address, client_ip_address, ip_override, loopback, key, uploaded, downloaded, left, interval, up_speed, network_position);
				if (queue_it)
					torrent.peerQueued(client_ip_address, port, udp_port, http_port, crypto_level, az_ver, interval, left == 0L);
				HashMap pre_map = new HashMap();
				TRTrackerServerPeer pre_process_peer = peer;
				if (pre_process_peer == null)
					pre_process_peer = new lightweightPeer(client_ip_address, port, peer_id);
				server.preProcess(pre_process_peer, torrent, request_type, request, pre_map);
				boolean stopped = event != null && event.equalsIgnoreCase("stopped");
				root_out[0] = torrent.exportAnnounceToMap(client_ip_address, pre_map, peer, left > 0L, stopped ? 0 : num_want, interval, min_interval, no_peer_id, compact_mode, crypto_level, network_position);
				peer_out[0] = peer;
			} else
			if (request_type == 4)
			{
				if (link == null)
				{
					if (hashes == null || hashes.length == 0)
						throw new TRTrackerServerException("Hash missing from request ");
					if (hashes.length != 1)
						throw new TRTrackerServerException("Too many hashes for query");
					byte hash[] = hashes[0];
					torrent = server.getTorrent(hash);
				} else
				{
					torrent = server.getTorrent(link);
				}
				if (torrent == null)
					throw new TRTrackerServerException("Torrent unauthorised");
				long interval = server.getAnnounceRetryInterval(torrent);
				root_out[0] = torrent.exportAnnounceToMap(client_ip_address, new HashMap(), null, true, num_want, interval, server.getMinAnnounceRetryInterval(), true, compact_mode, crypto_level, network_position);
			} else
			{
				if (hashes == null || hashes.length == 0)
					throw new TRTrackerServerException("Hash missing from request ");
				boolean local_scrape = client_ip_address.equals("127.0.0.1");
				long max_interval = server.getMinScrapeRetryInterval();
				Map root = new HashMap();
				root_out[0] = root;
				Map files = new ByteEncodedKeyHashMap();
				root.put("files", files);
				char scrape_chars[] = scrape_flags != null ? scrape_flags.toCharArray() : null;
				if (scrape_chars != null && scrape_chars.length != hashes.length)
					scrape_chars = null;
				for (int i = 0; i < hashes.length; i++)
				{
					byte hash[] = hashes[i];
					String str_hash;
					try
					{
						str_hash = new String(hash, "ISO-8859-1");
						if (i > 0 && files.get(str_hash) != null)
							continue;
					}
					catch (UnsupportedEncodingException e)
					{
						continue;
					}
					torrent = server.getTorrent(hash);
					if (torrent == null)
					{
						if (!COConfigurationManager.getBooleanParameter("Tracker Public Enable"))
							continue;
						try
						{
							torrent = (TRTrackerServerTorrentImpl)server.permit(real_ip_address, hash, false);
						}
						catch (Throwable e)
						{
							continue;
						}
					}
					long interval = server.getScrapeRetryInterval(torrent);
					if (interval > max_interval)
						max_interval = interval;
					if (scrape_chars != null && !loopback && !ip_override && scrape_chars[i] == 'Q')
						torrent.peerQueued(client_ip_address, port, udp_port, http_port, crypto_level, az_ver, (int)interval, true);
					if (torrent.getRedirects() == null || hashes.length <= 1)
					{
						server.preProcess(new lightweightPeer(client_ip_address, port, peer_id), torrent, request_type, request, null);
						Map hash_entry = torrent.exportScrapeToMap(request, client_ip_address, !local_scrape);
						files.put(str_hash, hash_entry);
					}
				}

				if (hashes.length > 1)
					torrent = null;
				addScrapeInterval(max_interval, root);
			}
		} else
		{
			if (!TRTrackerServerImpl.isFullScrapeEnabled())
				throw new TRTrackerServerException("Full scrape disabled");
			Map files = new ByteEncodedKeyHashMap();
			TRTrackerServerTorrentImpl torrents[] = server.getTorrents();
			for (int i = 0; i < torrents.length; i++)
			{
				TRTrackerServerTorrentImpl this_torrent = torrents[i];
				if (this_torrent.getRedirects() != null)
					continue;
				server.preProcess(new lightweightPeer(client_ip_address, port, peer_id), this_torrent, request_type, request, null);
				byte torrent_hash[] = this_torrent.getHash().getHash();
				try
				{
					String str_hash = new String(torrent_hash, "ISO-8859-1");
					Map hash_entry = this_torrent.exportScrapeToMap(request, client_ip_address, true);
					files.put(str_hash, hash_entry);
				}
				catch (UnsupportedEncodingException e)
				{
					throw new TRTrackerServerException("Encoding error", e);
				}
			}

			Map root = new HashMap();
			root_out[0] = root;
			addScrapeInterval(((TRTrackerServerTorrentImpl) (null)), root);
			root.put("files", files);
		}
		return torrent;
	}

	protected void addScrapeInterval(TRTrackerServerTorrentImpl torrent, Map root)
	{
		long interval = server.getScrapeRetryInterval(torrent);
		addScrapeInterval(interval, root);
	}

	protected void addScrapeInterval(long interval, Map root)
	{
		if (interval > 0L)
		{
			Map flags = new HashMap();
			flags.put("min_request_interval", new Long(interval));
			root.put("flags", flags);
		}
	}

	public void taskCompleted()
	{
		if (start > 0L)
		{
			long time = SystemTime.getHighPrecisionCounter() - start;
			server.updateTime(request_type, time);
		}
	}

}

⌨️ 快捷键说明

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