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

📄 genericmessageconnectiondirect.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:   GenericMessageConnectionDirect.java

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

import com.aelitis.azureus.core.networkmanager.*;
import com.aelitis.azureus.core.peermanager.messaging.Message;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.gudy.azureus2.core3.util.DirectByteBuffer;
import org.gudy.azureus2.plugins.messaging.MessageException;
import org.gudy.azureus2.plugins.messaging.generic.GenericMessageEndpoint;
import org.gudy.azureus2.plugins.network.RateLimiter;
import org.gudy.azureus2.plugins.utils.PooledByteBuffer;
import org.gudy.azureus2.pluginsimpl.local.utils.PooledByteBufferImpl;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.messaging:
//			GenericMessage, GenericMessageConnectionAdapter, GenericMessageDecoder, GenericMessageEncoder, 
//			GenericMessageEndpointImpl, GenericMessageConnectionImpl

public class GenericMessageConnectionDirect
	implements GenericMessageConnectionAdapter
{

	public static final int MAX_MESSAGE_SIZE = 0x40000;
	private GenericMessageConnectionImpl owner;
	private String msg_id;
	private String msg_desc;
	private int stream_crypto;
	private byte shared_secrets[][];
	private GenericMessageEndpointImpl endpoint;
	private NetworkConnection connection;
	private volatile boolean connected;
	private boolean processing;
	private volatile boolean closed;
	private List inbound_rls;
	private List outbound_rls;

	protected static GenericMessageConnectionDirect receive(GenericMessageEndpointImpl endpoint, String msg_id, String msg_desc, int stream_crypto, byte shared_secrets[][])
	{
		GenericMessageConnectionDirect direct_connection = new GenericMessageConnectionDirect(msg_id, msg_desc, endpoint, stream_crypto, shared_secrets);
		return direct_connection;
	}

	protected GenericMessageConnectionDirect(String _msg_id, String _msg_desc, GenericMessageEndpointImpl _endpoint, int _stream_crypto, byte _shared_secrets[][])
	{
		msg_id = _msg_id;
		msg_desc = _msg_desc;
		endpoint = _endpoint;
		stream_crypto = _stream_crypto;
		shared_secrets = _shared_secrets;
	}

	public void setOwner(GenericMessageConnectionImpl _owner)
	{
		owner = _owner;
	}

	public int getMaximumMessageSize()
	{
		return 0x40000;
	}

	public String getType()
	{
		if (connection == null)
			return "";
		Transport transport = connection.getTransport();
		if (transport == null)
			return "";
		else
			return transport.getEncryption(true);
	}

	public int getTransportType()
	{
		if (connection == null)
			return 0;
		Transport t = connection.getTransport();
		if (t == null)
			return 0;
		return !t.isTCP() ? 0 : 0;
	}

	public void addInboundRateLimiter(RateLimiter limiter)
	{
		synchronized (this)
		{
			if (processing)
			{
				connection.addRateLimiter(limiter, false);
			} else
			{
				if (inbound_rls == null)
					inbound_rls = new ArrayList();
				inbound_rls.add(limiter);
			}
		}
	}

	public void removeInboundRateLimiter(RateLimiter limiter)
	{
		synchronized (this)
		{
			if (processing)
				connection.removeRateLimiter(limiter, false);
			else
			if (inbound_rls != null)
				inbound_rls.remove(limiter);
		}
	}

	public void addOutboundRateLimiter(RateLimiter limiter)
	{
		synchronized (this)
		{
			if (processing)
			{
				connection.addRateLimiter(limiter, true);
			} else
			{
				if (outbound_rls == null)
					outbound_rls = new ArrayList();
				outbound_rls.add(limiter);
			}
		}
	}

	public void removeOutboundRateLimiter(RateLimiter limiter)
	{
		synchronized (this)
		{
			if (processing)
				connection.removeRateLimiter(limiter, true);
			else
			if (outbound_rls != null)
				outbound_rls.remove(limiter);
		}
	}

	protected void connect(NetworkConnection _connection)
	{
		connection = _connection;
		connection.connect(3, new com.aelitis.azureus.core.networkmanager.NetworkConnection.ConnectionListener() {

			final GenericMessageConnectionDirect this$0;

			public void connectStarted()
			{
			}

			public void connectSuccess(ByteBuffer remaining_initial_data)
			{
				connected = true;
			}

			public void connectFailure(Throwable failure_msg)
			{
				owner.reportFailed(failure_msg);
				connection.close();
			}

			public void exceptionThrown(Throwable error)
			{
				owner.reportFailed(error);
				connection.close();
			}

			public String getDescription()
			{
				return (new StringBuilder()).append("generic connection: ").append(endpoint.getNotionalAddress()).toString();
			}

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

	public void accepted()
	{
		startProcessing();
	}

	public GenericMessageEndpoint getEndpoint()
	{
		return endpoint;
	}

	public void connect(ByteBuffer upper_initial_data, final GenericMessageConnectionAdapter.ConnectionListener listener)
	{
		if (connected)
			return;
		ConnectionEndpoint cep = endpoint.getConnectionEndpoint();
		cep = cep.getLANAdjustedEndpoint();
		connection = NetworkManager.getSingleton().createConnection(cep, new GenericMessageEncoder(), new GenericMessageDecoder(msg_id, msg_desc), stream_crypto != 1, stream_crypto != 3, shared_secrets);
		ByteBuffer initial_data = ByteBuffer.wrap(msg_id.getBytes());
		if (upper_initial_data != null)
		{
			GenericMessage gm = new GenericMessage(msg_id, msg_desc, new DirectByteBuffer(upper_initial_data), false);
			DirectByteBuffer payload[] = (new GenericMessageEncoder()).encodeMessage(gm)[0].getRawData();
			int size = initial_data.remaining();
			for (int i = 0; i < payload.length; i++)
				size += payload[i].remaining((byte)11);

			ByteBuffer temp = ByteBuffer.allocate(size);
			temp.put(initial_data);
			for (int i = 0; i < payload.length; i++)
				temp.put(payload[i].getBuffer((byte)11));

			temp.rewind();
			initial_data = temp;
		}
		connection.connect(initial_data, 3, new com.aelitis.azureus.core.networkmanager.NetworkConnection.ConnectionListener() {

			final GenericMessageConnectionAdapter.ConnectionListener val$listener;
			final GenericMessageConnectionDirect this$0;

			public void connectStarted()
			{
			}

			public void connectSuccess(ByteBuffer remaining_initial_data)
			{
				connected = true;
				try
				{
					if (remaining_initial_data != null && remaining_initial_data.remaining() > 0)
						connection.getOutgoingMessageQueue().addMessage(new GenericMessage(msg_id, msg_desc, new DirectByteBuffer(remaining_initial_data), true), false);
					listener.connectSuccess();
					startProcessing();
				}
				catch (Throwable e)
				{
					connectFailure(e);
				}
			}

			public void connectFailure(Throwable failure_msg)
			{
				listener.connectFailure(failure_msg);
				connection.close();
			}

			public void exceptionThrown(Throwable error)
			{
				listener.connectFailure(error);
				connection.close();
			}

			public String getDescription()
			{
				return "generic connection";
			}

			
			{
				this$0 = GenericMessageConnectionDirect.this;
				listener = connectionlistener;
				super();
			}
		});
	}

	protected void startProcessing()
	{
		connection.getIncomingMessageQueue().registerQueueListener(new com.aelitis.azureus.core.networkmanager.IncomingMessageQueue.MessageQueueListener() {

			final GenericMessageConnectionDirect this$0;

			public boolean messageReceived(Message _message)
			{
				GenericMessage message = (GenericMessage)_message;
				owner.receive(message);
				return true;
			}

			public void protocolBytesReceived(int j)
			{
			}

			public void dataBytesReceived(int j)
			{
			}

			
			{
				this$0 = GenericMessageConnectionDirect.this;
				super();
			}
		});
		connection.getOutgoingMessageQueue().registerQueueListener(new com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue.MessageQueueListener() {

			final GenericMessageConnectionDirect this$0;

			public boolean messageAdded(Message message)
			{
				return true;
			}

			public void messageQueued(Message message1)
			{
			}

			public void messageRemoved(Message message1)
			{
			}

			public void messageSent(Message message1)
			{
			}

			public void protocolBytesSent(int j)
			{
			}

			public void dataBytesSent(int j)
			{
			}

			public void flush()
			{
			}

			
			{
				this$0 = GenericMessageConnectionDirect.this;
				super();
			}
		});
		connection.startMessageProcessing();
		connection.enableEnhancedMessageProcessing(true);
		synchronized (this)
		{
			if (inbound_rls != null)
			{
				for (int i = 0; i < inbound_rls.size(); i++)
					connection.addRateLimiter((LimitedRateGroup)inbound_rls.get(i), false);

				inbound_rls = null;
			}
			if (outbound_rls != null)
			{
				for (int i = 0; i < outbound_rls.size(); i++)
					connection.addRateLimiter((LimitedRateGroup)outbound_rls.get(i), true);

				inbound_rls = null;
			}
			processing = true;
		}
	}

	public void send(PooledByteBuffer data)
		throws MessageException
	{
		if (!connected)
			throw new MessageException("not connected");
		PooledByteBufferImpl impl = (PooledByteBufferImpl)data;
		try
		{
			connection.getOutgoingMessageQueue().addMessage(new GenericMessage(msg_id, msg_desc, impl.getBuffer(), false), false);
		}
		catch (Throwable e)
		{
			throw new MessageException("send failed", e);
		}
	}

	public void close()
		throws MessageException
	{
		if (!connected)
			throw new MessageException("not connected");
		if (!closed)
		{
			closed = true;
			connection.close();
		}
	}






}

⌨️ 快捷键说明

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