| 394 | |
| 395 | |
| 396 | void CUploadQueue::AddClientToQueue(CUpDownClient* client) |
| 397 | { |
| 398 | if (theApp->serverconnect->IsConnected() && theApp->serverconnect->IsLowID() && !theApp->serverconnect->IsLocalServer(client->GetServerIP(),client->GetServerPort()) && client->GetDownloadState() == DS_NONE && !client->IsFriend() && theStats::GetWaitingUserCount() > 50) { |
| 399 | // Well, all that issues finish in the same: don't allow to add to the queue |
| 400 | return; |
| 401 | } |
| 402 | |
| 403 | if ( client->IsBanned() ) { |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | client->AddAskedCount(); |
| 408 | client->SetLastUpRequest(); |
| 409 | |
| 410 | // Find all clients with the same user-hash |
| 411 | CClientList::SourceList found = theApp->clientlist->GetClientsByHash( client->GetUserHash() ); |
| 412 | |
| 413 | CClientList::SourceList::iterator it = found.begin(); |
| 414 | while (it != found.end()) { |
| 415 | CUpDownClient* cur_client = it++->GetClient(); |
| 416 | |
| 417 | if ( IsOnUploadQueue( cur_client ) ) { |
| 418 | if ( cur_client == client ) { |
| 419 | // This is where LowID clients get their upload slot assigned. |
| 420 | // They can't be contacted if they reach top of the queue, so they are just marked for uploading. |
| 421 | // When they reconnect next time AddClientToQueue() is called, and they get their slot |
| 422 | // through the connection they initiated. |
| 423 | // Since at that time no slot is free they get assigned an extra slot, |
| 424 | // so then the number of slots exceeds the configured number by one. |
| 425 | // To prevent a further increase no more LowID clients get a slot, until |
| 426 | // - a HighID client has got one (which happens only after two clients |
| 427 | // have been kicked so a slot is free again) |
| 428 | // - or there is a free slot, which means there is no HighID client on queue |
| 429 | if (client->m_bAddNextConnect) { |
| 430 | uint32 maxSlots = GetMaxSlots(); |
| 431 | if (lastupslotHighID) { |
| 432 | maxSlots++; |
| 433 | } |
| 434 | if (m_uploadinglist.size() < maxSlots) { |
| 435 | client->m_bAddNextConnect = false; |
| 436 | RemoveFromWaitingQueue(client); |
| 437 | AddUpNextClient(client); |
| 438 | lastupslotHighID = false; // LowID alternate |
| 439 | return; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | client->SendRankingInfo(); |
| 444 | Notify_SharedCtrlRefreshClient(client->ECID(), AVAILABLE_SOURCE); |
| 445 | return; |
| 446 | } else { |
| 447 | // Hash-clash, remove unidentified clients (possibly both) |
| 448 | |
| 449 | if ( !cur_client->IsIdentified() ) { |
| 450 | // Cur_client isn't identifed, remove it |
| 451 | theApp->clientlist->AddTrackClient( cur_client ); |
| 452 | |
| 453 | RemoveFromWaitingQueue( cur_client ); |
no test coverage detected