FileDocCategorySizeDatePackage
TRTrackerServerPeerImpl.javaAPI DocAzureus 3.0.3.48169Tue Jun 05 13:18:14 BST 2007org.gudy.azureus2.core3.tracker.server.impl

TRTrackerServerPeerImpl

public class TRTrackerServerPeerImpl extends Object implements HostNameToIPResolverListener, TRTrackerServerNatCheckerListener, TRTrackerServerPeer

Fields Summary
private HashWrapper
peer_id
private int
key_hash_code
private byte[]
ip
private boolean
ip_override
private short
tcp_port
private short
udp_port
private short
http_port
private byte
crypto_level
private byte
az_ver
private String
ip_str
private byte[]
ip_bytes
private byte
NAT_status
private long
timeout
private long
uploaded
private long
downloaded
private long
amount_left
private long
last_contact_time
private boolean
download_completed
private boolean
biased
private short
up_speed
private com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition
network_position
private Object
user_data
Constructors Summary
protected TRTrackerServerPeerImpl(HashWrapper _peer_id, int _key_hash_code, byte[] _ip, boolean _ip_override, int _tcp_port, int _udp_port, int _http_port, byte _crypto_level, byte _az_ver, long _last_contact_time, boolean _download_completed, byte _last_nat_status, int _up_speed, com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition _network_position)

	
	
	
					
							
						
						
							
							
							
						
						
						
						
						
							
			 
	
		peer_id				= _peer_id;
		key_hash_code		= _key_hash_code;
		ip					= _ip;
		ip_override			= _ip_override;
		tcp_port			= (short)_tcp_port;
		udp_port			= (short)_udp_port;
		http_port			= (short)_http_port;
		crypto_level		= _crypto_level;
		az_ver				= _az_ver;
		last_contact_time	= _last_contact_time;
		download_completed	= _download_completed;
		NAT_status			= _last_nat_status;	
		up_speed			= _up_speed>Short.MAX_VALUE?Short.MAX_VALUE:(short)_up_speed;
		network_position	= _network_position;
			
		resolveAndCheckNAT();
	
Methods Summary
public voidNATCheckComplete(boolean ok)

		if ( ok ){
			
			NAT_status = NAT_CHECK_OK;
			
		}else{
			
			NAT_status	= NAT_CHECK_FAILED;
		}
	
protected bytegetAZVer()

		return( az_ver );
	
public longgetAmountLeft()

		return( amount_left );
	
protected bytegetCryptoLevel()

		return( crypto_level );
	
protected booleangetDownloadCompleted()

		return( download_completed );
	
public longgetDownloaded()

		return( downloaded );
	
protected intgetHTTPPort()

		return( http_port&0xffff );
	
public java.lang.StringgetIP()
If asynchronous resolution of the address is required, this will return the non-resolved address until the async process completes

		
		return( ip_str );
	
protected byte[]getIPAddressBytes()
This will return in resolution of the address is not complete or fails

return

		return( ip_bytes );
	
protected byte[]getIPAsRead()

		return( ip );
	
public java.lang.StringgetIPRaw()

		return( new String(ip));
	
protected intgetKeyHashCode()

		return( key_hash_code );
	
protected longgetLastContactTime()

		return( last_contact_time );
	
public bytegetNATStatus()

		return( NAT_status );
	
protected com.aelitis.azureus.core.dht.netcoords.DHTNetworkPositiongetNetworkPosition()

		return( network_position );
	
public byte[]getPeerID()

		return( peer_id.getBytes());
	
protected HashWrappergetPeerId()

		return( peer_id );
	
public intgetSecsToLive()

		return((int)(( timeout - SystemTime.getCurrentTime())/1000 ));
	
protected java.lang.StringgetString()

		return( new String(ip) + ":" + getTCPPort() + "(" + new String(peer_id.getHash()) + ")" );
	
public intgetTCPPort()

		return( tcp_port&0xffff );
	
protected longgetTimeout()

		return( timeout );
	
