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

📄 trhostimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}
		catch (TOTorrentException e)
		{
			Debug.printStackTrace(e);
		}
		host_torrent_map.remove(torrent);
		if (host_torrent instanceof TRHostTorrentHostImpl)
			stopHosting((TRHostTorrentHostImpl)host_torrent);
		listeners.dispatch(2, host_torrent);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_134;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void stopHosting(TRHostTorrentHostImpl host_torrent)
	{
		TOTorrent torrent = host_torrent.getTorrent();
		TRTrackerAnnouncer tc = (TRTrackerAnnouncer)tracker_client_map.get(torrent);
		if (tc != null)
			stopHosting(host_torrent, tc);
	}

	protected void stopHosting(TRTrackerAnnouncer tracker_client)
	{
		TRHostTorrent host_torrent = (TRHostTorrent)host_torrent_map.get(tracker_client.getTorrent());
		if (host_torrent instanceof TRHostTorrentHostImpl)
			stopHosting((TRHostTorrentHostImpl)host_torrent, tracker_client);
	}

	protected void stopHosting(TRHostTorrentHostImpl host_torrent, TRTrackerAnnouncer tracker_client)
	{
		Thread thread = new AEThread(tracker_client) {

			final TRHostTorrentHostImpl val$host_torrent;
			final TRTrackerAnnouncer val$tracker_client;
			final TRHostImpl this$0;

			public void runSupport()
			{
				try
				{
					Thread.sleep(2500L);
				}
				catch (InterruptedException e) { }
				this_mon.enter();
				TRHostTorrent ht = lookupHostTorrent(host_torrent.getTorrent());
				if (ht == null || ht == host_torrent && ht.getStatus() == 1)
					tracker_client.clearIPOverride();
				this_mon.exit();
				break MISSING_BLOCK_LABEL_92;
				Exception exception;
				exception;
				this_mon.exit();
				throw exception;
			}

			
			{
				this$0 = TRHostImpl.this;
				host_torrent = trhosttorrenthostimpl;
				tracker_client = trtrackerannouncer;
				super(x0);
			}
		};
		thread.setDaemon(true);
		thread.start();
	}

	protected TRTrackerAnnouncer getTrackerClient(TRHostTorrent host_torrent)
	{
		TRTrackerAnnouncer trtrackerannouncer;
		this_mon.enter();
		trtrackerannouncer = (TRTrackerAnnouncer)tracker_client_map.get(host_torrent.getTorrent());
		this_mon.exit();
		return trtrackerannouncer;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void hostTorrentStateChange(TRHostTorrent host_torrent)
	{
		this_mon.enter();
		TOTorrent torrent = host_torrent.getTorrent();
		TRTrackerAnnouncer tc = (TRTrackerAnnouncer)tracker_client_map.get(torrent);
		if (tc != null)
			tc.refreshListeners();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_60;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public TRHostTorrent[] getTorrents()
	{
		TRHostTorrent atrhosttorrent[];
		this_mon.enter();
		TRHostTorrent res[] = new TRHostTorrent[host_torrents.size()];
		host_torrents.toArray(res);
		atrhosttorrent = res;
		this_mon.exit();
		return atrhosttorrent;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void clientCreated(TRTrackerAnnouncer client)
	{
		this_mon.enter();
		tracker_client_map.put(client.getTorrent(), client);
		startHosting(client);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_49;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void clientDestroyed(TRTrackerAnnouncer client)
	{
		this_mon.enter();
		tracker_client_map.remove(client.getTorrent());
		stopHosting(client);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_48;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected TRHostTorrent lookupHostTorrentViaHash(byte hash[])
	{
		return (TRHostTorrent)host_torrent_hash_map.get(new HashWrapper(hash));
	}

	public boolean permitted(String originator, byte hash[], boolean explicit)
	{
		boolean flag;
		this_mon.enter();
		TRHostTorrent ht = lookupHostTorrentViaHash(hash);
		if (ht == null)
			break MISSING_BLOCK_LABEL_60;
		if (explicit || ht.getStatus() == 2)
			break MISSING_BLOCK_LABEL_47;
		flag = false;
		this_mon.exit();
		return flag;
		flag = true;
		this_mon.exit();
		return flag;
		addExternalTorrent(hash, 2, SystemTime.getCurrentTime());
		flag = true;
		this_mon.exit();
		return flag;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void addExternalTorrent(byte hash[], int state, long date_added)
	{
		this_mon.enter();
		if (lookupHostTorrentViaHash(hash) != null)
		{
			this_mon.exit();
			return;
		}
		String tracker_ip = COConfigurationManager.getStringParameter("Tracker IP", "127.0.0.1");
		int port = COConfigurationManager.getIntParameter("Tracker Port", 6969);
		try
		{
			TOTorrent external_torrent = new TRHostExternalTorrent(hash, new URL((new StringBuilder()).append("http://").append(UrlUtils.convertIPV6Host(tracker_ip)).append(":").append(port).append("/announce").toString()));
			addTorrent(external_torrent, state, true, false, date_added);
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_140;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public boolean denied(byte hash[], boolean permitted)
	{
		return true;
	}

	public boolean handleExternalRequest(InetSocketAddress client_address, String user, String url, URL absolute_url, String header, InputStream is, OutputStream os, 
			AsyncController async)
		throws IOException
	{
		List listeners_copy = listeners.getListenersCopy();
		for (int i = 0; i < listeners_copy.size(); i++)
		{
			TRHostListener listener = (TRHostListener)listeners_copy.get(i);
			if (listener.handleExternalRequest(client_address, user, url, absolute_url, header, is, os, async))
				return true;
		}

		return false;
	}

	public TRHostTorrent getHostTorrent(TOTorrent torrent)
	{
		return lookupHostTorrent(torrent);
	}

	public void addListener(TRHostListener l)
	{
		this_mon.enter();
		listeners.addListener(l);
		for (int i = 0; i < host_torrents.size(); i++)
			listeners.dispatch(l, 1, host_torrents.get(i));

		this_mon.exit();
		break MISSING_BLOCK_LABEL_75;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void removeListener(TRHostListener l)
	{
		listeners.removeListener(l);
	}

	protected void torrentListenerRegistered()
	{
		this_mon.enter();
		if (!server_factory_listener_added)
		{
			server_factory_listener_added = true;
			TRTrackerServerFactory.addListener(this);
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_43;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void serverCreated(TRTrackerServer server)
	{
		server.addRequestListener(this);
	}

	public void serverDestroyed(TRTrackerServer server)
	{
		server.removeRequestListener(this);
	}

	public void preProcess(TRTrackerServerRequest request)
		throws TRTrackerServerException
	{
		if (request.getType() == 1 || request.getType() == 2)
		{
			TRTrackerServerTorrent ts_torrent = request.getTorrent();
			HashWrapper hash_wrapper = ts_torrent.getHash();
			TRHostTorrent h_torrent = lookupHostTorrentViaHash(hash_wrapper.getHash());
			if (h_torrent != null)
			{
				org.gudy.azureus2.core3.tracker.host.TRHostTorrentRequest req = new TRHostTorrentRequestImpl(h_torrent, new TRHostPeerHostImpl(request.getPeer()), request);
				try
				{
					if (h_torrent instanceof TRHostTorrentHostImpl)
						((TRHostTorrentHostImpl)h_torrent).preProcess(req);
					else
						((TRHostTorrentPublishImpl)h_torrent).preProcess(req);
				}
				catch (TRHostException e)
				{
					throw new TRTrackerServerException(e.getMessage(), e);
				}
				catch (Throwable e)
				{
					throw new TRTrackerServerException("Pre-process fails", e);
				}
			}
		}
	}

	public void postProcess(TRTrackerServerRequest request)
		throws TRTrackerServerException
	{
		if (request.getType() == 1 || request.getType() == 2)
		{
			TRTrackerServerTorrent ts_torrent = request.getTorrent();
			if (ts_torrent != null)
			{
				HashWrapper hash_wrapper = ts_torrent.getHash();
				TRHostTorrent h_torrent = lookupHostTorrentViaHash(hash_wrapper.getHash());
				if (h_torrent != null)
				{
					org.gudy.azureus2.core3.tracker.host.TRHostTorrentRequest req = new TRHostTorrentRequestImpl(h_torrent, new TRHostPeerHostImpl(request.getPeer()), request);
					try
					{
						if (h_torrent instanceof TRHostTorrentHostImpl)
							((TRHostTorrentHostImpl)h_torrent).postProcess(req);
						else
							((TRHostTorrentPublishImpl)h_torrent).postProcess(req);
					}
					catch (TRHostException e)
					{
						throw new TRTrackerServerException("Post process fails", e);
					}
				}
			}
		}
	}

	public void close()
	{
		closed = true;
		config.saveConfig(true);
	}

	public boolean authenticate(URL resource, String user, String password)
	{
		int i = 0;
_L3:
		if (i >= auth_listeners.size()) goto _L2; else goto _L1
_L1:
		boolean res = ((TRHostAuthenticationListener)auth_listeners.get(i)).authenticate(resource, user, password);
		if (res)
			return true;
		continue; /* Loop/switch isn't completed */
		Throwable e;
		e;
		Debug.printStackTrace(e);
		i++;
		  goto _L3
_L2:
		return false;
	}

	public byte[] authenticate(URL resource, String user)
	{
		int i = 0;
_L3:
		if (i >= auth_listeners.size()) goto _L2; else goto _L1
_L1:
		byte res[] = ((TRHostAuthenticationListener)auth_listeners.get(i)).authenticate(resource, user);
		if (res != null)
			return res;
		continue; /* Loop/switch isn't completed */
		Throwable e;
		e;
		Debug.printStackTrace(e);
		i++;
		  goto _L3
_L2:
		return null;
	}

	public void addAuthenticationListener(TRHostAuthenticationListener l)
	{
		this_mon.enter();
		auth_listeners.add(l);
		if (auth_listeners.size() == 1)
		{
			for (Iterator it = server_map.values().iterator(); it.hasNext(); ((TRTrackerServer)it.next()).addAuthenticationListener(this));
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_91;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void removeAuthenticationListener(TRHostAuthenticationListener l)
	{
		this_mon.enter();
		auth_listeners.remove(l);
		if (auth_listeners.size() == 0)
		{
			for (Iterator it = server_map.values().iterator(); it.hasNext(); ((TRTrackerServer)it.next()).removeAuthenticationListener(this));
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_90;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void startTorrent(TRHostTorrentHostImpl torrent)
	{
		this_mon.enter();
		torrent.startSupport();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_31;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void stopTorrent(TRHostTorrentHostImpl torrent)
	{
		this_mon.enter();
		torrent.stopSupport();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_31;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void addTrackerAnnounce(TOTorrent torrent)
	{
		if (TorrentUtils.isDecentralised(torrent))
			return;
		URL url_sets[][] = TRTrackerUtils.getAnnounceURLs();
		if (url_sets.length == 0)
		{
			TorrentUtils.setDecentralised(torrent);
		} else
		{
			URL primary_urls[] = url_sets[0];
			for (int i = primary_urls.length - 1; i >= 0; i--)
			{
				String url_str = primary_urls[i].toString();
				if (TorrentUtils.announceGroupsContainsURL(torrent, url_str))
					TorrentUtils.announceGroupsSetFirst(torrent, url_str);
				else
					TorrentUtils.announceGroupsInsertFirst(torrent, url_str);
			}

		}
	}

	static 
	{
		LOGID = LogIDs.TRACKER;
		COConfigurationManager.addAndFireParameterListener("Tracker Host Add Our Announce URLs", new ParameterListener() {

			public void parameterChanged(String name)
			{
				TRHostImpl.host_add_announce_urls = COConfigurationManager.getBooleanParameter(name);
			}

		});
	}





}

⌨️ 快捷键说明

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