FileDocCategorySizeDatePackage
DHTTransportUDPContactImpl.javaAPI DocAzureus 3.0.3.48377Tue Jul 04 05:03:48 BST 2006com.aelitis.azureus.core.dht.transport.udp.impl

DHTTransportUDPContactImpl

public class DHTTransportUDPContactImpl extends Object implements DHTTransportUDPContact
author
parg

Fields Summary
public static final int
NODE_STATUS_UNKNOWN
public static final int
NODE_STATUS_ROUTABLE
private DHTTransportUDPImpl
transport
private InetSocketAddress
external_address
private InetSocketAddress
transport_address
private byte[]
id
private byte
protocol_version
private int
instance_id
private long
skew
private int
random_id
private int
node_status
private com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition[]
network_positions
Constructors Summary
protected DHTTransportUDPContactImpl(boolean _is_local, DHTTransportUDPImpl _transport, InetSocketAddress _transport_address, InetSocketAddress _external_address, byte _protocol_version, int _instance_id, long _skew)

	
	
	
							
				
				
				
							
								
							 
	
		 
	
		transport				= _transport;
		transport_address		= _transport_address;
		external_address		= _external_address;
		protocol_version		= _protocol_version;
		
		if ( transport_address.equals( external_address )){
			
			external_address	= transport_address;
		}
		
		instance_id		=		 _instance_id;
		skew			= 		_skew;
		
		if ( 	transport_address == external_address ||
				transport_address.getAddress().equals( external_address.getAddress())){

			id = DHTUDPUtils.getNodeID( external_address, protocol_version );
		}
		
		network_positions	= DHTNetworkPositionManager.createPositions( id==null?DHTUDPUtils.getBogusNodeID():id, _is_local );
	
Methods Summary
protected booleanaddressMatchesID()

		return( id != null );
	
public voidexportContact(java.io.DataOutputStream os)

		transport.exportContact( this, os );
	
public java.net.InetSocketAddressgetAddress()

		return( getExternalAddress());
	
public longgetClockSkew()

		return( skew );
	
public java.net.InetSocketAddressgetExternalAddress()

		return( external_address );
	
public byte[]getID()

		if ( id == null ){
			
			throw( new RuntimeException( "Invalid contact" ));
		}
		
		return( id );
	
public intgetInstanceID()

		return( instance_id );
	
public intgetMaxFailForLiveCount()

		return( transport.getMaxFailForLiveCount() );
	
public intgetMaxFailForUnknownCount()

		return( transport.getMaxFailForUnknownCount() );
	
public java.lang.StringgetName()

		return( DHTLog.getString2( id  ));
	
public com.aelitis.azureus.core.dht.netcoords.DHTNetworkPositiongetNetworkPosition(byte position_type)

  		for (int i=0;i<network_positions.length;i++){
  			
  			if ( network_positions[i].getPositionType() == position_type ){
  				
  				return( network_positions[i] );
  			}
  		}
  		
  		return( null );
  	
public com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition[]getNetworkPositions()

		return( network_positions );
	
protected intgetNodeStatus()

		return( node_status );
	
public bytegetProtocolVersion()

		return( protocol_version );
	
public intgetRandomID()

		return( random_id );
	
public DHTTransportFullStatsgetStats()

		return( transport.getFullStats( this ));
	
public java.lang.StringgetString()

		if ( transport_address.equals( external_address )){
			
			return( DHTLog.getString2(id) + "["+transport_address.toString()+",V" + getProtocolVersion() +"]");
		}
		
		return( DHTLog.getString2(id) + "[tran="+transport_address.toString()+",ext="+external_address+",V" + getProtocolVersion() +"]");
	
public DHTTransportgetTransport()

		return( transport );
	
public java.net.InetSocketAddressgetTransportAddress()

		return( transport_address );
	
public booleanisAlive(long timeout)

		final AESemaphore	sem = new AESemaphore( "DHTTransportContact:alive");
		
		final boolean[]	alive = { false };
		
		try{
			sendPing(
				new DHTTransportReplyHandlerAdapter()
				{
					public void
					pingReply(
						DHTTransportContact contact )
					{
						alive[0]	= true;
						
						sem.release();
					}
					
					public void
					failed(
						DHTTransportContact 	contact,
						Throwable 				cause )
					{
						sem.release();
					}
				});
			
			sem.reserve( timeout );
		
			return( alive[0] );
			
		}catch( Throwable e ){
			
			return( false );
		}
	
public booleanisValid()

		return( 	addressMatchesID() &&
					!transport.invalidExternalAddress( external_address.getAddress()));
	
public voidremove()

		transport.removeContact( this );
	
public voidsendFindNode(DHTTransportReplyHandler handler, byte[] nid)

		transport.sendFindNode( this, handler, nid );
	
public voidsendFindValue(DHTTransportReplyHandler handler, byte[] key, int max_values, byte flags)

		transport.sendFindValue( this, handler, key, max_values, flags );
	
public voidsendImmediatePing(DHTTransportReplyHandler handler, long timeout)

		transport.sendImmediatePing( this, handler, timeout );
	
public voidsendKeyBlock(DHTTransportReplyHandler handler, byte[] request, byte[] signature)

			// gotta do anti-spoof
		
		sendFindNode(
			new DHTTransportReplyHandlerAdapter()
			{
				public void
				findNodeReply(
					DHTTransportContact 	contact,
					DHTTransportContact[]	contacts )
				{	
					transport.sendKeyBlockRequest( DHTTransportUDPContactImpl.this, handler, request, signature );
				}
				public void
				failed(
					DHTTransportContact 	_contact,
					Throwable				_error )
				{	
					handler.failed( _contact, _error );
				}
			},
			new byte[0] );
		
	
public voidsendPing(DHTTransportReplyHandler handler)

		transport.sendPing( this, handler );
	
public voidsendStats(DHTTransportReplyHandler handler)

		transport.sendStats( this, handler );
	
public voidsendStore(DHTTransportReplyHandler handler, byte[][] keys, DHTTransportValue[][] value_sets)

		transport.sendStore( this, handler, keys, value_sets );
	
protected voidsetInstanceIDAndVersion(int _instance_id, byte _protocol_version)

		instance_id	= _instance_id;
		
			// target supports a higher version than we thought, update
		
		if ( _protocol_version > protocol_version ){
						
			protocol_version = _protocol_version;
		}
	
protected voidsetNetworkPositions(com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition[] positions)

  		network_positions	= positions;
  	
protected voidsetNodeStatus(int ns)

		node_status	= ns;
	
protected voidsetProtocolVersion(byte v)

		protocol_version 	= v;
	
public voidsetRandomID(int _random_id)

		random_id	= _random_id;
	
public voidsetTransportAddress(java.net.InetSocketAddress address)

		transport_address = address;