improved stun failure resistance

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1761 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2009-10-30 00:38:52 +00:00
parent f090ee87b6
commit 3c7f714650

View file

@ -54,8 +54,8 @@ const uint32_t RS_STUN_DONE = 0x0002;
const uint32_t RS_STUN_LIST_MIN = 100; const uint32_t RS_STUN_LIST_MIN = 100;
const uint32_t RS_STUN_FOUND_MIN = 10; const uint32_t RS_STUN_FOUND_MIN = 10;
const uint32_t MAX_UPNP_INIT = 60; /* seconds UPnP timeout */ const uint32_t MAX_UPNP_INIT = 80; /* seconds UPnP timeout */
const uint32_t MAX_UDP_INIT = 80; /* seconds Udp timeout */ const uint32_t MAX_UDP_INIT = 100; /* seconds Udp timeout */
const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5; const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
@ -345,6 +345,7 @@ void p3ConnectMgr::addNetListener(pqiNetListener *listener)
void p3ConnectMgr::netStatusReset() void p3ConnectMgr::netStatusReset()
{ {
std::cerr << "p3ConnectMgr::netStatusReset()";
netFlagOk = false; netFlagOk = false;
netFlagUpnpOk = false; netFlagUpnpOk = false;
netFlagDhtOk = false; netFlagDhtOk = false;
@ -374,6 +375,7 @@ void p3ConnectMgr::netStartup()
*/ */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
netStatusReset();
mNetInitTS = time(NULL); mNetInitTS = time(NULL);
#ifdef CONN_DEBUG #ifdef CONN_DEBUG
@ -945,9 +947,10 @@ bool p3ConnectMgr::udpExtAddressCheck()
* so up is okay, and ext address is known stable or not. * so up is okay, and ext address is known stable or not.
*/ */
if (mStunAddrStable) if (mStunAddrStable) {
netFlagExtOk = true; netFlagExtOk = true;
netFlagUdpOk = true; netFlagUdpOk = true;
}
return true; return true;
} }
@ -1059,12 +1062,23 @@ bool p3ConnectMgr::stunCheck()
else else
{ {
#ifdef CONN_DEBUG #ifdef CONN_DEBUG
std::cerr << "No Ext Address -> netReset" << std::endl; std::cerr << "Stun : No Ext Address. Checking upnp est address." << std::endl;
#endif
struct sockaddr_in extAddr;
bool upnpExtAdress = netAssistExtAddress(extAddr);
if (upnpExtAdress) {
//don't do a reset
#ifdef CONN_DEBUG
std::cerr << "Found upnp Ext Address. don't do a reset." << std::endl;
#endif
} else {
#ifdef CONN_DEBUG
std::cerr << "No upnp Ext Address. doing a reset." << std::endl;
#endif #endif
doNetReset = true; doNetReset = true;
} }
} }
}
if (doNetReset) if (doNetReset)
{ {
@ -1080,6 +1094,8 @@ bool p3ConnectMgr::stunCheck()
if (delta > MAX_UDP_INIT) { if (delta > MAX_UDP_INIT) {
//stun failed let's do a network reset //stun failed let's do a network reset
netReset(); netReset();
} else {
doNetReset = false;;
} }
} }