Changeset 994


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
Files:
7 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
  • trunk/macosx/PiecesView.m

    r989 r994  
    258258        [image unlockFocus];
    259259        [fImageView setNeedsDisplay];
     260       
     261        /*int8_t * piecesC = malloc(fNumPieces);
     262        [fTorrent getAmountFinished: piecesC size: fNumPieces];
     263        for (i = 0; i < fNumPieces; i++)
     264            NSLog(@"%d", piecesC[i]);
     265        free(piecesC);*/
    260266    }
    261267   
  • trunk/macosx/Torrent.h

    r985 r994  
    6565- (void)       setDownloadFolder: (NSString *) path;
    6666- (NSString *) downloadFolder;
    67 - (void)       getAvailability: (int8_t *) tab size: (int) size;
     67
     68- (void) getAvailability: (int8_t *) tab size: (int) size;
     69- (void) getAmountFinished: (int8_t *) tab size: (int) size;
    6870
    6971- (void)            update;
  • trunk/macosx/Torrent.m

    r993 r994  
    163163{
    164164    tr_torrentAvailability(fHandle, tab, size);
     165}
     166
     167- (void) getAmountFinished: (int8_t *) tab size: (int) size
     168{
     169    tr_torrentAmountFinished(fHandle, tab, size);
    165170}
    166171
Note: See TracChangeset for help on using the changeset viewer.