improve udp stun and upnp collaboration

Conflicts:

	libretroshare/src/libretroshare.pro

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1749 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-10-30 00:35:12 +00:00
parent e7273b0453
commit 324b51e250
4 changed files with 74 additions and 72 deletions

View file

@ -733,24 +733,31 @@ const std::string CUPnPService::GetStateVariable(
GetAbsControlURL().c_str(),
stateVariableName.c_str(),
&StVarVal);
std::cerr << "GetStateVariable pausing in case of an UPnP event incomming.";
time_t begin_time = time(NULL);
while (true) {
if (time(NULL) - begin_time > 7) {
break;
}
}
std::cerr << "GetStateVariable pause finished.";
std::cerr << "GetStateVariable(" << stateVariableName << ") = ";
std::map<std::string, std::string>::iterator it;
it = propertyMap.find(stateVariableName);
if (it == propertyMap.end()) {
std::cerr << "Empty String" << std::endl;
return stdEmptyString;
if (StVarVal != NULL) {
std::string varValue = std::string(StVarVal);
std::cerr << "GetStateVariable varValue returned by UpnpGetServiceVarStatus : " << varValue << std::endl;
return varValue;
} else {
std::cerr << (*it).second << std::endl;
return (*it).second;
//use event to get state variable
std::cerr << "GetStateVariable pausing in case of an UPnP event incomming.";
time_t begin_time = time(NULL);
while (true) {
if (time(NULL) - begin_time > 7) {
break;
}
}
std::cerr << "GetStateVariable pause finished.";
std::cerr << "GetStateVariable(" << stateVariableName << ") = ";
std::map<std::string, std::string>::iterator it;
it = propertyMap.find(stateVariableName);
if (it == propertyMap.end()) {
std::cerr << "Empty String" << std::endl;
return stdEmptyString;
} else {
std::cerr << (*it).second << std::endl;
return (*it).second;
}
}
}
@ -1078,14 +1085,6 @@ bool CUPnPControlPoint::DeletePortMappings(
}
int n = upnpPortMapping.size();
bool ok = false;
// Check the number of port mappings before
std::istringstream PortMappingNumberOfEntries(
m_WanService->GetStateVariable(
"PortMappingNumberOfEntries"));
unsigned long oldNumberOfEntries;
PortMappingNumberOfEntries >> oldNumberOfEntries;
// Delete the enabled port mappings
for (int i = 0; i < n; ++i) {
@ -1108,21 +1107,8 @@ bool CUPnPControlPoint::DeletePortMappings(
PrivateDeletePortMapping(upnpPortMapping[i]);
}
}
// Debug only
std::cerr << "CUPnPControlPoint::DeletePortMappings: "
"m_ActivePortMappingsMap.size() == " <<
m_ActivePortMappingsMap.size() << std::endl;
// Not very good, must find a better test
PortMappingNumberOfEntries.str(
m_WanService->GetStateVariable(
"PortMappingNumberOfEntries"));
unsigned long newNumberOfEntries;
PortMappingNumberOfEntries >> newNumberOfEntries;
ok = oldNumberOfEntries - newNumberOfEntries >= 4;
return ok;
return true;
}

View file

@ -59,6 +59,7 @@ class upnpThreadData
/* Thread routines */
extern "C" void* doSetupUPnP(void* p)
{
std::cerr << "doSetupUPnP Creating upnp thread." << std::endl;
upnpThreadData *data = (upnpThreadData *) p;
if ((!data) || (!data->handler))
{
@ -88,7 +89,7 @@ bool upnphandler::background_setup_upnp(bool start, bool stop)
pthread_t tid;
/* launch thread */
std::cerr << "Creating upnp thread." << std::endl;
std::cerr << "background_setup_upnp Creating upnp thread." << std::endl;
upnpThreadData *data = new upnpThreadData();
data->handler = this;
data->start = start;
@ -249,7 +250,10 @@ bool upnphandler::shutdown_upnp()
//destroy the upnp object
cUPnPControlPoint->~CUPnPControlPoint();
upnpState = RS_UPNP_S_UNINITIALISED;
//stopping os ok, set starting to true for next net reset
toStop = false;
toStart = true;
}
return true;
@ -276,6 +280,9 @@ upnphandler::~upnphandler()
/* RsIface */
void upnphandler::enable(bool active)
{
std::cerr << "upnphandler::enable called with argument active : " << active << std::endl;
std::cerr << "toEnable : " << toEnable << std::endl;
std::cerr << "toStart : " << toStart << std::endl;
dataMtx.lock(); /*** LOCK MUTEX ***/
if (active != toEnable)

View file

@ -12,29 +12,6 @@
#include "upnp.h"
#include "upnp/UPnPBase.h"
class upnpentry
{
public:
std::string name;
std::string id;
struct sockaddr_in addr;
unsigned int flags;
int status;
int lastTs;
};
class upnpforward
{
public:
std::string name;
unsigned int flags;
struct sockaddr_in iaddr;
struct sockaddr_in eaddr;
int status;
int lastTs;
};
#define RS_UPNP_S_UNINITIALISED 0
#define RS_UPNP_S_UNAVAILABLE 1
#define RS_UPNP_S_READY 2
@ -42,8 +19,6 @@ class upnpforward
#define RS_UPNP_S_UDP_FAILED 4
#define RS_UPNP_S_ACTIVE 5
class uPnPConfigData;
class upnphandler: public pqiNetAssistFirewall
{
public:
@ -95,10 +70,6 @@ class upnphandler: public pqiNetAssistFirewall
/* info from upnp */
struct sockaddr_in upnp_iaddr;
struct sockaddr_in upnp_eaddr;
/* active port forwarding */
std::list<upnpforward> activeForwards;
};
/* info from upnp */