diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index dce2ee0a6..42f83b8de 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -790,18 +790,24 @@ 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 (getUpnpExtAddress(extAddr)) { - #ifdef CONN_DEBUG_TICK - std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getUpnpExtAddress for ownState.serveraddr." << std::endl; - #endif - ownState.currentserveraddr = extAddr; - } else if (getExtFinderExtAddress(extAddr)) { + if (getExtFinderExtAddress(extAddr)) { netExtFinderAddressCheck(); //so we put the extra address flag ok. #ifdef CONN_DEBUG_TICK std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getExtFinderExtAddress for ownState.serveraddr." << std::endl; #endif ownState.currentserveraddr = extAddr; + } else if (getUpnpExtAddress(extAddr)) { + #ifdef CONN_DEBUG_TICK + std::cerr << "p3ConnectMgr::networkConsistencyCheck() using getUpnpExtAddress for ownState.serveraddr." << std::endl; + #endif + ownState.currentserveraddr = extAddr; } else { + //try to extract ext address from our own ip address list + IpAddressTimed extractedAddress; + if (peerConnectState::extractExtAddress(ownState.getIpAddressList(), extractedAddress)) { + ownState.currentserveraddr = extractedAddress.ipAddr; + } + //check if a peer is connected, if yes don't do a net reset bool is_connected = false; std::map::iterator it; diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3disc.cc index 397c65247..9f864defd 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -550,21 +550,23 @@ void p3disc::recvPeerDetails(RsDiscReply *item) mConnMgr->setLocation(pitem->pid, pitem->location); } } - } else { - if (pitem->currentremoteaddr.sin_addr.s_addr != 0 && pitem->currentremoteaddr.sin_port != 0 && - pitem->currentremoteaddr.sin_addr.s_addr != 1 && pitem->currentremoteaddr.sin_port != 1 && - std::string(inet_ntoa(pitem->currentremoteaddr.sin_addr)) != "1.1.1.1" && - (!isLoopbackNet(&pitem->currentremoteaddr.sin_addr)) && - (!isPrivateNet(&pitem->currentremoteaddr.sin_addr)) - ) { - //the current server address given by the peer looks nice, let's use it for our own ext address if needed - sockaddr_in tempAddr; - if (!mConnMgr->getExtFinderExtAddress(tempAddr) && !mConnMgr->getUpnpExtAddress(tempAddr)) { - //don't change the port, just the ip - pitem->currentremoteaddr.sin_port = mConnMgr->ownState.currentserveraddr.sin_port; - mConnMgr->setExtAddress(mConnMgr->getOwnId(), pitem->currentremoteaddr); - } - } + + //useless, we will exploit the list in the connect manager +// } else { +// if (pitem->currentremoteaddr.sin_addr.s_addr != 0 && pitem->currentremoteaddr.sin_port != 0 && +// pitem->currentremoteaddr.sin_addr.s_addr != 1 && pitem->currentremoteaddr.sin_port != 1 && +// std::string(inet_ntoa(pitem->currentremoteaddr.sin_addr)) != "1.1.1.1" && +// (!isLoopbackNet(&pitem->currentremoteaddr.sin_addr)) && +// (!isPrivateNet(&pitem->currentremoteaddr.sin_addr)) +// ) { +// //the current server address given by the peer looks nice, let's use it for our own ext address if needed +// sockaddr_in tempAddr; +// if (!mConnMgr->getExtFinderExtAddress(tempAddr) && !mConnMgr->getUpnpExtAddress(tempAddr)) { +// //don't change the port, just the ip +// pitem->currentremoteaddr.sin_port = mConnMgr->ownState.currentserveraddr.sin_port; +// mConnMgr->setExtAddress(mConnMgr->getOwnId(), pitem->currentremoteaddr); +// } +// } } //allways update address list mConnMgr->setAddressList(pitem->pid, pitem->ipAddressList);