bool ChunkDownload::assignPeer(PeerDownloader* pd) { if (!pd || pdown.contains(pd)) return false; pd->grab(); pdown.append(pd); dstatus.insert(pd->getPeer()->getID(),new DownloadStatus()); sendRequests(pd); connect(pd,SIGNAL(timedout(const Request& )),this,SLOT(onTimeout(const Request& ))); connect(pd,SIGNAL(rejected( const Request& )),this,SLOT(onRejected( const Request& ))); return true; }
void ChunkDownload::notDownloaded(const Request & r,bool reject) { // find the peer DownloadStatus* ds = dstatus.find(r.getPeer()); if (ds) { // Out() << "ds != 0" << endl; Uint32 p = r.getOffset() / MAX_PIECE_LEN; ds->remove(p); } // go over all PD's and do requets again for (QPtrList<PeerDownloader>::iterator i = pdown.begin();i != pdown.end();++i) sendRequests(*i); }
bool ChunkDownload::piece(const Piece & p,bool & ok) { ok = false; timer.update(); Uint32 pp = p.getOffset() / MAX_PIECE_LEN; Uint32 len = pp == num - 1 ? last_size : MAX_PIECE_LEN; if (pp >= num || pieces.get(pp) || p.getLength() != len) return false; DownloadStatus* ds = dstatus.find(p.getPieceDownloader()); if (ds) ds->remove(pp); PieceData::Ptr buf = chunk->getPiece(p.getOffset(),p.getLength(),false); if (buf && buf->write(p.getData(),p.getLength()) == p.getLength()) { piece_data[pp] = buf; ok = true; pieces.set(pp,true); piece_providers.insert(p.getPieceDownloader()); num_downloaded++; if (pdown.count() > 1) { endgameCancel(p); } updateHash(); if (num_downloaded >= num) { // finalize hash hash_gen.end(); releaseAllPDs(); return true; } } sendRequests(); return false; }
void ChunkDownload::update() { // go over all PD's and do requets again for (QPtrList<PeerDownloader>::iterator i = pdown.begin();i != pdown.end();++i) sendRequests(*i); }
// . returns false if blocked, true otherwise // . sets g_errno on error bool Msg51::getClusterRecs ( const int64_t *docIds, char *clusterLevels , key96_t *clusterRecs , int32_t numDocIds , collnum_t collnum , int32_t maxCacheAge , bool addToCache , void *state , void (* callback)( void *state ) , int32_t niceness , // output bool isDebug ) { // warning if ( collnum < 0 ) log(LOG_LOGIC,"net: NULL collection. msg51."); // reset this msg reset(); // get the collection rec CollectionRec *cr = g_collectiondb.getRec ( collnum ); if ( ! cr ) { log("db: msg51. Collection rec null for collnum %" PRId32".", (int32_t)collnum); g_errno = EBADENGINEER; gbshutdownLogicError(); } // keep a pointer for the caller m_maxCacheAge = maxCacheAge; m_addToCache = addToCache; m_state = state; m_callback = callback; m_collnum = collnum; // these are storage for the requester m_docIds = docIds; m_clusterLevels = clusterLevels; m_clusterRecs = clusterRecs; m_numDocIds = numDocIds; m_isDebug = isDebug; // bail if none to do if ( m_numDocIds <= 0 ) return true; m_nexti = 0; // for i/o mostly m_niceness = niceness; m_errno = 0; // reset these m_numRequests = 0; m_numReplies = 0; // clear/initialize these if(m_numDocIds<MSG51_MAX_REQUESTS) m_numSlots = m_numDocIds; else m_numSlots = MSG51_MAX_REQUESTS; m_slot = new Slot[m_numSlots]; for ( int32_t i = 0 ; i < m_numSlots ; i++ ) { m_slot[i].m_msg51 = this; m_slot[i].m_inUse = false; } // . do gathering // . returns false if blocked, true otherwise // . send up to MSG51_MAX_REQUESTS requests at the same time return sendRequests ( -1 ); }