Changeset 994 for trunk/libtransmission


Ignore:
Timestamp:
Oct 12, 2006, 11:34:20 PM (15 years ago)
Author:
livings124
Message:

Initial attempt at against the completeness of a specific piece.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r261 r994  
    201201}
    202202
     203uint8_t tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece )
     204{
     205    tr_torrent_t * tor = cp->tor;
     206    int i;
     207    int blockCount, startBlock, endBlock;
     208    int complete;
     209    uint8_t * bitfield;
     210   
     211    blockCount  = tr_pieceCountBlocks( piece );
     212    startBlock  = tr_pieceStartBlock( piece );
     213    endBlock    = startBlock + blockCount;
     214    complete    = 0;
     215   
     216    bitfield = cp->blockBitfield;
     217
     218    for( i = startBlock; i < endBlock; i++ )
     219        if( tr_bitfieldHas( bitfield, i ) )
     220            complete++;
     221   
     222    return (complete * 100.0) / blockCount;
     223}
     224
    203225int tr_cpMissingBlockInPiece( tr_completion_t * cp, int piece )
    204226{
     
    211233
    212234    for( i = start; i < end; i++ )
    213     {
    214         if( tr_cpBlockIsComplete( cp, i ) || cp->blockDownloaders[i] )
    215         {
    216             continue;
    217         }
    218         return i;
    219     }
     235        if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
     236            return i;
    220237
    221238    return -1;
  • trunk/libtransmission/completion.h

    r261 r994  
    5858uint8_t         * tr_cpBlockBitfield( tr_completion_t * );
    5959void              tr_cpBlockBitfieldSet( tr_completion_t *, uint8_t * );
     60uint8_t           tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece );
    6061/* Missing = we don't have it and we are not getting it from any peer yet */
    6162static inline int tr_cpMissingBlocksForPiece( tr_completion_t * cp, int piece )
  • trunk/libtransmission/transmission.c

    r931 r994  
    630630            }
    631631        }
     632    }
     633    tr_lockUnlock( &tor->lock );
     634}
     635
     636void tr_torrentAmountFinished( tr_torrent_t * tor, int8_t * tab, int size )
     637{
     638    int i, piece;
     639
     640    tr_lockLock( &tor->lock );
     641    for( i = 0; i < size; i++ )
     642    {
     643        piece = i * tor->info.pieceCount / size;
     644        tab[i] = tr_cpPercentBlocksInPiece( tor->completion, piece );
    632645    }
    633646    tr_lockUnlock( &tor->lock );
  • trunk/libtransmission/transmission.h

    r926 r994  
    274274void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
    275275
     276void tr_torrentAmountFinished( tr_torrent_t * tor, int8_t * tab, int size );
     277
    276278/***********************************************************************
    277279 * tr_torrentRemoveSaved
Note: See TracChangeset for help on using the changeset viewer.