FileDocCategorySizeDatePackage
AddressUtils.javaAPI DocAzureus 3.0.3.43684Wed Sep 19 09:55:38 BST 2007org.gudy.azureus2.core3.util

AddressUtils

public class AddressUtils extends Object

Fields Summary
public static final byte
LAN_LOCAL_MAYBE
public static final byte
LAN_LOCAL_YES
public static final byte
LAN_LOCAL_NO
private static com.aelitis.azureus.core.instancemanager.AZInstanceManager
instance_manager
Constructors Summary
Methods Summary
public static java.net.InetSocketAddressadjustDHTAddress(java.net.InetSocketAddress address, boolean ext_to_lan)

		if ( instance_manager == null ){
			
			try{
				instance_manager = AzureusCoreFactory.getSingleton().getInstanceManager();
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
		}
		
		if ( instance_manager == null || !instance_manager.isInitialized()){
			
			return( address );
		}
		
		InetSocketAddress	adjusted_address;
		
		if ( ext_to_lan ){
			
			adjusted_address	= instance_manager.getLANAddress( address, AZInstanceManager.AT_UDP_NON_DATA );
			
		}else{

			adjusted_address	= instance_manager.getExternalAddress( address, AZInstanceManager.AT_UDP_NON_DATA );
		}
		
		if ( adjusted_address == null ){
			
			adjusted_address	= address;
			
		}else{
		
			// System.out.println( "adj: " + address + "/" + ext_to_lan + " -> " + adjusted_address );
		}
		
		return( adjusted_address );
	
public static java.net.URLadjustURL(java.net.URL url)

	
	  
	
				 
	
		url = AEProxyFactory.getAddressMapper().internalise( url );

		return( url );
	
public static byteisLANLocalAddress(java.net.InetSocketAddress socket_address)

		InetAddress address = socket_address.getAddress();
		
		return( isLANLocalAddress( address ));
	
public static byteisLANLocalAddress(java.net.InetAddress address)

			// if someone passes us an unresolved address then handle sensibly
		
		if ( address == null ){
			
			return( LAN_LOCAL_NO );
		}
		
		if ( instance_manager == null ){
			
			if ( AzureusCoreFactory.isCoreAvailable()){
				
				try{
					instance_manager = AzureusCoreFactory.getSingleton().getInstanceManager();
					
				}catch( Throwable e ){
					
					Debug.printStackTrace(e);
				}
			}
		}
		
		if ( instance_manager == null || !instance_manager.isInitialized()){
			
			return( LAN_LOCAL_MAYBE );
		}
		
		return( instance_manager.isLANAddress( address )? LAN_LOCAL_YES:LAN_LOCAL_NO);
	
public static byteisLANLocalAddress(java.lang.String address)

		byte is_lan_local = LAN_LOCAL_MAYBE;
		
		try {
			is_lan_local = isLANLocalAddress( HostNameToIPResolver.syncResolve( address ));
			
		}catch( Throwable t ){
			
			t.printStackTrace();  
		}
		
		return is_lan_local;