From d6bb8f5f0014b7bc719be0ede4d10d88ff59dd7a Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 24 May 2010 12:12:31 +0000 Subject: [PATCH] fixed proper sorting of IP lists. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@2989 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 af7dc6327..80d35fb3a 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -3483,7 +3483,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) @@ -3492,20 +3492,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) {