mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
net: Keep trying to use UPnP when -upnp=1
This commit is contained in:
parent
28e2961fd6
commit
8b50d1b5bb
@ -37,9 +37,11 @@ static std::thread g_upnp_thread;
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
static constexpr auto PORT_MAPPING_REANNOUNCE_PERIOD{20min};
|
||||
static constexpr auto PORT_MAPPING_RETRY_PERIOD{5min};
|
||||
|
||||
static void ThreadMapPort()
|
||||
static bool ProcessUpnp()
|
||||
{
|
||||
bool ret = false;
|
||||
std::string port = strprintf("%u", GetListenPort());
|
||||
const char * multicastif = nullptr;
|
||||
const char * minissdpdpath = nullptr;
|
||||
@ -84,11 +86,15 @@ static void ThreadMapPort()
|
||||
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype, port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
|
||||
|
||||
if (r != UPNPCOMMAND_SUCCESS) {
|
||||
ret = false;
|
||||
LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n", port, port, lanaddr, r, strupnperror(r));
|
||||
break;
|
||||
} else {
|
||||
ret = true;
|
||||
LogPrintf("UPnP Port Mapping successful.\n");
|
||||
}
|
||||
} while (g_upnp_interrupt.sleep_for(PORT_MAPPING_REANNOUNCE_PERIOD));
|
||||
g_upnp_interrupt.reset();
|
||||
|
||||
r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
|
||||
LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
|
||||
@ -100,6 +106,15 @@ static void ThreadMapPort()
|
||||
if (r != 0)
|
||||
FreeUPNPUrls(&urls);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void ThreadMapPort()
|
||||
{
|
||||
do {
|
||||
if (ProcessUpnp()) return;
|
||||
} while (g_upnp_interrupt.sleep_for(PORT_MAPPING_RETRY_PERIOD));
|
||||
}
|
||||
|
||||
void StartMapPort()
|
||||
|
Loading…
Reference in New Issue
Block a user