Package org.drasyl.util.protocol
Class PcpPortUtil
- java.lang.Object
-
- org.drasyl.util.protocol.PcpPortUtil
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PcpPortUtil.MappingResponseMessage
static interface
PcpPortUtil.Message
static class
PcpPortUtil.ResultCode
-
Field Summary
Fields Modifier and Type Field Description static int
EPOCH_TIME_LENGTH
static int
EXTERNAL_SUGGESTED_ADDRESS_LENGTH
static int
LIFETIME_LENGTH
static int
MAP_OPCODE
static int
MAPPING_NONCE_LENGTH
static int
PCP_PORT
static int
PCP_VERSION
static int
PROTO_TCP
static int
PROTO_UDP
static int
REQUEST_RESERVED1_LENGTH
static int
REQUEST_RESERVED2_LENGTH
static int
RESPONSE_RESERVED1_LENGTH
static int
RESPONSE_RESERVED2_LENGTH
static int
RESPONSE_RESERVED3_LENGTH
static InetAddress
ZERO_IPV4
static InetAddress
ZERO_IPV6
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
buildMappingRequestMessage(Duration lifetime, InetAddress clientAddress, byte[] nonce, int protocol, int port, InetAddress externalAddress)
All MAP opcode requests have the following format: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Version = 2 |R| Opcode | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Requested Lifetime (32 bits) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | PCP Client's IP Address (128 bits) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Mapping Nonce (96 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Protocol | Reserved (24 bits) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Internal Port | Suggested External Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Suggested External IP Address (128 bits) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ These fields are described below: Version: This document specifies protocol version 2.static PcpPortUtil.Message
readMessage(InputStream inputStream)
-
-
-
Field Detail
-
PCP_PORT
public static final int PCP_PORT
- See Also:
- Constant Field Values
-
PCP_VERSION
public static final int PCP_VERSION
- See Also:
- Constant Field Values
-
MAP_OPCODE
public static final int MAP_OPCODE
- See Also:
- Constant Field Values
-
PROTO_TCP
public static final int PROTO_TCP
- See Also:
- Constant Field Values
-
PROTO_UDP
public static final int PROTO_UDP
- See Also:
- Constant Field Values
-
ZERO_IPV6
public static final InetAddress ZERO_IPV6
-
ZERO_IPV4
public static final InetAddress ZERO_IPV4
-
LIFETIME_LENGTH
public static final int LIFETIME_LENGTH
- See Also:
- Constant Field Values
-
EPOCH_TIME_LENGTH
public static final int EPOCH_TIME_LENGTH
- See Also:
- Constant Field Values
-
MAPPING_NONCE_LENGTH
public static final int MAPPING_NONCE_LENGTH
- See Also:
- Constant Field Values
-
EXTERNAL_SUGGESTED_ADDRESS_LENGTH
public static final int EXTERNAL_SUGGESTED_ADDRESS_LENGTH
- See Also:
- Constant Field Values
-
REQUEST_RESERVED1_LENGTH
public static final int REQUEST_RESERVED1_LENGTH
- See Also:
- Constant Field Values
-
REQUEST_RESERVED2_LENGTH
public static final int REQUEST_RESERVED2_LENGTH
- See Also:
- Constant Field Values
-
RESPONSE_RESERVED1_LENGTH
public static final int RESPONSE_RESERVED1_LENGTH
- See Also:
- Constant Field Values
-
RESPONSE_RESERVED2_LENGTH
public static final int RESPONSE_RESERVED2_LENGTH
- See Also:
- Constant Field Values
-
RESPONSE_RESERVED3_LENGTH
public static final int RESPONSE_RESERVED3_LENGTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
buildMappingRequestMessage
public static byte[] buildMappingRequestMessage(Duration lifetime, InetAddress clientAddress, byte[] nonce, int protocol, int port, InetAddress externalAddress)
All MAP opcode requests have the following format: 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Version = 2 |R| Opcode | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Requested Lifetime (32 bits) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | PCP Client's IP Address (128 bits) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Mapping Nonce (96 bits) | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Protocol | Reserved (24 bits) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Internal Port | Suggested External Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | Suggested External IP Address (128 bits) | | | | | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ These fields are described below: Version: This document specifies protocol version 2. PCP clients and servers compliant with this document use the value 2. This field is used for version negotiation as described in Section 9. R: Indicates Request (0) or Response (1). Opcode: A 7-bit value specifying the operation to be performed. MAP and PEER Opcodes are defined in Sections 11 and 12. Reserved: 16 reserved bits. MUST be zero on transmission and MUST be ignored on reception. Requested Lifetime: An unsigned 32-bit integer, in seconds, ranging from 0 to 2^32-1 seconds. Requested lifetime of this mapping, in seconds. The value 0 indicates "delete". PCP Client's IP Address: The source IPv4 or IPv6 address in the IP header used by the PCP client when sending this PCP request. An IPv4 address is represented using an IPv4-mapped IPv6 address. The PCP Client IP Address in the PCP message header is used to detect an unexpected NAT on the path between the PCP client and the PCP-controlled NAT or firewall device. See Section 8.1. Mapping Nonce: Random value chosen by the PCP client. See Section 11.2, "Generating a MAP Request". Zero is a legal value (but unlikely, occurring in roughly one in 2^96 requests). Protocol: Upper-layer protocol associated with this Opcode. Values are taken from the IANA protocol registry [proto_numbers]. For example, this field contains 6 (TCP) if the Opcode is intended to create a TCP mapping. This field contains 17 (UDP) if the Opcode is intended to create a UDP mapping. The value 0 has a special meaning for 'all protocols'. Reserved: 24 reserved bits, MUST be sent as 0 and MUST be ignored when received. Internal Port: Internal port for the mapping. The value 0 indicates 'all ports', and is legal when the lifetime is zero (a delete request), if the protocol does not use 16-bit port numbers, or the client is requesting 'all ports'. If the protocol is zero (meaning 'all protocols'), then internal port MUST be zero on transmission and MUST be ignored on reception. Suggested External Port: Suggested external port for the mapping. This is useful for refreshing a mapping, especially after the PCP server loses state. If the PCP client does not know the external port, or does not have a preference, it MUST use 0. Suggested External IP Address: Suggested external IPv4 or IPv6 address. This is useful for refreshing a mapping, especially after the PCP server loses state. If the PCP client does not know the external address, or does not have a preference, it MUST use the address-family-specific all-zeros address (see Section 5).
- Throws:
IllegalArgumentException
- ifport
is not in range of [0, 2^16 - 1]
-
readMessage
public static PcpPortUtil.Message readMessage(InputStream inputStream) throws IOException
- Throws:
IOException
-
-