Initial attempt at against the completeness of a specific piece.

This commit is contained in:
Mitchell Livingston 2006-10-12 23:34:20 +00:00
parent de198e1c0a
commit 663c671f93
7 changed files with 54 additions and 8 deletions

View File

@ -200,6 +200,28 @@ void tr_cpBlockBitfieldSet( tr_completion_t * cp, uint8_t * bitfield )
}
}
uint8_t tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece )
{
tr_torrent_t * tor = cp->tor;
int i;
int blockCount, startBlock, endBlock;
int complete;
uint8_t * bitfield;
blockCount = tr_pieceCountBlocks( piece );
startBlock = tr_pieceStartBlock( piece );
endBlock = startBlock + blockCount;
complete = 0;
bitfield = cp->blockBitfield;
for( i = startBlock; i < endBlock; i++ )
if( tr_bitfieldHas( bitfield, i ) )
complete++;
return (complete * 100.0) / blockCount;
}
int tr_cpMissingBlockInPiece( tr_completion_t * cp, int piece )
{
tr_torrent_t * tor = cp->tor;
@ -210,13 +232,8 @@ int tr_cpMissingBlockInPiece( tr_completion_t * cp, int piece )
end = start + count;
for( i = start; i < end; i++ )
{
if( tr_cpBlockIsComplete( cp, i ) || cp->blockDownloaders[i] )
{
continue;
}
return i;
}
if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
return i;
return -1;
}

View File

@ -57,6 +57,7 @@ void tr_cpBlockAdd( tr_completion_t *, int block );
void tr_cpBlockRem( tr_completion_t *, int block );
uint8_t * tr_cpBlockBitfield( tr_completion_t * );
void tr_cpBlockBitfieldSet( tr_completion_t *, uint8_t * );
uint8_t tr_cpPercentBlocksInPiece( tr_completion_t * cp, int piece );
/* Missing = we don't have it and we are not getting it from any peer yet */
static inline int tr_cpMissingBlocksForPiece( tr_completion_t * cp, int piece )
{

View File

@ -633,6 +633,19 @@ void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
tr_lockUnlock( &tor->lock );
}
void tr_torrentAmountFinished( tr_torrent_t * tor, int8_t * tab, int size )
{
int i, piece;
tr_lockLock( &tor->lock );
for( i = 0; i < size; i++ )
{
piece = i * tor->info.pieceCount / size;
tab[i] = tr_cpPercentBlocksInPiece( tor->completion, piece );
}
tr_lockUnlock( &tor->lock );
}
void tr_torrentRemoveSaved( tr_torrent_t * tor ) {
tr_metainfoRemoveSaved( tor->info.hashString );
}

View File

@ -273,6 +273,8 @@ void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
**********************************************************************/
void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
void tr_torrentAmountFinished( tr_torrent_t * tor, int8_t * tab, int size );
/***********************************************************************
* tr_torrentRemoveSaved
***********************************************************************

View File

@ -257,6 +257,12 @@
{
[image unlockFocus];
[fImageView setNeedsDisplay];
/*int8_t * piecesC = malloc(fNumPieces);
[fTorrent getAmountFinished: piecesC size: fNumPieces];
for (i = 0; i < fNumPieces; i++)
NSLog(@"%d", piecesC[i]);
free(piecesC);*/
}
free(pieces);

View File

@ -64,7 +64,9 @@
- (void) setDownloadFolder: (NSString *) path;
- (NSString *) downloadFolder;
- (void) getAvailability: (int8_t *) tab size: (int) size;
- (void) getAvailability: (int8_t *) tab size: (int) size;
- (void) getAmountFinished: (int8_t *) tab size: (int) size;
- (void) update;
- (NSDictionary *) infoForCurrentView;

View File

@ -164,6 +164,11 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
tr_torrentAvailability(fHandle, tab, size);
}
- (void) getAmountFinished: (int8_t *) tab size: (int) size
{
tr_torrentAmountFinished(fHandle, tab, size);
}
- (void) update
{
fStat = tr_torrentStat(fHandle);