From 2b52db6c472404e071ffc0d354a78339e4016e31 Mon Sep 17 00:00:00 2001 From: joss17 Date: Mon, 14 Dec 2009 21:59:15 +0000 Subject: [PATCH] rework a little the netCheckConsistency git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1886 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 70 ++++++++++++------------------ 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index b24a48f5e..e9262a06b 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -567,10 +567,6 @@ void p3ConnectMgr::netTick() #ifdef CONN_DEBUG //std::cerr << "p3ConnectMgr::netTick() STATUS: DONE" << std::endl; #endif - stunCheck(); /* Keep on stunning */ - if (!netFlagStunOk) { - netExtFinderAddressCheck(); - } break; @@ -743,30 +739,34 @@ void p3ConnectMgr::networkConsistencyCheck() if (!doNetReset) {//set an external address. if ip adresses are different, let's use the stun address, then the extaddrfinder and then the upnp address. struct sockaddr_in extAddr; - if (getStunExtAddress(extAddr)) { + if (getUpnpExtAddress(extAddr)) { #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::networkConsistencyCheck() using STUN for ownState.serveraddr." << std::endl; + std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getUpnpExtAddress for ownState.serveraddr." << std::endl; + #endif + ownState.currentserveraddr = extAddr; + } else if (getExtFinderExtAddress(extAddr)) { + netExtFinderAddressCheck(); //so we put the extra address flag ok. + #ifdef CONN_DEBUG + std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getExtFinderExtAddress for ownState.serveraddr." << std::endl; #endif ownState.currentserveraddr = extAddr; } else { - //call the extrafinder address - if (getUpnpExtAddress(extAddr)) { - #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getUpnpExtAddress for ownState.serveraddr." << std::endl; - #endif - ownState.currentserveraddr = extAddr; - } else if (getExtFinderExtAddress(extAddr)) { - netExtFinderAddressCheck(); //so we put the extra address flag ok. - #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getExtFinderExtAddress for ownState.serveraddr." << std::endl; - #endif - ownState.currentserveraddr = extAddr; + //check if a peer is connected, if yes don't do a net reset + bool is_connected = false; + std::map::iterator it; + for(it = mFriendList.begin(); it != mFriendList.end() && !is_connected; it++) + { + /* get last contact detail */ + is_connected = it->second.state & RS_PEER_S_CONNECTED; + } + #ifdef CONN_DEBUG + if (is_connected) { + std::cerr << "p3ConnectMgr::networkConsistencyCheck() not doing a net reset because a peer is connected." << std::endl; } else { - #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::networkConsistencyCheck() no external ip address." << std::endl; - #endif - doNetReset = true; + std::cerr << "p3ConnectMgr::networkConsistencyCheck() no peer is connected." << std::endl; } + #endif + doNetReset = !is_connected; } } connMtx.unlock(); /* UNLOCK MUTEX */ @@ -779,25 +779,6 @@ void p3ConnectMgr::networkConsistencyCheck() ownState.updateIpAddressList(ipAddressTimed); } - if (doNetReset) { - //check if a peer is connected, then don't do a net reset - bool is_connected = false; - std::map::iterator it; - for(it = mFriendList.begin(); it != mFriendList.end() && !is_connected; it++) - { - /* get last contact detail */ - is_connected = it->second.state & RS_PEER_S_CONNECTED; - } - doNetReset = !is_connected; - #ifdef CONN_DEBUG - if (is_connected) { - std::cerr << "p3ConnectMgr::networkConsistencyCheck() not doing a net reset because a peer is connected." << std::endl; - } else { - std::cerr << "p3ConnectMgr::networkConsistencyCheck() no peer is connected." << std::endl; - } - #endif - } - //let's do a net reset if (doNetReset) { //don't do a reset it if the network init is not finished @@ -2492,10 +2473,13 @@ bool p3ConnectMgr::setAddressList(std::string id, std::list I { /* check if it is our own ip */ if (id == getOwnId()) { + struct sockaddr_in extAddr; + if (getUpnpExtAddress(extAddr) || getExtFinderExtAddress(extAddr)) { #ifdef CONN_DEBUG - std::cerr << "p3ConnectMgr::setAddressList() received own ip address list." << std::endl; - peerConnectState::printIpAddressList(IpAddressTimedList); + std::cerr << "p3ConnectMgr::setAddressList() received own ip address list, but already got an external address with upnp or extaddrfinder." << std::endl; #endif + return false; + } //extract first address that is not the same as local address //check if the ip list contains the current remote address of the connected peer IpAddressTimed foundAddress;