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

📄 trhostconfigimpl.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:   TRHostConfigImpl.java

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

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentException;
import org.gudy.azureus2.core3.tracker.host.TRHostTorrent;
import org.gudy.azureus2.core3.tracker.host.TRHostTorrentFinder;
import org.gudy.azureus2.core3.util.*;

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

public class TRHostConfigImpl
{

	public static final String LOG_FILE_NAME = "tracker.log";
	public static final long BACKUP_RETENTION_PERIOD = 0x240c8400L;
	private TRHostImpl host;
	private AEMonitor save_lock_mon;
	private String log_dir;
	private volatile boolean loading;
	private volatile boolean save_outstanding;
	private Map saved_stats;
	private List saved_stats_to_delete;
	private AEMonitor this_mon;

	protected TRHostConfigImpl(TRHostImpl _host)
	{
		save_lock_mon = new AEMonitor("TRHostConfig:SL");
		loading = false;
		save_outstanding = false;
		saved_stats = new HashMap();
		saved_stats_to_delete = new ArrayList();
		this_mon = new AEMonitor("TRHostConfig");
		host = _host;
		log_dir = SystemProperties.getUserPath();
	}

	protected void loadConfig(TRHostTorrentFinder finder)
	{
		List torrents;
		this_mon.enter();
		loading = true;
		Map map = FileUtil.readResilientConfigFile("tracker.config");
		torrents = (List)map.get("torrents");
		if (torrents == null)
		{
			loading = false;
			this_mon.exit();
			return;
		}
		Iterator iter = torrents.iterator();
		do
		{
			if (!iter.hasNext())
				break;
			Map t_map = (Map)iter.next();
			Long persistent_l = (Long)t_map.get("persistent");
			boolean persistent = persistent_l == null || persistent_l.longValue() == 1L;
			Long passive_l = (Long)t_map.get("passive");
			boolean passive = passive_l != null && passive_l.longValue() == 1L;
			Long dateadded_l = (Long)t_map.get("dateadded");
			long date_added = dateadded_l != null ? dateadded_l.longValue() : SystemTime.getCurrentTime();
			byte hash[] = (byte[])(byte[])t_map.get("hash");
			if (persistent)
			{
				int state = ((Long)t_map.get("status")).intValue();
				if (state == 0)
					state = 1;
				TOTorrent torrent = finder.lookupTorrent(hash);
				if (torrent == null && passive)
				{
					byte file_b[] = (byte[])(byte[])t_map.get("torrent_file");
					if (file_b != null)
						try
						{
							File file = new File(new String(file_b, "ISO-8859-1"));
							torrent = TorrentUtils.readFromFile(file, true, true);
						}
						catch (Throwable e) { }
				}
				if (torrent != null)
				{
					TRHostTorrent ht = host.addTorrent(torrent, state, true, passive, date_added);
					if (ht instanceof TRHostTorrentHostImpl)
					{
						TRHostTorrentHostImpl hth = (TRHostTorrentHostImpl)ht;
						recoverStats(hth, t_map);
					}
				} else
				if (COConfigurationManager.getBooleanParameter("Tracker Public Enable"))
					host.addExternalTorrent(hash, state, date_added);
			} else
			{
				saved_stats.put(new HashWrapper(hash), t_map);
			}
		} while (true);
		loading = false;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_453;
		Exception e;
		e;
		Debug.printStackTrace(e);
		loading = false;
		this_mon.exit();
		break MISSING_BLOCK_LABEL_453;
		Exception exception;
		exception;
		loading = false;
		this_mon.exit();
		throw exception;
	}

