From c54d581472ec1bf1c0e43a79061f8f5027cb5e9d Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 May 2010 12:17:05 +0000 Subject: [PATCH] fixed proper sorting of IP lists. (branch comit 2989) git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2990 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3connmgr.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 360bd5082..6ababd38f 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -3604,7 +3604,7 @@ void peerConnectState::updateIpAddressList(const IpAddressTimed& ipTimed) } // 2 - check if the ip list already contains the current remote address of the connected peer. In such a case, - // we update the time stamp. + // we remove the list entry, and update the time stamp. We only compare ips not ports, so that the last port is kept. // bool found = false; for (std::list::iterator ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()) && !found; ++ipListIt) @@ -3613,20 +3613,21 @@ void peerConnectState::updateIpAddressList(const IpAddressTimed& ipTimed) #ifdef CONN_DEBUG std::cerr << "peerConnectState::updateIpAdressList() ip found in the list." << std::endl; #endif - found = true; //update the seen time // - if (ipListIt->seenTime < ipTimed.seenTime) + if ( (*ipListIt).seenTime < ipTimed.seenTime) { - (*ipListIt).seenTime = ipTimed.seenTime; - (*ipListIt).ipAddr.sin_port = ipTimed.ipAddr.sin_port ; // keep the port of the most recent address. + ipAddressList.erase(ipListIt) ; #ifdef CONN_DEBUG std::cerr << "peerConnectState::updateIpAdressList() Update seen time to : " << ipTimed.seenTime << std::endl; #endif } + else + found = true; // We keep the entry. + break ; } - // if not found, insert the address at sorted position into the list + // if not found (or removed), insert the address at sorted position into the list // if (!found) {