added server-based ip determination as a fallback to existing methods. Forced Dht publishing as soon as an external ip is known

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1109 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-04-03 09:21:20 +00:00
parent db74c9ef58
commit e23bd13bc9
4 changed files with 22 additions and 2 deletions

View File

@ -26,6 +26,7 @@
#include "pqi/p3connmgr.h" #include "pqi/p3connmgr.h"
#include "pqi/p3dhtmgr.h" // Only need it for constants. #include "pqi/p3dhtmgr.h" // Only need it for constants.
#include "tcponudp/tou.h" #include "tcponudp/tou.h"
#include "tcponudp/extaddrfinder.h"
#include "util/rsprint.h" #include "util/rsprint.h"
#include "util/rsdebug.h" #include "util/rsdebug.h"
@ -122,6 +123,7 @@ p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
ownState.name = mAuthMgr->getName(ownState.id); ownState.name = mAuthMgr->getName(ownState.id);
ownState.netMode = RS_NET_MODE_UDP; ownState.netMode = RS_NET_MODE_UDP;
} }
mExtAddrFinder = NULL ;
return; return;
} }
@ -404,6 +406,9 @@ void p3ConnectMgr::netTick()
uint32_t netStatus = mNetStatus; uint32_t netStatus = mNetStatus;
if(mExtAddrFinder == NULL)
mExtAddrFinder = new ExtAddrFinder ;
connMtx.unlock(); /* UNLOCK MUTEX */ connMtx.unlock(); /* UNLOCK MUTEX */
switch(netStatus) switch(netStatus)
@ -572,7 +577,9 @@ void p3ConnectMgr::netUdpCheck()
#ifdef CONN_DEBUG #ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl; std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl;
#endif #endif
if (udpExtAddressCheck() || (mUpnpAddrValid)) struct sockaddr_in tmpip ;
if (udpExtAddressCheck() || (mUpnpAddrValid) || mExtAddrFinder->hasValidIP(&tmpip))
{ {
bool extValid = false; bool extValid = false;
bool extAddrStable = false; bool extAddrStable = false;
@ -598,6 +605,13 @@ void p3ConnectMgr::netUdpCheck()
extAddr = mStunExtAddr; extAddr = mStunExtAddr;
extAddrStable = mStunAddrStable; extAddrStable = mStunAddrStable;
} }
else if(mExtAddrFinder->hasValidIP(&tmpip))
{
extValid = true;
extAddr = tmpip ;
extAddr.sin_port = iaddr.sin_port ;
extAddrStable = true;
}
if (extValid) if (extValid)
{ {

View File

@ -37,6 +37,8 @@
#include "util/rsthreads.h" #include "util/rsthreads.h"
class ExtAddrFinder ;
/* RS_VIS_STATE_XXXX /* RS_VIS_STATE_XXXX
* determines how public this peer wants to be... * determines how public this peer wants to be...
* *
@ -347,6 +349,7 @@ private:
std::list<pqiMonitor *> clients; std::list<pqiMonitor *> clients;
ExtAddrFinder *mExtAddrFinder ;
/* external Address determination */ /* external Address determination */
bool mUpnpAddrValid, mStunAddrValid; bool mUpnpAddrValid, mStunAddrValid;

View File

@ -198,6 +198,7 @@ bool p3DhtMgr::setExternalInterface(
ownEntry.raddr = raddr; ownEntry.raddr = raddr;
ownEntry.type = type; ownEntry.type = type;
ownEntry.state = DHT_PEER_ADDR_KNOWN; /* will force republish */ ownEntry.state = DHT_PEER_ADDR_KNOWN; /* will force republish */
ownEntry.lastTS = 0; /* will force republish */
#ifdef DHT_DEBUG #ifdef DHT_DEBUG
std::cerr << "p3DhtMgr::setExternalInterface()"; std::cerr << "p3DhtMgr::setExternalInterface()";
@ -224,6 +225,7 @@ bool p3DhtMgr::setExternalInterface(
dhtMtx.unlock(); /* UNLOCK MUTEX */ dhtMtx.unlock(); /* UNLOCK MUTEX */
checkOwnDHTKeys();
return true; return true;
} }

View File

@ -40,10 +40,11 @@
#include <netinet/in.h> #include <netinet/in.h>
#else #else
#include <stdint.h>
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> // #include <stdint.h>
typedef int socklen_t; typedef int socklen_t;
#endif #endif