| 251 | |
| 252 | |
| 253 | CUpDownClient* CClientList::FindMatchingClient( CUpDownClient* client ) |
| 254 | { |
| 255 | typedef std::pair<IDMap::const_iterator, IDMap::const_iterator> IDMapIteratorPair; |
| 256 | wxCHECK(client, NULL); |
| 257 | |
| 258 | const uint32 userIP = client->GetIP(); |
| 259 | const uint32 userID = client->GetUserIDHybrid(); |
| 260 | const uint16 userPort = client->GetUserPort(); |
| 261 | const uint16 userKadPort = client->GetKadPort(); |
| 262 | |
| 263 | |
| 264 | // LowID clients need a different set of checks |
| 265 | if (client->HasLowID()) { |
| 266 | // User is firewalled ... Must do two checks. |
| 267 | if (userIP && (userPort || userKadPort)) { |
| 268 | IDMapIteratorPair range = m_ipList.equal_range(userIP); |
| 269 | |
| 270 | for ( ; range.first != range.second; ++range.first ) { |
| 271 | CUpDownClient* other = range.first->second.GetClient(); |
| 272 | wxASSERT(userIP == other->GetIP()); |
| 273 | |
| 274 | if (userPort && (userPort == other->GetUserPort())) { |
| 275 | return other; |
| 276 | } else if (userKadPort && (userKadPort == other->GetKadPort())) { |
| 277 | return other; |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | const uint32 serverIP = client->GetServerIP(); |
| 283 | const uint32 serverPort = client->GetServerPort(); |
| 284 | if (userID && serverIP && serverPort) { |
| 285 | IDMapIteratorPair range = m_clientList.equal_range(userID); |
| 286 | |
| 287 | for (; range.first != range.second; ++range.first) { |
| 288 | CUpDownClient* other = range.first->second.GetClient(); |
| 289 | wxASSERT(userID == other->GetUserIDHybrid()); |
| 290 | |
| 291 | // For lowid, we also have to check the server |
| 292 | if (serverIP == other->GetServerIP()) { |
| 293 | if (serverPort == other->GetServerPort()) { |
| 294 | return other; |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | } else if (userPort || userKadPort) { |
| 300 | // Check by IP first, then by ID |
| 301 | struct { const IDMap& map; uint32 value; } toCheck[] = { |
| 302 | { m_ipList, userIP }, { m_clientList, userID } |
| 303 | }; |
| 304 | |
| 305 | for (size_t i = 0; i < itemsof(toCheck); ++i) { |
| 306 | if (toCheck[i].value == 0) { |
| 307 | // We may not have both (or any) of these values. |
| 308 | continue; |
| 309 | } |
| 310 |
nothing calls this directly
no test coverage detected