5#if defined(HAVE_CONFIG_H)
6#include <config/bitcoin-config.h>
26#include <miniupnpc/miniupnpc.h>
27#include <miniupnpc/upnpcommands.h>
28#include <miniupnpc/upnperrors.h>
32 "miniUPnPc API version >= 10 assumed");
42#if defined(USE_NATPMP) || defined(USE_UPNP)
49using namespace std::chrono_literals;
79 LogPrintf(
"natpmp: The gateway does not support NAT-PMP.\n");
81 LogPrintf(
"natpmp: readnatpmpresponseorretry() for public address "
82 "failed with %d error.\n",
86 LogPrintf(
"natpmp: sendpublicaddressrequest() failed with %d error.\n",
113 pm.mappedpublicport};
119 "natpmp: Port mapping successful. External address = %s\n",
123 LogPrintf(
"natpmp: Port mapping failed.\n");
126 LogPrintf(
"natpmp: The gateway does not support NAT-PMP.\n");
128 LogPrintf(
"natpmp: readnatpmpresponseorretry() for port mapping "
129 "failed with %d error.\n",
133 LogPrintf(
"natpmp: sendnewportmappingrequest() failed with %d error.\n",
159 LogPrintf(
"natpmp: Port mapping removed successfully.\n");
162 "natpmp: sendnewportmappingrequest(0) failed with %d error.\n",
182#if MINIUPNPC_API_VERSION < 14
191#if MINIUPNPC_API_VERSION <= 17
203 LogPrintf(
"UPnP: GetExternalIPAddress() returned %d\n", r);
208 LogPrintf(
"UPnP: ExternalIPAddress = %s\n",
213 LogPrintf(
"UPnP: GetExternalIPAddress failed.\n");
222 port.c_str(), port.c_str(),
lanaddr,
223 strDesc.c_str(),
"TCP", 0,
"0");
228 "AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
233 LogPrintf(
"UPnP Port Mapping successful.\n");
239 port.c_str(),
"TCP", 0);
240 LogPrintf(
"UPNP_DeletePortMapping() returned: %d\n", r);
A combination of a network address (CNetAddr) and a (TCP) port.
A helper class for interruptible sleeps.
std::string FormatFullVersion()
bool error(const char *fmt, const Args &...args)
void StartMapPort(bool use_upnp, bool use_natpmp)
void TraceThread(const char *thread_name, std::function< void()> thread_func)
A wrapper for do-something-once thread functions.
bool AddLocal(const CService &addr, int nScore)
bool LookupHost(const std::string &name, std::vector< CNetAddr > &vIP, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...