From 573e7b2474f48f8f4da0ca2cc2973b36f2242693 Mon Sep 17 00:00:00 2001 From: joss17 Date: Thu, 12 Nov 2009 22:19:45 +0000 Subject: [PATCH] remove upnp mapping before adding new ones git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1821 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 7 ++++--- libretroshare/src/pqi/p3connmgr.h | 2 +- libretroshare/src/upnp/upnphandler.cc | 11 ++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 18d065488..3cfd59b39 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -544,7 +544,7 @@ void p3ConnectMgr::netTick() #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::netTick() STATUS: UPNP_INIT" << std::endl; #endif - netExtraAddressCheck(); + netExtFinderAddressCheck(); netUpnpInit(); break; @@ -561,7 +561,7 @@ void p3ConnectMgr::netTick() #endif stunCheck(); /* Keep on stunning */ if (!netFlagStunOk) { - netExtraAddressCheck(); + netExtFinderAddressCheck(); } break; @@ -755,6 +755,7 @@ void p3ConnectMgr::networkConsistencyCheck() #endif ownState.currentserveraddr = extAddr; } else if (getExtFinderExtAddress(extAddr)) { + netExtFinderAddressCheck(); //so we put the extra address flag ok. #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getExtFinderExtAddress for ownState.serveraddr." << std::endl; #endif @@ -794,7 +795,7 @@ void p3ConnectMgr::networkConsistencyCheck() } } -void p3ConnectMgr::netExtraAddressCheck() +void p3ConnectMgr::netExtFinderAddressCheck() { struct sockaddr_in tmpip; if (getExtFinderExtAddress(tmpip)) { #ifdef CONN_DEBUG diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index d6a1ce729..a7505629d 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -317,7 +317,7 @@ void netExtCheck(); void netUpnpInit(); void netUpnpCheck(); -void netExtraAddressCheck(); +void netExtFinderAddressCheck(); void netUnreachableCheck(); /* Udp / Stun functions */ diff --git a/libretroshare/src/upnp/upnphandler.cc b/libretroshare/src/upnp/upnphandler.cc index c519adf49..39daadf64 100644 --- a/libretroshare/src/upnp/upnphandler.cc +++ b/libretroshare/src/upnp/upnphandler.cc @@ -168,15 +168,20 @@ bool upnphandler::start_upnp() #endif } - //build port mapping config + //first of all, build the mappings std::vector upnpPortMapping1; CUPnPPortMapping cUPnPPortMapping1 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "TCP", true, "tcp retroshare redirection"); upnpPortMapping1.push_back(cUPnPPortMapping1); - bool res = cUPnPControlPoint->AddPortMappings(upnpPortMapping1); - std::vector upnpPortMapping2; CUPnPPortMapping cUPnPPortMapping2 = CUPnPPortMapping(eport_curr, ntohs(localAddr.sin_port), "UDP", true, "udp retroshare redirection"); upnpPortMapping2.push_back(cUPnPPortMapping2); + + //attempt to remove formal port redirection rules + cUPnPControlPoint->DeletePortMappings(upnpPortMapping1); + cUPnPControlPoint->DeletePortMappings(upnpPortMapping2); + + //add new rules + bool res = cUPnPControlPoint->AddPortMappings(upnpPortMapping1); bool res2 = cUPnPControlPoint->AddPortMappings(upnpPortMapping2); struct sockaddr_in extAddr;