protected intgetUDPPort()

		return( udp_port&0xffff );
	
protected intgetUpSpeed()

		return( up_speed&0xffff );
	
public longgetUploaded()

		return( uploaded );
	
public java.lang.ObjectgetUserData(java.lang.Object key)

		if ( user_data == null ){
			
			return( null );
			
		}else if( user_data instanceof Object[]){
			
			Object[]	x = (Object[])user_data;
			
			if ( x[0] == key ){
				
				return( x[1] );
				
			}else{
				
				return( null );
			}
		}else{
			
			return(((Map)user_data).get(key));
		}
	
public voidhostNameResolutionComplete(java.net.InetAddress address)

		if ( address != null ){
			
			ip_str 		= address.getHostAddress();
			
			ip_bytes	= address.getAddress();
		}
	
public booleanisBiased()

		return( biased );
	
protected booleanisIPOverride()

		return( ip_override );
	
protected booleanisNATStatusBad()

		return( NAT_status == NAT_CHECK_FAILED || NAT_status == NAT_CHECK_FAILED_AND_REPORTED );
	
protected booleanisSeed()

		return( amount_left == 0 );
	
protected voidresolveAndCheckNAT()

		// default values pending resolution
		
		ip_str 		= new String( ip );
		ip_bytes	= null;
		
		HostNameToIPResolver.addResolverRequest( ip_str, this );
		
			// a port of 0 is taken to mean that the client can't/won't receive incoming
			// connections - tr

		if ( tcp_port == 0 ){
			
			NAT_status = NAT_CHECK_FAILED_AND_REPORTED;
			
		}else{
			
				// only recheck if we haven't already ascertained the state
			
			if ( NAT_status == NAT_CHECK_UNKNOWN ){
				
				NAT_status	= NAT_CHECK_INITIATED;
				
				if ( !TRTrackerServerNATChecker.getSingleton().addNATCheckRequest( ip_str, getTCPPort(), this )){
					
					NAT_status = NAT_CHECK_DISABLED;
				}
			}	
		}
	
public voidsetBiased(boolean _biased)

		biased	= _biased;
	
protected voidsetDownloadCompleted()

		download_completed	= true;
	
protected voidsetNATStatus(byte status)

		NAT_status	= status;
	
protected voidsetStats(long _uploaded, long _downloaded, long _amount_left)

		uploaded	= _uploaded;
		downloaded	= _downloaded;
		amount_left	= _amount_left;
	
protected voidsetTimeout(long _now, long _timeout)

		last_contact_time	= _now;
		
		timeout				= _timeout;
	
public voidsetUserData(java.lang.Object key, java.lang.Object data)

		if ( user_data == null ){
			
			user_data = new Object[]{ key, data };
			
		}else if ( user_data instanceof Object[]){
			
			Object[]	x = (Object[])user_data;
			
			if ( x[0] == key ){
				
				x[1] = data;
				
			}else{
				
				HashMap	map = new HashMap();
				
				user_data = map;
				
				map.put( x[0], x[1] );
				
				map.put( key, data );
			}
		}else{
			
			((Map)user_data).put( key, data );
		}
	
protected booleanupdate(byte[] _ip, int _port, int _udp_port, int _http_port, byte _crypto_level, byte _az_ver, int _up_speed, com.aelitis.azureus.core.dht.netcoords.DHTNetworkPosition _network_position)

		udp_port			= (short)_udp_port;
		http_port			= (short)_http_port;
		crypto_level		= _crypto_level;
		az_ver				= _az_ver;
		up_speed			= _up_speed>Short.MAX_VALUE?Short.MAX_VALUE:(short)_up_speed;
		network_position	= _network_position;
		
		boolean	res	= false;
		
		if ( _port != getTCPPort() ){
			
			tcp_port	= (short)_port;
			
			res		= true;
		}
		
		if ( !Arrays.equals( _ip, ip )){
			
			ip			= _ip;
	
			res	= true;	
		}
		
		if ( res ){
			
			resolveAndCheckNAT();
		}
		
		return( res );