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

📄 test.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:   Test.java

package org.gudy.azureus2.pluginsimpl.local.test;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.core.security.CryptoManager;
import com.aelitis.azureus.core.security.CryptoManagerPasswordHandler;
import java.io.File;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Properties;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.*;
import org.gudy.azureus2.plugins.ddb.*;
import org.gudy.azureus2.plugins.disk.DiskManagerFileInfo;
import org.gudy.azureus2.plugins.download.*;
import org.gudy.azureus2.plugins.messaging.MessageException;
import org.gudy.azureus2.plugins.messaging.MessageManager;
import org.gudy.azureus2.plugins.messaging.generic.*;
import org.gudy.azureus2.plugins.torrent.*;
import org.gudy.azureus2.plugins.utils.PooledByteBuffer;
import org.gudy.azureus2.plugins.utils.Utilities;
import org.gudy.azureus2.plugins.utils.security.*;

public class Test
	implements Plugin
{

	private static AESemaphore init_sem = new AESemaphore("PluginTester");
	private static AEMonitor class_mon = new AEMonitor("PluginTester");
	private static Test singleton;
	protected PluginInterface plugin_interface;

	public Test()
	{
	}

	public static Test getSingleton()
	{
		Test test;
		class_mon.enter();
		if (singleton == null)
		{
			(new AEThread("plugin initialiser") {

				public void runSupport()
				{
					PluginManager.registerPlugin(org/gudy/azureus2/pluginsimpl/local/test/Test);
					Properties props = new Properties();
					props.put("MULTI_INSTANCE", "true");
					PluginManager.startAzureus(1, props);
				}

			}).start();
			init_sem.reserve();
		}
		test = singleton;
		class_mon.exit();
		return test;
		Exception exception;
		exception;
		class_mon.exit();
		throw exception;
	}

	public void initialize(PluginInterface _pi)
	{
		plugin_interface = _pi;
		singleton = this;
		init_sem.release();
		plugin_interface.addListener(new PluginListener() {

			final Test this$0;

			public void initializationComplete()
			{
				Thread t = new AEThread("test") {

					final 2 this$1;

					public void runSupport()
					{
						testMessaging();
					}

					
					{
						this$1 = 2.this;
						super(x0);
					}
				};
				t.setDaemon(true);
				t.start();
			}

			public void closedownInitiated()
			{
			}

			public void closedownComplete()
			{
			}

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

	protected void testMessaging()
	{
		try
		{
			AzureusCoreFactory.getSingleton().getCryptoManager().addPasswordHandler(new CryptoManagerPasswordHandler() {

				final Test this$0;

				public int getHandlerType()
				{
					return 1;
				}

				public com.aelitis.azureus.core.security.CryptoManagerPasswordHandler.passwordDetails getPassword(int handler_type, int action_type, boolean last_pw_incorrect, String reason)
				{
					System.out.println((new StringBuilder()).append("CryptoPassword (").append(reason).append(")").toString());
					return new com.aelitis.azureus.core.security.CryptoManagerPasswordHandler.passwordDetails() {

						final 3 this$1;

						public char[] getPassword()
						{
							return "changeit".toCharArray();
						}

						public int getPersistForSeconds()
						{
							return 0;
						}

					
					{
						this$1 = 3.this;
						super();
					}
					};
				}

				public void passwordOK(int j, com.aelitis.azureus.core.security.CryptoManagerPasswordHandler.passwordDetails passworddetails)
				{
				}

			
			{
				this$0 = Test.this;
				super();
			}
			});
			final SESecurityManager sec_man = plugin_interface.getUtilities().getSecurityManager();
			final SEPublicKey my_key = sec_man.getPublicKey(1, "test");
			int stream_crypto = 3;
			boolean use_sts = true;
			int block_crypto = 2;
			GenericMessageRegistration reg = plugin_interface.getMessageManager().registerGenericMessageType("GENTEST", "Gen test desc", 3, new GenericMessageHandler() {

				final SESecurityManager val$sec_man;
				final SEPublicKey val$my_key;
				final Test this$0;

				public boolean accept(GenericMessageConnection connection)
					throws MessageException
				{
					System.out.println("accept");
					try
					{
						connection = sec_man.getSTSConnection(connection, my_key, new SEPublicKeyLocator() {

							final 4 this$1;

							public boolean accept(Object context, SEPublicKey other_key)
							{
								System.out.println("acceptKey");
								return true;
							}

					
					{
						this$1 = 4.this;
						super();
					}
						}, "test", 2);
						connection.addListener(new GenericMessageConnectionListener() {

							final 4 this$1;

							public void connected(GenericMessageConnection genericmessageconnection)
							{
							}

							public void receive(GenericMessageConnection connection, PooledByteBuffer message)
								throws MessageException
							{
								System.out.println((new StringBuilder()).append("receive: ").append(message.toByteArray().length).toString());
								PooledByteBuffer reply = plugin_interface.getUtilities().allocatePooledByteBuffer(new byte[connection.getMaximumMessageSize()]);
								connection.send(reply);
							}

							public void failed(GenericMessageConnection connection, Throwable error)
								throws MessageException
							{
								System.out.println("Responder connection error:");
								error.printStackTrace();
							}

					
					{
						this$1 = 4.this;
						super();
					}
						});
					}
					catch (Throwable e)
					{
						connection.close();
						e.printStackTrace();
					}
					return true;
				}

			
			{
				this$0 = Test.this;
				sec_man = sesecuritymanager;
				my_key = sepublickey;
				super();
			}
			});
			InetSocketAddress tcp_target = new InetSocketAddress("127.0.0.1", 6889);
			InetSocketAddress udp_target = new InetSocketAddress("212.159.18.92", 6881);
			GenericMessageEndpoint endpoint = reg.createEndpoint(tcp_target);
			endpoint.addTCP(tcp_target);
			endpoint.addUDP(udp_target);
			do
			{
				try
				{
					do
					{
						int i = 0;
						while (i < 1000) 
						{
							System.out.println("Test: initiating connection");
							final AESemaphore sem = new AESemaphore("wait!");
							GenericMessageConnection con = reg.createConnection(endpoint);
							con = sec_man.getSTSConnection(con, my_key, new SEPublicKeyLocator() {

								final Test this$0;

								public boolean accept(Object context, SEPublicKey other_key)
								{
									System.out.println("acceptKey");
									return true;
								}

			
			{
				this$0 = Test.this;
				super();
			}
							}, "test", 2);
							con.addListener(new GenericMessageConnectionListener() {

								final AESemaphore val$sem;
								final Test this$0;

								public void connected(GenericMessageConnection connection)
								{
									System.out.println("connected");
									PooledByteBuffer data = plugin_interface.getUtilities().allocatePooledByteBuffer("1234".getBytes());
									try
									{
										connection.send(data);
									}
									catch (Throwable e)
									{
										e.printStackTrace();
									}
								}

								public void receive(GenericMessageConnection connection, PooledByteBuffer message)
									throws MessageException
								{
									System.out.println((new StringBuilder()).append("receive: ").append(message.toByteArray().length).toString());
									try
									{
										Thread.sleep(30000L);
									}
									catch (Throwable e) { }
									System.out.println("closing connection");
									connection.close();
									sem.release();
								}

								public void failed(GenericMessageConnection connection, Throwable error)
									throws MessageException
								{
									System.out.println("Initiator connection error:");
									error.printStackTrace();
									sem.release();
								}

			
			{
				this$0 = Test.this;
				sem = aesemaphore;
				super();
			}
							});
							con.connect();
							sem.reserve();
							Thread.sleep(1000L);
							i++;
						}
					} while (true);
				}
				catch (Throwable e)
				{
					e.printStackTrace();
				}
				try
				{
					System.out.println("Sleeping before retrying");
					Thread.sleep(30000L);
				}
				catch (Throwable f) { }
			} while (true);
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
	}

	protected void testLinks()
	{
		plugin_interface.getDownloadManager().addListener(new DownloadManagerListener() {

			final Test this$0;

			public void downloadAdded(Download download)
			{
				DiskManagerFileInfo info[] = download.getDiskManagerFileInfo();
				for (int i = 0; i < info.length; i++)
					info[i].setLink(new File("C:\\temp"));

			}

			public void downloadRemoved(Download download1)
			{
			}

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

	protected void testDDB()
	{
		try
		{
			DistributedDatabase db = plugin_interface.getDistributedDatabase();
			DistributedDatabaseKey key = db.createKey(new byte[] {
				4, 7, 1, 2, 5, 8
			});
			boolean do_write = false;
			if (do_write)
			{
				DistributedDatabaseValue values[] = new DistributedDatabaseValue[500];
				for (int i = 0; i < values.length; i++)
				{
					byte val[] = new byte[20];
					Arrays.fill(val, (byte)i);
					values[i] = db.createValue(val);
				}

				db.write(new DistributedDatabaseListener() {

					final Test this$0;

					public void event(DistributedDatabaseEvent event)
					{
						System.out.println((new StringBuilder()).append("Event:").append(event.getType()).toString());
						if (event.getType() == 1)
							try
							{
								System.out.println((new StringBuilder()).append("    write - key = ").append(ByteFormatter.encodeString((byte[])(byte[])event.getKey().getKey())).append(", val = ").append(ByteFormatter.encodeString((byte[])(byte[])event.getValue().getValue([B))).toString());
							}
							catch (Throwable e)
							{
								e.printStackTrace();
							}
					}

			
			{
				this$0 = Test.this;
				super();
			}
				}, key, values);
			} else
			{
				db.read(new DistributedDatabaseListener() {

					final Test this$0;

					public void event(DistributedDatabaseEvent event)
					{
						System.out.println((new StringBuilder()).append("Event:").append(event.getType()).toString());
						if (event.getType() == 2)
							try
							{
								System.out.println((new StringBuilder()).append("    read - key = ").append(ByteFormatter.encodeString((byte[])(byte[])event.getKey().getKey())).append(", val = ").append(ByteFormatter.encodeString((byte[])(byte[])event.getValue().getValue([B))).toString());
							}
							catch (Throwable e)
							{
								e.printStackTrace();
							}
					}

			
			{
				this$0 = Test.this;
				super();
			}
				}, key, 60000L);
			}
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
	}

	protected void taTest()
	{
		try
		{
			final TorrentAttribute ta = plugin_interface.getTorrentManager().getAttribute("Category");
			ta.addTorrentAttributeListener(new TorrentAttributeListener() {

				final TorrentAttribute val$ta;
				final Test this$0;

				public void event(TorrentAttributeEvent ev)
				{
					System.out.println((new StringBuilder()).append("ev: ").append(ev.getType()).append(", ").append(ev.getData()).toString());
					if (ev.getType() == 1 && "plop".equals(ev.getData()))
						ta.removeDefinedValue("plop");
				}

			
			{
				this$0 = Test.this;
				ta = torrentattribute;
				super();
			}
			});
			ta.addDefinedValue("wibble");
			plugin_interface.getDownloadManager().addListener(new DownloadManagerListener() {

				final TorrentAttribute val$ta;
				final Test this$0;

				public void downloadAdded(Download download)
				{
					try
					{
						download.setAttribute(ta, "wibble");
					}
					catch (Throwable e)
					{
						e.printStackTrace();
					}
				}

				public void downloadRemoved(Download download1)
				{
				}

			
			{
				this$0 = Test.this;
				ta = torrentattribute;
				super();
			}
			});
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
	}

	public static void main(String args[])
	{
		getSingleton();
	}

}

⌨️ 快捷键说明

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