Changeset 10387


Ignore:
Timestamp:
Mar 15, 2010, 11:29:56 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #3051 "faster startup by adding 'have all' idiom to .resume files" -- implemented in trunk for 2.00

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r9868 r10387  
    165165}
    166166
     167
     168void
     169tr_cpSetHaveAll( tr_completion * cp )
     170{
     171    tr_piece_index_t i;
     172    tr_torrent * tor = cp->tor;
     173
     174    tr_cpReset( cp );
     175
     176    cp->sizeNow = tor->info.totalSize;
     177    tr_bitfieldAddRange( &cp->blockBitfield, 0, tor->blockCount );
     178    tr_bitfieldAddRange( &cp->pieceBitfield, 0, tor->info.pieceCount );
     179    for( i=0; i<tor->info.pieceCount; ++i )
     180        cp->completeBlocks[i] = tr_torPieceCountBlocks( tor, i );
     181    cp->sizeWhenDoneIsDirty = 1;
     182    cp->haveValidIsDirty = 1;
     183}
     184
    167185/* Initialize a completion object from a bitfield indicating which blocks we have */
    168186tr_bool
  • trunk/libtransmission/completion.h

    r10031 r10387  
    158158                                 struct tr_bitfield * blocks );
    159159
     160void      tr_cpSetHaveAll( tr_completion * completion );
     161
    160162/***
    161163****
  • trunk/libtransmission/resume.c

    r10084 r10387  
    5656#define KEY_RATIOLIMIT_MODE        "ratio-mode"
    5757
    58 #define KEY_PROGRESS_MTIMES   "mtimes"
    59 #define KEY_PROGRESS_BITFIELD "bitfield"
     58#define KEY_PROGRESS_MTIMES    "mtimes"
     59#define KEY_PROGRESS_BITFIELD  "bitfield"
     60#define KEY_PROGRESS_HAVE      "have"
    6061
    6162enum
     
    397398    }
    398399
    399     /* add the bitfield */
     400    /* add the progress */
     401    if( tor->completeness == TR_SEED )
     402        tr_bencDictAddStr( p, KEY_PROGRESS_HAVE, "all" );
    400403    bitfield = tr_cpBlockBitfield( &tor->completion );
    401404    tr_bencDictAddRaw( p, KEY_PROGRESS_BITFIELD,
     
    415418    if( tr_bencDictFindDict( dict, KEY_PROGRESS, &p ) )
    416419    {
     420        const char * err;
     421        const char * str;
    417422        const uint8_t * raw;
    418423        size_t          rawlen;
     
    460465        }
    461466
    462         if( tr_bencDictFindRaw( p, KEY_PROGRESS_BITFIELD, &raw, &rawlen ) )
     467        err = NULL;
     468        if( tr_bencDictFindStr( p, KEY_PROGRESS_HAVE, &str ) )
     469        {
     470            if( !strcmp( str, "all" ) )
     471                tr_cpSetHaveAll( &tor->completion );
     472            else
     473                err = "Invalid value for HAVE";
     474        }
     475        else if( tr_bencDictFindRaw( p, KEY_PROGRESS_BITFIELD, &raw, &rawlen ) )
    463476        {
    464477            tr_bitfield tmp;
     
    467480            tmp.bits = (uint8_t*) raw;
    468481            if( !tr_cpBlockBitfieldSet( &tor->completion, &tmp ) )
    469             {
    470                 tr_torrentUncheck( tor );
    471                 tr_tordbg(
    472                     tor,
    473                     "Torrent needs to be verified - error loading bitfield" );
    474             }
    475         }
    476         else
    477         {
     482                err = "Error loading bitfield";
     483        }
     484        else err = "Couldn't find 'have' or 'bitfield'";
     485        if( err != NULL )
     486        {
    478487            tr_torrentUncheck( tor );
    479             tr_tordbg(
    480                 tor,
    481                 "Torrent needs to be verified - unable to find bitfield" );
     488            tr_tordbg( tor, "Torrent needs to be verified - %s", err );
    482489        }
    483490
Note: See TracChangeset for help on using the changeset viewer.