Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
pcp.cpp File Reference
#include <common/pcp.h>
#include <atomic>
#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 <util/threadinterrupt.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, CThreadInterrupt &interrupt, int num_tries, std::chrono::milliseconds timeout_per_try)
std::variant< MappingResult, MappingErrorPCPRequestPortMap (const PCPMappingNonce &nonce, const CNetAddr &gateway, const CNetAddr &bind, uint16_t port, uint32_t lifetime, CThreadInterrupt &interrupt, int num_tries, std::chrono::milliseconds timeout_per_try)

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: