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
This commit is contained in:
csoler 2010-05-24 12:12:31 +00:00
parent 88018d4512
commit d6bb8f5f00

View File

@ -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, // 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; bool found = false;
for (std::list<IpAddressTimed>::iterator ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()) && !found; ++ipListIt) for (std::list<IpAddressTimed>::iterator ipListIt = ipAddressList.begin(); ipListIt!=(ipAddressList.end()) && !found; ++ipListIt)
@ -3492,20 +3492,21 @@ void peerConnectState::updateIpAddressList(const IpAddressTimed& ipTimed)
#ifdef CONN_DEBUG #ifdef CONN_DEBUG
std::cerr << "peerConnectState::updateIpAdressList() ip found in the list." << std::endl; std::cerr << "peerConnectState::updateIpAdressList() ip found in the list." << std::endl;
#endif #endif
found = true;
//update the seen time //update the seen time
// //
if (ipListIt->seenTime < ipTimed.seenTime) if ( (*ipListIt).seenTime < ipTimed.seenTime)
{ {
(*ipListIt).seenTime = ipTimed.seenTime; ipAddressList.erase(ipListIt) ;
(*ipListIt).ipAddr.sin_port = ipTimed.ipAddr.sin_port ; // keep the port of the most recent address.
#ifdef CONN_DEBUG #ifdef CONN_DEBUG
std::cerr << "peerConnectState::updateIpAdressList() Update seen time to : " << ipTimed.seenTime << std::endl; std::cerr << "peerConnectState::updateIpAdressList() Update seen time to : " << ipTimed.seenTime << std::endl;
#endif #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) if (!found)
{ {