From 18281f4d205d9e320fad23ac3c28b66ea4bb2ff7 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Thu, 2 Oct 2014 18:43:13 +0200 Subject: remove dangling upnp port mappings, updated miniupnpc --- src/p2p/net_node.inl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/p2p/net_node.inl') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 2953bdb7a..01fbaa497 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -48,9 +48,11 @@ #ifdef UPNP_STATIC #include #include + #include #else #include "miniupnpc.h" #include "upnpcommands.h" + #include "upnperrors.h" #endif #define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4)))) @@ -326,8 +328,14 @@ namespace nodetool if (result == 1) { std::ostringstream portString; portString << m_listenning_port; - if (UPNP_AddPortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), portString.str().c_str(), lanAddress, CRYPTONOTE_NAME, "TCP", 0, "0") != 0) { - LOG_ERROR("UPNP_AddPortMapping failed."); + + // Delete the port mapping before we create it, just in case we have dangling port mapping from the daemon not being shut down correctly + UPNP_DeletePortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), "TCP", 0); + + int portMappingResult; + portMappingResult = UPNP_AddPortMapping(urls.controlURL, igdData.first.servicetype, portString.str().c_str(), portString.str().c_str(), lanAddress, CRYPTONOTE_NAME, "TCP", 0, "0"); + if (portMappingResult != 0) { + LOG_ERROR("UPNP_AddPortMapping failed, error: " << strupnperror(portMappingResult)); } else { LOG_PRINT_GREEN("Added IGD port mapping.", LOG_LEVEL_0); } -- cgit v1.2.3