Bitcoin Core 28.99.0
P2P Digital Currency
Functions
pcp.cpp File Reference
#include <common/pcp.h>
#include <common/netif.h>
#include <crypto/common.h>
#include <logging.h>
#include <netaddress.h>
#include <netbase.h>
#include <random.h>
#include <span.h>
#include <util/check.h>
#include <util/readwritefile.h>
#include <util/sock.h>
#include <util/strencodings.h>
Include dependency graph for pcp.cpp:

Go to the source code of this file.

Functions

std::variant< MappingResult, MappingErrorNATPMPRequestPortMap (const CNetAddr &gateway, uint16_t port, uint32_t lifetime, int num_tries, std::chrono::milliseconds timeout_per_try)
 Try to open a port using RFC 6886 NAT-PMP. More...
 
std::variant< MappingResult, MappingErrorPCPRequestPortMap (const PCPMappingNonce &nonce, const CNetAddr &gateway, const CNetAddr &bind, uint16_t port, uint32_t lifetime, int num_tries, std::chrono::milliseconds timeout_per_try)
 Try to open a port using RFC 6887 Port Control Protocol (PCP). More...
 

Function Documentation

◆ NATPMPRequestPortMap()

std::variant< MappingResult, MappingError > NATPMPRequestPortMap ( const CNetAddr gateway,
uint16_t  port,
uint32_t  lifetime,
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 274 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,
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 387 of file pcp.cpp.

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