void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ) { if( ctor->notWantSize ) tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE ); if( ctor->wantSize ) tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, TRUE ); }
void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ) { if( ctor->notWantSize ) tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, false ); if( ctor->wantSize ) tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, true ); }
static uint64_t parsePriorities( tr_torrent * tor, const uint8_t * buf, uint32_t len ) { uint64_t ret = 0; if( len == (uint32_t)( 2 * tor->info.fileCount ) ) { const size_t n = tor->info.fileCount; const size_t len = 2 * n; tr_file_index_t *dnd = NULL, dndCount = 0; tr_file_index_t *dl = NULL, dlCount = 0; size_t i; const uint8_t * walk = buf; /* set file priorities */ for( i = 0; i < n; ++i ) { tr_priority_t priority; const char ch = *walk++; switch( ch ) { case 'l': priority = TR_PRI_LOW; break; case 'h': priority = TR_PRI_HIGH; break; default: priority = TR_PRI_NORMAL; break; } tr_torrentInitFilePriority( tor, i, priority ); } /* set the dnd flags */ dl = tr_new( tr_file_index_t, len ); dnd = tr_new( tr_file_index_t, len ); for( i = 0; i < n; ++i ) if( *walk++ == 't' ) /* 't' means the DND flag is true */ dnd[dndCount++] = i; else dl[dlCount++] = i; if( dndCount ) tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE ); if( dlCount ) tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE ); tr_free( dnd ); tr_free( dl ); ret = TR_FR_PRIORITY; } return ret; }
static uint64_t loadDND( tr_benc * dict, tr_torrent * tor ) { uint64_t ret = 0; tr_info * inf = &tor->info; const tr_file_index_t n = inf->fileCount; tr_benc * list = NULL; if( tr_bencDictFindList( dict, KEY_DND, &list ) && ( tr_bencListSize( list ) == n ) ) { int64_t tmp; tr_file_index_t * dl = tr_new( tr_file_index_t, n ); tr_file_index_t * dnd = tr_new( tr_file_index_t, n ); tr_file_index_t i, dlCount = 0, dndCount = 0; for( i = 0; i < n; ++i ) { if( tr_bencGetInt( tr_bencListChild( list, i ), &tmp ) && tmp ) dnd[dndCount++] = i; else dl[dlCount++] = i; } if( dndCount ) { tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE ); tr_tordbg( tor, "Resume file found %d files listed as dnd", dndCount ); } if( dlCount ) { tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE ); tr_tordbg( tor, "Resume file found %d files marked for download", dlCount ); } tr_free( dnd ); tr_free( dl ); ret = TR_FR_DND; } else { tr_tordbg( tor, "Couldn't load DND flags. DND list (%p) has %zu children; torrent has %d files", list, tr_bencListSize( list ), (int)n ); } return ret; }
static uint64_t loadDND(tr_variant* dict, tr_torrent* tor) { uint64_t ret = 0; tr_variant* list = NULL; tr_file_index_t const n = tor->info.fileCount; if (tr_variantDictFindList(dict, TR_KEY_dnd, &list) && tr_variantListSize(list) == n) { int64_t tmp; tr_file_index_t* dl = tr_new(tr_file_index_t, n); tr_file_index_t* dnd = tr_new(tr_file_index_t, n); tr_file_index_t dlCount = 0; tr_file_index_t dndCount = 0; for (tr_file_index_t i = 0; i < n; ++i) { if (tr_variantGetInt(tr_variantListChild(list, i), &tmp) && tmp != 0) { dnd[dndCount++] = i; } else { dl[dlCount++] = i; } } if (dndCount != 0) { tr_torrentInitFileDLs(tor, dnd, dndCount, false); tr_logAddTorDbg(tor, "Resume file found %d files listed as dnd", dndCount); } if (dlCount != 0) { tr_torrentInitFileDLs(tor, dl, dlCount, true); tr_logAddTorDbg(tor, "Resume file found %d files marked for download", dlCount); } tr_free(dnd); tr_free(dl); ret = TR_FR_DND; } else { tr_logAddTorDbg(tor, "Couldn't load DND flags. DND list (%p) has %zu" " children; torrent has %d files", (void*)list, tr_variantListSize(list), (int)n); } return ret; }