aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mapport.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/mapport.cpp b/src/mapport.cpp
index 1f24b75708..ced2b773f3 100644
--- a/src/mapport.cpp
+++ b/src/mapport.cpp
@@ -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()