net.tomp2p.natpmp
Class MapRequestMessage

java.lang.Object
  extended by net.tomp2p.natpmp.Message
      extended by net.tomp2p.natpmp.MapRequestMessage

public class MapRequestMessage
extends Message

This class manages an External Address message. This class is thread-safe. After instantiation, this class may be added to the message queue on the NatPmpDevice. It is important to remove the mapping before shutdown of the NatPmpDevice. Refer to the parameters of #MapRequestMessage(boolean, int, int, long, com.hoodcomputing.natpmp.MessageResponseInterface) for details of how to perform this.

Author:
flszen

Constructor Summary
MapRequestMessage(boolean isTCP, int internalPort, int requestedExternalPort, int requestedPortMappingLifetime, MessageResponseInterface listener)
          Constructs a new MapRequestMessage.
 
Method Summary
 Integer getExternalPort()
          Gets the external port that was assigned.
 int getInternalPort()
          Gets the internal port on which mapped data will arrive.
 Integer getPortMappingLifetime()
          Gets the assigned port mapping lifetime.
 int getRequestedExternalPort()
          Get sthe external port that was requested.
 int getRequestedPortMappingLifetime()
          Gets the requested port mapping lifetime.
 
Methods inherited from class net.tomp2p.natpmp.Message
getResponseException, getResultCode, getSecondsSinceEpoch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapRequestMessage

public MapRequestMessage(boolean isTCP,
                         int internalPort,
                         int requestedExternalPort,
                         int requestedPortMappingLifetime,
                         MessageResponseInterface listener)
Constructs a new MapRequestMessage. If requestedPortMappingLifetime is zero, an existing port mapping is removed. If both internalPort and requestedPortMappingLifetime are zero, then all mappings for this host are removed.

Parameters:
isTCP - A value of true indicates that this is a TCP mapping. A value of false indicates that this is a UDP mapping.
internalPort - The port on which this client is listening. A value of zero, along with a lifetime of zero indicates that all port mappings for this client are to be removed.
requestedExternalPort - The external port to request. This port may not be available. Always check the result of the Message to determine which external port is assigned. A value of zero indicates that the NAT-PMP Gateway should choose a port on its own.
requestedPortMappingLifetime - The time, in seconds, to request the mapping for. A value of zero requests that this mapping is removed. Always check the result of the Message to determine the actual lifetime that was assigned, as it may be different than the requested. The recommended port mapping lifetime is 3600 seconds. The protocol specifies an unsigned integer for this parameter, however Java will not support that as a data type. Therefore, the parameter is given as a long. Do not assign values larger than an unsigned int can handle to this parameter.
listener - The MessageResponseInterface that will respond to the message result.
Method Detail

getInternalPort

public int getInternalPort()
Gets the internal port on which mapped data will arrive.

Returns:
The port on this host that is listening.

getRequestedExternalPort

public int getRequestedExternalPort()
Get sthe external port that was requested.

Returns:
The requested external port.

getExternalPort

public Integer getExternalPort()
                        throws NatPmpException
Gets the external port that was assigned.

Returns:
The external port that was assigned.
Throws:
NatPmpException - Thrown if there was an exception generated during the parsing of the respnse.

getRequestedPortMappingLifetime

public int getRequestedPortMappingLifetime()
Gets the requested port mapping lifetime.

Returns:
The requested port mapping lifetime, in seconds.

getPortMappingLifetime

public Integer getPortMappingLifetime()
                               throws NatPmpException
Gets the assigned port mapping lifetime.

Returns:
The assigned port mapping lifetime, in seconds.
Throws:
NatPmpException - Thrown if there was an exception generated during the parsing of the respnse.


Copyright © 2013. All Rights Reserved.