FileDocCategorySizeDatePackage
NatPMPImpl.javaAPI DocAzureus 3.0.3.45553Sun Jul 09 07:06:14 BST 2006com.aelitis.net.natpmp.upnp.impl

NatPMPImpl

public class NatPMPImpl extends Object

Fields Summary
private com.aelitis.net.natpmp.NatPMPDevice
natDevice
private List
mappings
Constructors Summary
public NatPMPImpl(com.aelitis.net.natpmp.NatPMPDevice device)

 // not synchronized!
    

    
          
        try {
            natDevice = device;
        } catch( Exception e) {
            throw( new UPnPException( "Error in getting NatPMP Service!" ));
        }
    
Methods Summary
public voidaddPortMapping(boolean tcp, int port, java.lang.String description)
Azureus framework methods

see:
...service/UPnPSSWANConnectionImpl.java

        try{
            /* use public port for internal port */
            natDevice.addPortMapping( tcp, port, port );
        } catch( Exception e) {
            throw( new UPnPException( "addPortMapping failed", e ));
        }
        
        synchronized( this ){
	        /* Find and remove old mapping, if any */
	        Iterator it = mappings.iterator();
	        while( it.hasNext() ) {
	            portMapping m = (portMapping)it.next();
	                
	            if (m.getExternalPort() == port && m.isTCP() == tcp) 
	                it.remove() ;
	        }
	        /* add new port to list */   
	        mappings.add(   new portMapping( port, tcp, 
	                        natDevice.getLocalAddress().getHostAddress(), 
	                        description) );
        }
    
public voiddeletePortMapping(boolean tcp, int port)

        try {
            natDevice.deletePortMapping( tcp, port, port );
        } catch ( Exception e) {
            throw( new UPnPException("deletePortMapping failed", e) );
        }
        
        synchronized( this ){
	        /* Delete from the mappings */
	        Iterator it = mappings.iterator();
	        while( it.hasNext() ) {
	            portMapping m = (portMapping)it.next();
	                
	            if (m.getExternalPort() == port && m.isTCP() == tcp) 
	                it.remove() ;       
	        }
        }
    
public java.lang.StringgetExternalIPAddress()

		return(natDevice.getExternalIPAddress());
	
public com.aelitis.net.upnp.services.UPnPWANConnectionPortMapping[]getPortMappings()

    	  synchronized( this ){
	        /* Check UPnPSSWANConnectionImpl.java for hints */
	        UPnPWANConnectionPortMapping[] res2 = new UPnPWANConnectionPortMapping[mappings.size()];
	        mappings.toArray(res2);
	        return res2;
    	  }
    
public java.lang.String[]getStatusInfo()

        String connection_status    = null;
        String connection_error     = null;
        String uptime               = null;
        
        /* can we ping the NAT for this info? */
        uptime = "" + natDevice.getEpoch();
        return( new String[] { connection_status, connection_error, uptime } );