Package org.drasyl.util.protocol
Class PcpPortUtil
java.lang.Object
org.drasyl.util.protocol.PcpPortUtil
Utility class for Port Control Protocol (PCP)-related stuff.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
static enum
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final InetAddress
static final InetAddress
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 Details
-
PCP_PORT
public static final int PCP_PORT- See Also:
-
PCP_VERSION
public static final int PCP_VERSION- See Also:
-
MAP_OPCODE
public static final int MAP_OPCODE- See Also:
-
PROTO_TCP
public static final int PROTO_TCP- See Also:
-
PROTO_UDP
public static final int PROTO_UDP- See Also:
-
ZERO_IPV6
-
ZERO_IPV4
-
LIFETIME_LENGTH
public static final int LIFETIME_LENGTH- See Also:
-
EPOCH_TIME_LENGTH
public static final int EPOCH_TIME_LENGTH- See Also:
-
MAPPING_NONCE_LENGTH
public static final int MAPPING_NONCE_LENGTH- See Also:
-
EXTERNAL_SUGGESTED_ADDRESS_LENGTH
public static final int EXTERNAL_SUGGESTED_ADDRESS_LENGTH- See Also:
-
REQUEST_RESERVED1_LENGTH
public static final int REQUEST_RESERVED1_LENGTH- See Also:
-
REQUEST_RESERVED2_LENGTH
public static final int REQUEST_RESERVED2_LENGTH- See Also:
-
RESPONSE_RESERVED1_LENGTH
public static final int RESPONSE_RESERVED1_LENGTH- See Also:
-
RESPONSE_RESERVED2_LENGTH
public static final int RESPONSE_RESERVED2_LENGTH- See Also:
-
RESPONSE_RESERVED3_LENGTH
public static final int RESPONSE_RESERVED3_LENGTH- See Also:
-
-
Method Details
-
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
- Throws:
IOException
-