Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
pcp.h File Reference
#include <netaddress.h>
#include <util/threadinterrupt.h>
#include <variant>
Include dependency graph for pcp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MappingResult
 Successful response to a port mapping. More...

Typedefs

typedef std::array< uint8_t, PCP_MAP_NONCE_SIZEPCPMappingNonce
 PCP mapping nonce. Arbitrary data chosen by the client to identify a mapping.

Enumerations

enum class  MappingError { NETWORK_ERROR , PROTOCOL_ERROR , UNSUPP_VERSION , NO_RESOURCES }
 Unsuccessful response to a port mapping. More...

Functions

std::variant< MappingResult, MappingErrorNATPMPRequestPortMap (const CNetAddr &gateway, uint16_t port, uint32_t lifetime, CThreadInterrupt &interrupt, int num_tries=3, std::chrono::milliseconds timeout_per_try=std::chrono::milliseconds(1000))
std::variant< MappingResult, MappingErrorPCPRequestPortMap (const PCPMappingNonce &nonce, const CNetAddr &gateway, const CNetAddr &bind, uint16_t port, uint32_t lifetime, CThreadInterrupt &interrupt, int num_tries=3, std::chrono::milliseconds timeout_per_try=std::chrono::milliseconds(1000))

Variables

constexpr size_t PCP_MAP_NONCE_SIZE = 12
 Mapping nonce size in bytes (see RFC6887 section 11.1).

Typedef Documentation

◆ PCPMappingNonce

typedef std::array<uint8_t, PCP_MAP_NONCE_SIZE> PCPMappingNonce

PCP mapping nonce. Arbitrary data chosen by the client to identify a mapping.

Definition at line 20 of file pcp.h.

Enumeration Type Documentation

◆ MappingError

enum class MappingError
strong

Unsuccessful response to a port mapping.

Enumerator
NETWORK_ERROR 

Any kind of network-level error.

PROTOCOL_ERROR 

Any kind of protocol-level error, except unsupported version or no resources.

UNSUPP_VERSION 

Unsupported protocol version.

NO_RESOURCES 

No resources available (port probably already mapped).

Definition at line 23 of file pcp.h.

Function Documentation

◆ NATPMPRequestPortMap()

std::variant< MappingResult, MappingError > NATPMPRequestPortMap ( const CNetAddr & gateway,
uint16_t port,
uint32_t lifetime,
CThreadInterrupt & interrupt,
int num_tries = 3,
std::chrono::milliseconds timeout_per_try = std::chrono::milliseconds(1000) )

Try to open a port using RFC 6886 NAT-PMP. IPv4 only.

  • gateway: Destination address for PCP requests (usually the default gateway).
  • port: Internal port, and desired external port.
  • lifetime: Requested lifetime in seconds for mapping. The server may assign as shorter or longer lifetime. A lifetime of 0 deletes the mapping.
  • num_tries: Number of tries in case of no response.

Returns the external_ip:external_port of the mapping if successful, otherwise a MappingError.

Definition at line 282 of file pcp.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PCPRequestPortMap()

std::variant< MappingResult, MappingError > PCPRequestPortMap ( const PCPMappingNonce & nonce,
const CNetAddr & gateway,
const CNetAddr & bind,
uint16_t port,
uint32_t lifetime,
CThreadInterrupt & interrupt,
int num_tries = 3,
std::chrono::milliseconds timeout_per_try = std::chrono::milliseconds(1000) )

Try to open a port using RFC 6887 Port Control Protocol (PCP). Handles IPv4 and IPv6.

  • nonce: Mapping cookie. Keep this the same over renewals.
  • gateway: Destination address for PCP requests (usually the default gateway).
  • bind: Specific local bind address for IPv6 pinholing. Set this as INADDR_ANY for IPv4.
  • port: Internal port, and desired external port.
  • lifetime: Requested lifetime in seconds for mapping. The server may assign as shorter or longer lifetime. A lifetime of 0 deletes the mapping.
  • num_tries: Number of tries in case of no response.

Returns the external_ip:external_port of the mapping if successful, otherwise a MappingError.

Definition at line 406 of file pcp.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ PCP_MAP_NONCE_SIZE

size_t PCP_MAP_NONCE_SIZE = 12
constexpr

Mapping nonce size in bytes (see RFC6887 section 11.1).

Definition at line 17 of file pcp.h.