From e23bd13bc9dae34cbdc97852f1007581819b3bd9 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 3 Apr 2009 09:21:20 +0000 Subject: [PATCH] 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 --- libretroshare/src/pqi/p3connmgr.cc | 16 +++++++++++++++- libretroshare/src/pqi/p3connmgr.h | 3 +++ libretroshare/src/pqi/p3dhtmgr.cc | 2 ++ libretroshare/src/tcponudp/tou.h | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 3d17ca245..c04a99355 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -26,6 +26,7 @@ #include "pqi/p3connmgr.h" #include "pqi/p3dhtmgr.h" // Only need it for constants. #include "tcponudp/tou.h" +#include "tcponudp/extaddrfinder.h" #include "util/rsprint.h" #include "util/rsdebug.h" @@ -122,6 +123,7 @@ p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am) ownState.name = mAuthMgr->getName(ownState.id); ownState.netMode = RS_NET_MODE_UDP; } + mExtAddrFinder = NULL ; return; } @@ -404,6 +406,9 @@ void p3ConnectMgr::netTick() uint32_t netStatus = mNetStatus; + if(mExtAddrFinder == NULL) + mExtAddrFinder = new ExtAddrFinder ; + connMtx.unlock(); /* UNLOCK MUTEX */ switch(netStatus) @@ -572,7 +577,9 @@ void p3ConnectMgr::netUdpCheck() #ifdef CONN_DEBUG std::cerr << "p3ConnectMgr::netUdpCheck()" << std::endl; #endif - if (udpExtAddressCheck() || (mUpnpAddrValid)) + struct sockaddr_in tmpip ; + + if (udpExtAddressCheck() || (mUpnpAddrValid) || mExtAddrFinder->hasValidIP(&tmpip)) { bool extValid = false; bool extAddrStable = false; @@ -598,6 +605,13 @@ void p3ConnectMgr::netUdpCheck() extAddr = mStunExtAddr; extAddrStable = mStunAddrStable; } + else if(mExtAddrFinder->hasValidIP(&tmpip)) + { + extValid = true; + extAddr = tmpip ; + extAddr.sin_port = iaddr.sin_port ; + extAddrStable = true; + } if (extValid) { diff --git a/libretroshare/src/pqi/p3connmgr.h b/libretroshare/src/pqi/p3connmgr.h index 884d4c32c..d02ec121f 100644 --- a/libretroshare/src/pqi/p3connmgr.h +++ b/libretroshare/src/pqi/p3connmgr.h @@ -37,6 +37,8 @@ #include "util/rsthreads.h" +class ExtAddrFinder ; + /* RS_VIS_STATE_XXXX * determines how public this peer wants to be... * @@ -347,6 +349,7 @@ private: std::list clients; + ExtAddrFinder *mExtAddrFinder ; /* external Address determination */ bool mUpnpAddrValid, mStunAddrValid; diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index 8fea006a7..155fbbf43 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -198,6 +198,7 @@ bool p3DhtMgr::setExternalInterface( ownEntry.raddr = raddr; ownEntry.type = type; ownEntry.state = DHT_PEER_ADDR_KNOWN; /* will force republish */ + ownEntry.lastTS = 0; /* will force republish */ #ifdef DHT_DEBUG std::cerr << "p3DhtMgr::setExternalInterface()"; @@ -224,6 +225,7 @@ bool p3DhtMgr::setExternalInterface( dhtMtx.unlock(); /* UNLOCK MUTEX */ + checkOwnDHTKeys(); return true; } diff --git a/libretroshare/src/tcponudp/tou.h b/libretroshare/src/tcponudp/tou.h index 3c5461d1a..d53afa8ad 100644 --- a/libretroshare/src/tcponudp/tou.h +++ b/libretroshare/src/tcponudp/tou.h @@ -40,10 +40,11 @@ #include #else + #include #include #include #include - #include +// #include typedef int socklen_t; #endif