| 167 | |
| 168 | |
| 169 | void CUploadQueue::AddUpNextClient(CUpDownClient* directadd) |
| 170 | { |
| 171 | CUpDownClient* newclient = NULL; |
| 172 | CClientRef newClientRef; |
| 173 | // select next client or use given client |
| 174 | if (!directadd) { |
| 175 | SortGetBestClient(&newClientRef); |
| 176 | newclient = newClientRef.GetClient(); |
| 177 | #if EXTENDED_UPLOADQUEUE |
| 178 | if (!newclient) { |
| 179 | // Nothing to upload. Try to find something from the sources. |
| 180 | if (PopulatePossiblyWaitingList() > 0) { |
| 181 | newClientRef = * m_possiblyWaitingList.begin(); |
| 182 | m_possiblyWaitingList.pop_front(); |
| 183 | newclient = newClientRef.GetClient(); |
| 184 | AddDebugLogLineN( logLocalClient, "Added client from possiblyWaitingList " + newclient->GetFullIP() ); |
| 185 | } |
| 186 | } |
| 187 | #endif |
| 188 | if (!newclient) { |
| 189 | return; |
| 190 | } |
| 191 | } else { |
| 192 | // Check if requested file is suspended or not shared (maybe deleted recently) |
| 193 | |
| 194 | if (IsSuspended(directadd->GetUploadFileID()) |
| 195 | || !theApp->sharedfiles->GetFileByID(directadd->GetUploadFileID())) { |
| 196 | return; |
| 197 | } else { |
| 198 | newclient = directadd; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | if (IsDownloading(newclient)) { |
| 203 | return; |
| 204 | } |
| 205 | // tell the client that we are now ready to upload |
| 206 | if (!newclient->IsConnected()) { |
| 207 | newclient->SetUploadState(US_CONNECTING); |
| 208 | if (!newclient->TryToConnect(true)) { |
| 209 | return; |
| 210 | } |
| 211 | } else { |
| 212 | CPacket* packet = new CPacket(OP_ACCEPTUPLOADREQ, 0, OP_EDONKEYPROT); |
| 213 | theStats::AddUpOverheadFileRequest(packet->GetPacketSize()); |
| 214 | AddDebugLogLineN( logLocalClient, "Local Client: OP_ACCEPTUPLOADREQ to " + newclient->GetFullIP() ); |
| 215 | newclient->SendPacket(packet,true); |
| 216 | newclient->SetUploadState(US_UPLOADING); |
| 217 | } |
| 218 | newclient->SetUpStartTime(); |
| 219 | newclient->ResetSessionUp(); |
| 220 | |
| 221 | { |
| 222 | // Guard against concurrent iteration by the disk I/O thread. |
| 223 | wxMutexLocker lock(m_uploadingListMutex); |
| 224 | theApp->uploadBandwidthThrottler->AddToStandardList(m_uploadinglist.size(), newclient->GetSocket()); |
| 225 | m_uploadinglist.push_back(CCLIENTREF(newclient, "CUploadQueue::AddUpNextClient")); |
| 226 | } |
nothing calls this directly
no test coverage detected