void ChunkDownload::endgameCancel(const Piece & p) { QPtrList<PeerDownloader>::iterator i = pdown.begin(); while (i != pdown.end()) { PeerDownloader* pd = *i; DownloadStatus* ds = dstatus.find(pd->getPeer()->getID()); Uint32 pp = p.getOffset() / MAX_PIECE_LEN; if (ds && ds->contains(pp)) { pd->cancel(Request(p)); ds->remove(pp); } i++; } }
void ChunkDownload::sendRequests(PeerDownloader* pd) { timer.update(); DownloadStatus* ds = dstatus.find(pd->getPeer()->getID()); if (!ds) return; // if the peer is choked and we are not downloading an allowed fast chunk if (pd->isChoked()) return; Uint32 num_visited = 0; while (num_visited < piece_queue.count() && pd->canAddRequest()) { // get the first one in the queue Uint32 i = piece_queue.first(); if (!ds->contains(i)) { // send request pd->download( Request( chunk->getIndex(), i*MAX_PIECE_LEN, i+1<num ? MAX_PIECE_LEN : last_size, pd->getPeer()->getID())); ds->add(i); } // move to the back so that it will take a while before it's turn is up piece_queue.pop_front(); piece_queue.append(i); num_visited++; } if (piece_queue.count() < 2 && piece_queue.count() > 0) pd->setNearlyDone(true); }