Skip to main content

Module pcp

Module pcp 

Source
Expand description

PCP method (RFC 6887) — the successor to NAT-PMP. Same goal (open an inbound pinhole on the gateway) with a richer, IPv6-capable datagram.

PCP is spoken to the gateway on the same port as NAT-PMP (5351). We implement the MAP request / response directly (RFC 6887 §11.1 common header, §11.2 MAP opcode): a 24-byte common header plus a 36-byte MAP body. As with NAT-PMP, the fixed byte layout means encode/parse is fully unit-testable against the RFC with no network; the live attempt sends it and, absent a PCP gateway, times out so the strategy falls through.

Structs§

MapResponse
Parsed PCP MAP response (the fields dig-nat needs).
PcpMethod
The PCP traversal method — requests a MAP mapping from the gateway so inbound peer dials reach this node, then yields a dial address for the peer.

Enums§

PcpError
PCP protocol / transaction errors.

Constants§

OP_MAP
MAP opcode (RFC 6887 §11.2).
PCP_VERSION
PCP version (RFC 6887 — version 2).
PROTO_TCP
IANA protocol number for TCP.
PROTO_UDP
IANA protocol number for UDP (used in the MAP body’s protocol field).
RESPONSE_BIT
The R (response) bit in the opcode byte of a PCP response.
RESULT_SUCCESS
Result code SUCCESS (RFC 6887 §7.4).

Functions§

encode_map_request
Encode a PCP MAP request (RFC 6887 §11.1 header + §11.2 body).
ipv4_gateway
Turn a SocketAddr hint into an IPv4 gateway if possible.
new_nonce
Generate a 96-bit PCP MAP nonce from a CSPRNG (RFC 6887 §11.1 requires the nonce be unpredictable so a peer/attacker cannot forge or overwrite another client’s mapping).
parse_map_response
Parse a PCP MAP response, validating version, the MAP-response opcode, the result code, and the echoed nonce.

Type Aliases§

MapNonce
A 96-bit MAP nonce (RFC 6887 §11.1) matching a response to a request.