	protected void recoverStats(TRHostTorrentHostImpl host_torrent)
	{
		try
		{
			HashWrapper hash = host_torrent.getTorrent().getHashWrapper();
			Map t_map = (Map)saved_stats.get(hash);
			if (t_map != null)
			{
				recoverStats(host_torrent, t_map);
				synchronized (saved_stats_to_delete)
				{
					saved_stats_to_delete.add(hash);
				}
			}
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
	}

	private void recoverStats(TRHostTorrentHostImpl host_torrent, Map t_map)
	{
		long completed = 0L;
		long announces = 0L;
		long scrapes = 0L;
		long total_up = 0L;
		long total_down = 0L;
		long bytes_in = 0L;
		long bytes_out = 0L;
		Long dateadded_l = (Long)t_map.get("dateadded");
		long date_added = dateadded_l != null ? dateadded_l.longValue() : SystemTime.getCurrentTime();
		Map s_map = (Map)t_map.get("stats");
		if (s_map != null)
		{
			completed = ((Long)s_map.get("completed")).longValue();
			announces = ((Long)s_map.get("announces")).longValue();
			total_up = ((Long)s_map.get("uploaded")).longValue();
			total_down = ((Long)s_map.get("downloaded")).longValue();
			Long scrapes_l = (Long)s_map.get("scrapes");
			if (scrapes_l != null)
				scrapes = scrapes_l.longValue();
			Long bytes_in_l = (Long)s_map.get("bytesin");
			if (bytes_in_l != null)
				bytes_in = bytes_in_l.longValue();
			Long bytes_out_l = (Long)s_map.get("bytesout");
			if (bytes_out_l != null)
				bytes_out = bytes_out_l.longValue();
		}
		host_torrent.setStartOfDayValues(date_added, completed, announces, scrapes, total_up, total_down, bytes_in, bytes_out);
	}

	protected void saveConfig(boolean immediate)
	{
		if (loading)
			return;
		if (saved_stats_to_delete.size() > 0)
			synchronized (saved_stats_to_delete)
			{
				Map saved_stats_copy = new HashMap(saved_stats);
				for (int i = 0; i < saved_stats_to_delete.size(); i++)
					saved_stats_copy.remove(saved_stats_to_delete.get(i));

				saved_stats_to_delete.clear();
				saved_stats = saved_stats_copy;
			}
		if (!immediate && !save_outstanding)
			break MISSING_BLOCK_LABEL_1495;
		save_outstanding = false;
		Map map;
		List stats_entries;
		map = new HashMap();
		List list = new ArrayList();
		TRHostTorrent torrents[] = host.getTorrents();
		stats_entries = new ArrayList();
		Set added = new HashSet();
		for (int i = 0; i < torrents.length; i++)
			try
			{
				TRHostTorrent torrent = torrents[i];
				added.add(torrent.getTorrent().getHashWrapper());
				StringBuffer stats_entry = new StringBuffer(2048);
				byte hash[] = torrent.getTorrent().getHash();
				byte name[] = torrent.getTorrent().getName();
				int status = torrent.getStatus();
				long completed = torrent.getCompletedCount();
				long announces = torrent.getAnnounceCount();
				long scrapes = torrent.getScrapeCount();
				long uploaded = torrent.getTotalUploaded();
				long downloaded = torrent.getTotalDownloaded();
				long bytes_in = torrent.getTotalBytesIn();
				long bytes_out = torrent.getTotalBytesOut();
				long date_added = torrent.getDateAdded();
				int seed_count = torrent.getSeedCount();
				int non_seed_count = torrent.getLeecherCount();
				Map t_map = new HashMap();
				t_map.put("persistent", new Long(torrent.isPersistent() ? 1L : 0L));
				t_map.put("passive", new Long(torrent.isPassive() ? 1L : 0L));
				if (torrent.isPassive())
					try
					{
						String file = TorrentUtils.getTorrentFileName(torrent.getTorrent());
						t_map.put("torrent_file", file.getBytes("ISO-8859-1"));
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				t_map.put("hash", hash);
				t_map.put("dateadded", new Long(date_added));
				t_map.put("status", new Long(status));
				list.add(t_map);
				Map s_map = new HashMap();
				t_map.put("stats", s_map);
				s_map.put("completed", new Long(completed));
				s_map.put("announces", new Long(announces));
				s_map.put("scrapes", new Long(scrapes));
				s_map.put("uploaded", new Long(uploaded));
				s_map.put("downloaded", new Long(downloaded));
				s_map.put("bytesin", new Long(bytes_in));
				s_map.put("bytesout", new Long(bytes_out));
				stats_entry.append(new String(name, "UTF8"));
				stats_entry.append(",");
				stats_entry.append(ByteFormatter.nicePrint(hash, true));
				stats_entry.append(",");
				stats_entry.append(status);
				stats_entry.append(",");
				stats_entry.append(seed_count);
				stats_entry.append(",");
				stats_entry.append(non_seed_count);
				stats_entry.append(",");
				stats_entry.append(completed);
				stats_entry.append(",");
				stats_entry.append(announces);
				stats_entry.append(",");
				stats_entry.append(scrapes);
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtc(uploaded));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtc(downloaded));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(torrent.getAverageUploaded()));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(torrent.getAverageDownloaded()));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtc(torrent.getTotalLeft()));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtc(bytes_in));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtc(bytes_out));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(torrent.getAverageBytesIn()));
				stats_entry.append(",");
				stats_entry.append(DisplayFormatters.formatByteCountToKiBEtcPerSec(torrent.getAverageBytesOut()));
				stats_entry.append("\r\n");
				stats_entries.add(stats_entry);
			}
			catch (TOTorrentException e)
			{
				Debug.printStackTrace(e);
			}

		Iterator it = saved_stats.keySet().iterator();
		long now = SystemTime.getCurrentTime();
		do
		{
			if (!it.hasNext())
				break;
			HashWrapper hash = (HashWrapper)it.next();
			if (!added.contains(hash))
			{
				Map t_map = (Map)saved_stats.get(hash);
				Long backup = (Long)t_map.get("backup_time");
				if (backup == null)
				{
					backup = new Long(now);
					t_map.put("backup_time", backup);
				}
				if (now - backup.longValue() < 0x240c8400L)
				{
					list.add(t_map);
					added.add(hash);
				}
			}
		} while (true);
		map.put("torrents", list);
		save_lock_mon.enter();
		FileUtil.writeResilientConfigFile("tracker.config", map);
		if (!COConfigurationManager.getBooleanParameter("Tracker Log Enable") || stats_entries.size() <= 0)
			break MISSING_BLOCK_LABEL_1465;
		String timeStamp;
		PrintWriter pw;
		File file_name;
		timeStamp = (new StringBuilder()).append("[").append((new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss")).format(new Date())).append("] ").toString();
		pw = null;
		file_name = new File(log_dir.concat(File.separator).concat("tracker.log"));
		pw = new PrintWriter(new FileWriter(file_name, true));
		for (int i = 0; i < stats_entries.size(); i++)
		{
			StringBuffer stats_entry = (StringBuffer)stats_entries.get(i);
			String str = (new StringBuilder()).append(timeStamp).append(stats_entry.toString()).toString();
			pw.print(str);
		}

		Throwable e;
		if (pw != null)
			try
			{
				pw.close();
			}
			// Misplaced declaration of an exception variable
			catch (Throwable e) { }
		break MISSING_BLOCK_LABEL_1465;
		e;
		Debug.printStackTrace(e);
		if (pw != null)
			try
			{
				pw.close();
			}
			// Misplaced declaration of an exception variable
			catch (Throwable e) { }
		break MISSING_BLOCK_LABEL_1465;
		Exception exception1;
		exception1;
		if (pw != null)
			try
			{
				pw.close();
			}
			catch (Throwable e) { }
		throw exception1;
		Throwable e;
		e;
		Debug.printStackTrace(e);
		save_lock_mon.exit();
		break MISSING_BLOCK_LABEL_1495;
		Exception exception2;
		exception2;
		save_lock_mon.exit();
		throw exception2;
		Throwable e;
		e;
		Debug.printStackTrace(e);
	}

	protected void saveRequired()
	{
		save_outstanding = true;
	}
}

⌨️ 快捷键说明

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