Package com.biglybt.net.natpmp.impl
Class NatPMPDeviceImpl
java.lang.Object
com.biglybt.net.natpmp.impl.NatPMPDeviceImpl
- All Implemented Interfaces:
NatPMPDevice
Main class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate NATPMPDeviceAdapter
private String
private InetAddress
private int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final String
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final byte
(package private) static final byte
(package private) static final byte
private static NatPMPDeviceImpl
Singleton creation(package private) static final int
(package private) static final int
private InetAddress
private InetAddress
(package private) static final int
Network Failure (e.g.(package private) static final int
(package private) static final int
Not Authorized/Refused (e.g.(package private) static final int
(package private) static final int
(package private) static final int
private NetworkInterface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addPortMapping
(boolean tcp, int publicPort, int privatePort) Asks for a public port to be mapped to a private port from this host.byteArrayString
(byte[] buf) protected void
boolean
connect()
Try to connect with a NAT-PMP device.private String
void
deletePortMapping
(boolean tcp, int publicPort, int privatePort) Delete a mapped public portint
getEpoch()
static NatPMPDeviceImpl
getSingletonObject
(NATPMPDeviceAdapter adapter) intArrayString
(int[] buf) byte[]
intToByteArray
(int v) Convert a 32-bit int into a 4 byte arrayprotected void
int
portMappingProtocol
(boolean tcp, int publicPort, int privatePort, int lifetime) General port mapping protocolsendNATMsg
(InetAddress dstInet, DatagramPacket dstPkt, byte[] recBuf) Send a request and wait for reply This class should be threaded!!! This sends to the default NATPMP_PORT.byte[]
shortToByteArray
(short v) Convert a 16-bit short into a 2 byte arraystatic int
unsigned16ByteArrayToInt
(byte[] b, int offset) Convert the byte array containing 16-bits to an int starting from the given offset.static int
unsigned32ByteArrayToInt
(byte[] b, int offset) Convert the byte array containing 32-bit to an int starting from the given offset.static int
unsigned8ByteArrayToInt
(byte[] b, int offset) Convert the byte array containing 8-bits to an int starting from the given offset.short
unsignedByteArrayToShort
(byte[] buf)
-
Field Details
-
NATMAP_VER
static final int NATMAP_VER- See Also:
-
NATMAP_PORT
static final int NATMAP_PORT- See Also:
-
NATMAP_RESPONSE_MASK
static final int NATMAP_RESPONSE_MASK- See Also:
-
NATMAP_INIT_RETRY
static final int NATMAP_INIT_RETRY- See Also:
-
NATMAP_MAX_RETRY
static final int NATMAP_MAX_RETRY- See Also:
-
NATMAP_DEFAULT_LEASE
static final int NATMAP_DEFAULT_LEASE- See Also:
-
NATMAP_LLM
- See Also:
-
NATOp_AddrRequest
static final byte NATOp_AddrRequest- See Also:
-
NATOp_MapUDP
static final byte NATOp_MapUDP- See Also:
-
NATOp_MapTCP
static final byte NATOp_MapTCP- See Also:
-
NATAddrRequest
static final int NATAddrRequest- See Also:
-
NATPortMapRequestLen
static final int NATPortMapRequestLen- See Also:
-
NATAddrReplyLen
static final int NATAddrReplyLen- See Also:
-
NATPortMapReplyLen
static final int NATPortMapReplyLen- See Also:
-
NATResultSuccess
static final int NATResultSuccess- See Also:
-
NATResultUnsupportedVer
static final int NATResultUnsupportedVer- See Also:
-
NATResultNotAuth
static final int NATResultNotAuthNot Authorized/Refused (e.g. box supports mapping, but user has turned feature off)- See Also:
-
NATResultNetFailure
static final int NATResultNetFailureNetwork Failure (e.g. NAT box itself has not obtained a DHCP lease)- See Also:
-
NATResultNoResc
static final int NATResultNoResc- See Also:
-
NATResultUnsupportedOp
static final int NATResultUnsupportedOp- See Also:
-
current_router_address
-
hostInet
-
natPriInet
-
natPubInet
-
networkInterface
-
nat_epoch
private int nat_epoch -
adapter
-
NatPMPDeviceSingletonRef
Singleton creation
-
-
Constructor Details
-
NatPMPDeviceImpl
- Throws:
Exception
-
-
Method Details
-
getSingletonObject
- Throws:
Exception
-
checkRouterAddress
- Throws:
Exception
-
sendNATMsg
public DatagramPacket sendNATMsg(InetAddress dstInet, DatagramPacket dstPkt, byte[] recBuf) throws Exception Send a request and wait for reply This class should be threaded!!! This sends to the default NATPMP_PORT.- Parameters:
dstInet
- destination address (should be the private NAT address)dstPkt
- packet to sendrecBuf
- byte buffer big enough to hold received- Throws:
Exception
-
connect
Try to connect with a NAT-PMP device. This could take sometime.- Specified by:
connect
in interfaceNatPMPDevice
- Returns:
- true if it found one
- Throws:
Exception
-
addPortMapping
Asks for a public port to be mapped to a private port from this host. NAP-PMP allows the device to assign another public port if the requested one is taken. So, you should check the returned port.- Specified by:
addPortMapping
in interfaceNatPMPDevice
- Parameters:
tcp
- true TCP, false UDP- Returns:
- the returned publicPort. -1 if error occured
- Throws:
Exception
-
deletePortMapping
Delete a mapped public port- Specified by:
deletePortMapping
in interfaceNatPMPDevice
- Parameters:
tcp
- true TCP, false UDP portpublicPort
- the public port to closeprivatePort
- the private port that it is mapped to- Throws:
Exception
-
portMappingProtocol
public int portMappingProtocol(boolean tcp, int publicPort, int privatePort, int lifetime) throws Exception General port mapping protocol- Throws:
Exception
-
getLocalAddress
- Specified by:
getLocalAddress
in interfaceNatPMPDevice
-
getNetworkInterface
- Specified by:
getNetworkInterface
in interfaceNatPMPDevice
-
getExternalIPAddress
- Specified by:
getExternalIPAddress
in interfaceNatPMPDevice
-
getEpoch
public int getEpoch()- Specified by:
getEpoch
in interfaceNatPMPDevice
-
log
-
unsigned32ByteArrayToInt
public static int unsigned32ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 32-bit to an int starting from the given offset.- Parameters:
b
- The byte arrayoffset
- The array offset- Returns:
- The integer
-
unsigned16ByteArrayToInt
public static int unsigned16ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 16-bits to an int starting from the given offset.- Parameters:
b
- The byte arrayoffset
- The array offset- Returns:
- The integer
-
unsigned8ByteArrayToInt
public static int unsigned8ByteArrayToInt(byte[] b, int offset) Convert the byte array containing 8-bits to an int starting from the given offset.- Parameters:
b
- The byte arrayoffset
- The array offset- Returns:
- The integer
-
unsignedByteArrayToShort
public short unsignedByteArrayToShort(byte[] buf) -
shortToByteArray
public byte[] shortToByteArray(short v) Convert a 16-bit short into a 2 byte array- Returns:
- unsigned byte array
-
intToByteArray
public byte[] intToByteArray(int v) Convert a 32-bit int into a 4 byte array- Returns:
- unsigned byte array
-
intArrayString
-
byteArrayString
-
convertHost2RouterAddress
- Parameters:
init
- takes the host address- Returns:
- String the address as (xxx.xxx.xxx.1)
-