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

📄 trtrackerservernatchecker.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:   TRTrackerServerNATChecker.java

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

import com.aelitis.azureus.core.proxy.AEProxyAddressMapper;
import com.aelitis.azureus.core.proxy.AEProxyFactory;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
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.util.*;

// Referenced classes of package org.gudy.azureus2.core3.tracker.server.impl:
//			TRTrackerServerNatCheckerListener

public class TRTrackerServerNATChecker
{

	private static final LogIDs LOGID;
	protected static TRTrackerServerNATChecker singleton = new TRTrackerServerNATChecker();
	protected static final int THREAD_POOL_SIZE = 32;
	protected static final int CHECK_QUEUE_LIMIT = 2048;
	protected static int check_timeout = 15000;
	protected boolean enabled;
	protected ThreadPool thread_pool;
	protected List check_queue;
	protected AESemaphore check_queue_sem;
	protected AEMonitor check_queue_mon;
	protected AEMonitor this_mon;

	protected static TRTrackerServerNATChecker getSingleton()
	{
		return singleton;
	}

	protected TRTrackerServerNATChecker()
	{
		check_queue = new ArrayList();
		check_queue_sem = new AESemaphore("TracerServerNATChecker");
		check_queue_mon = new AEMonitor("TRTrackerServerNATChecker:Q");
		this_mon = new AEMonitor("TRTrackerServerNATChecker");
		String enable_param = "Tracker NAT Check Enable";
		String timeout_param = "Tracker NAT Check Timeout";
		String params[] = {
			"Tracker NAT Check Enable", "Tracker NAT Check Timeout"
		};
		for (int i = 0; i < params.length; i++)
			COConfigurationManager.addParameterListener(params[i], new ParameterListener() {

				final TRTrackerServerNATChecker this$0;

				public void parameterChanged(String parameter_name)
				{
					checkConfig("Tracker NAT Check Enable", "Tracker NAT Check Timeout");
				}

			
			{
				this$0 = TRTrackerServerNATChecker.this;
				super();
			}
			});

		checkConfig("Tracker NAT Check Enable", "Tracker NAT Check Timeout");
	}

	protected boolean isEnabled()
	{
		return enabled;
	}

	protected void checkConfig(String enable_param, String timeout_param)
	{
		this_mon.enter();
		enabled = COConfigurationManager.getBooleanParameter(enable_param);
		check_timeout = COConfigurationManager.getIntParameter(timeout_param) * 1000;
		if (check_timeout < 1000)
		{
			Debug.out((new StringBuilder()).append("NAT check timeout too small - ").append(check_timeout).toString());
			check_timeout = 1000;
		}
		if (thread_pool == null)
		{
			thread_pool = new ThreadPool("Tracker NAT Checker", 32);
			thread_pool.setExecutionLimit(check_timeout);
			Thread dispatcher_thread = new AEThread("Tracker NAT Checker Dispatcher") {

				final TRTrackerServerNATChecker this$0;

				public void runSupport()
				{
_L2:
					check_queue_sem.reserve();
					ThreadPoolTask task;
					check_queue_mon.enter();
					task = (ThreadPoolTask)check_queue.remove(0);
					check_queue_mon.exit();
					break MISSING_BLOCK_LABEL_63;
					Exception exception1;
					exception1;
					check_queue_mon.exit();
					throw exception1;
					try
					{
						thread_pool.run(task);
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
					if (true) goto _L2; else goto _L1
_L1:
				}

			
			{
				this$0 = TRTrackerServerNATChecker.this;
				super(x0);
			}
			};
			dispatcher_thread.setDaemon(true);
			dispatcher_thread.start();
		} else
		{
			thread_pool.setExecutionLimit(check_timeout);
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_154;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected boolean addNATCheckRequest(final String host, final int port, final TRTrackerServerNatCheckerListener listener)
	{
		if (!enabled || thread_pool == null)
			return false;
		check_queue_mon.enter();
		if (check_queue.size() > 2048)
		{
			if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, 1, (new StringBuilder()).append("NAT Check queue size too large, check for '").append(host).append(":").append(port).append("' skipped").toString()));
			listener.NATCheckComplete(true);
		} else
		{
			check_queue.add(new ThreadPoolTask() {

				protected Socket socket;
				final String val$host;
				final int val$port;
				final TRTrackerServerNatCheckerListener val$listener;
				final TRTrackerServerNATChecker this$0;

				public void runSupport()
				{
label0:
					{
						boolean ok = false;
						try
						{
							InetSocketAddress address = new InetSocketAddress(AEProxyFactory.getAddressMapper().internalise(host), port);
							socket = new Socket();
							socket.connect(address, TRTrackerServerNATChecker.check_timeout);
							ok = true;
							socket.close();
							socket = null;
						}
						catch (Throwable e)
						{
							listener.NATCheckComplete(ok);
							if (socket != null)
								try
								{
									socket.close();
								}
								// Misplaced declaration of an exception variable
								catch (Throwable e) { }
							break label0;
						}
						finally
						{
							listener.NATCheckComplete(ok);
							if (socket != null)
								try
								{
									socket.close();
								}
								catch (Throwable e) { }
							throw exception1;
						}
						listener.NATCheckComplete(ok);
						if (socket != null)
							try
							{
								socket.close();
							}
							catch (Throwable e) { }
						break label0;
					}
				}

				public void interruptTask()
				{
					if (socket != null)
						try
						{
							socket.close();
						}
						catch (Throwable e) { }
				}

			
			{
				this$0 = TRTrackerServerNATChecker.this;
				host = s;
				port = i;
				listener = trtrackerservernatcheckerlistener;
				super();
			}
			});
			check_queue_sem.release();
		}
		check_queue_mon.exit();
		break MISSING_BLOCK_LABEL_151;
		Exception exception;
		exception;
		check_queue_mon.exit();
		throw exception;
		return true;
	}

	static 
	{
		LOGID = LogIDs.TRACKER;
	}
}

⌨️ 快捷键说明

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