From d485c711262eb50c6ee0713d0d0a43d97fac337e Mon Sep 17 00:00:00 2001 From: joss17 Date: Fri, 18 Dec 2009 23:35:57 +0000 Subject: [PATCH] The external ip address is now set when a peer is connected if there is no upnp or extadrfinder git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1918 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 4daaf685f..c82df8c5f 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -2545,8 +2545,9 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list I /* check if it is our own ip */ if (id == getOwnId()) { ownState.updateIpAddressList(IpAddressTimedList); - //if we are using firewalled or manually set port mode, and we are not using extAddrFinder, we will use this list for ip ext ip detection - if ((!ownState.netMode & RS_NET_MODE_UPNP) && !use_extr_addr_finder) { + //if we have no ext address from upnp or extAdrFinder, we will use this list for ext ip detection + sockaddr_in extAddr; + if (!getExtFinderExtAddress(extAddr) && !getUpnpExtAddress(extAddr)) { //TODO fix it IpAddressTimed extractedAddress; if (peerConnectState::extractExtAddress(IpAddressTimedList, extractedAddress)) { #ifdef CONN_DEBUG @@ -2554,6 +2555,10 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list I #endif ownState.currentserveraddr.sin_addr = extractedAddress.ipAddr.sin_addr; IndicateConfigChanged(); + } else { + #ifdef CONN_DEBUG + std::cerr << "p3ConnectMgr::setAddressList() no valuable ext adress found." << std::endl; + #endif } } return true; @@ -3280,30 +3285,17 @@ void peerConnectState::sortIpAddressListBySeenTime() { //Sort the ip list orderi } void peerConnectState::sortIpAddressListBySeenTime(std::list &ipTimedListInput) { //Sort the ip list ordering by seen time -#ifdef CONN_DEBUG - std::cerr << "peerConnectState::sortIpAdressListBySeenTime() called" << std::endl; -#endif ipTimedListInput.sort(peerConnectState::compare_seen_time); ipTimedListInput.reverse(); } std::list peerConnectState::getIpAddressList() { -#ifdef CONN_DEBUG - std::cerr << "peerConnectState::getIpAddressList() called" << std::endl; -#endif purgeIpAddressList(); -#ifdef CONN_DEBUG - printIpAddressList(); -#endif return ipAddressList; } void peerConnectState::purgeIpAddressList() {//purge old and useless addresses to keep a small list -#ifdef CONN_DEBUG - std::cerr << "peerConnectState::purgeIpAdressList() called." << std::endl; -#endif - std::list::iterator ipListIt; for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end());) { if (ipListIt->ipAddr.sin_addr.s_addr == 0 || ipListIt->ipAddr.sin_port == 0 || @@ -3314,9 +3306,6 @@ void peerConnectState::purgeIpAddressList() {//purge old and useless addresses t ++ipListIt; } } -#ifdef CONN_DEBUG - printIpAddressList(); -#endif //purge duplicates for (ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()); ipListIt++) { @@ -3407,7 +3396,7 @@ bool peerConnectState::extractExtAddress(std::list IpAddressTime //if ((ipListIt->ipAddr.sin_addr.s_addr != 0) if (ipListIt->ipAddr.sin_addr.s_addr != 0 && ipListIt->ipAddr.sin_port != 0 && ipListIt->ipAddr.sin_addr.s_addr != 1 && ipListIt->ipAddr.sin_port != 1 && - std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) == "1.1.1.1" && + std::string(inet_ntoa(ipListIt->ipAddr.sin_addr)) != "1.1.1.1" && (!isLoopbackNet(&ipListIt->ipAddr.sin_addr)) && (!isPrivateNet(&ipListIt->ipAddr.sin_addr)) ) {