Ejemplo n.º 1
0
void
tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor )
{
    tr_file_index_t i;

    for( i=0; i<ctor->lowSize; ++i )
        tr_torrentInitFilePriority( tor, ctor->low[i], TR_PRI_LOW );
    for( i=0; i<ctor->normalSize; ++i )
        tr_torrentInitFilePriority( tor, ctor->normal[i], TR_PRI_NORMAL );
    for( i=0; i<ctor->highSize; ++i )
        tr_torrentInitFilePriority( tor, ctor->high[i], TR_PRI_HIGH );
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
static uint64_t
loadFilePriorities( tr_benc * dict, tr_torrent * tor )
{
    tr_benc * list;
    uint64_t ret = 0;
    const tr_file_index_t n = tor->info.fileCount;

    if( tr_bencDictFindList( dict, KEY_FILE_PRIORITIES, &list )
      && ( tr_bencListSize( list ) == n ) )
    {
        int64_t priority;
        tr_file_index_t i;
        for( i = 0; i < n; ++i )
            if( tr_bencGetInt( tr_bencListChild( list, i ), &priority ) )
                tr_torrentInitFilePriority( tor, i, priority );
        ret = TR_FR_FILE_PRIORITIES;
    }

    return ret;
}
Ejemplo n.º 4
0
static uint64_t loadFilePriorities(tr_variant* dict, tr_torrent* tor)
{
    tr_variant* list;
    uint64_t ret = 0;
    tr_file_index_t const n = tor->info.fileCount;

    if (tr_variantDictFindList(dict, TR_KEY_priority, &list) && tr_variantListSize(list) == n)
    {
        int64_t priority;

        for (tr_file_index_t i = 0; i < n; ++i)
        {
            if (tr_variantGetInt(tr_variantListChild(list, i), &priority))
            {
                tr_torrentInitFilePriority(tor, i, priority);
            }
        }

        ret = TR_FR_FILE_PRIORITIES;
    }

    return ret;
}