1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-03 13:35:36 +00:00

(trunk) #1608: Completed pieces bitfield in rpc

This commit is contained in:
Charles Kerr 2009-03-02 05:48:32 +00:00
parent 6be27c325f
commit e47808c277
3 changed files with 38 additions and 1 deletions

View file

@ -267,6 +267,7 @@ static const char * details_keys[] = {
"timesCompleted",
"totalSize",
"uploadedEver",
"pieces",
"webseeds",
"webseedsSendingToUs"
};
@ -847,6 +848,8 @@ printDetails( tr_benc * top )
{
tr_benc * t = tr_bencListChild( torrents, ti );
tr_benc * l;
const uint8_t * raw;
size_t rawlen;
const char * str;
char buf[512];
char buf2[512];
@ -1006,6 +1009,23 @@ printDetails( tr_benc * top )
printf( " Piece Count: %" PRId64 "\n", i );
if( tr_bencDictFindInt( t, "pieceSize", &i ) )
printf( " Piece Size: %" PRId64 "\n", i );
printf( "\n" );
printf("PIECES\n ");
if( tr_bencDictFindRaw( t, "pieces", &raw, &rawlen ) && tr_bencDictFindInt( t, "pieceCount", &j ) ) {
int len;
char * str = tr_base64_decode( raw, rawlen, &len );
for( i=k=0; k<len; ++k ) {
int e;
for( e=0; i<j && e<8; ++e, ++i )
printf( str[k] & (1<<(7-e)) ? "1" : "0" );
printf( " " );
if( !(i%64) )
printf( "\n " );
}
tr_free( str );
}
printf( "\n" );
}
}
}

View file

@ -167,6 +167,7 @@
peersGettingFromUs | number | tr_stat
peersKnown | number | tr_stat
peersSendingToUs | number | tr_stat
pieces | string (see below) | tr_torrent
pieceCount | tnumber | tr_info
pieceSize | tnumber | tr_info
priorities | array (see below) | n/a
@ -224,6 +225,12 @@
| fromPex | number | tr_stat
| fromTracker | number | tr_stat
-----------------------+--------------------------------------+
pieces | A bitfield holding pieceCount flags | tr_torrent
| which are set to 'true' if we have |
| the piece matching that position. |
| JSON doesn't allow raw binary data, |
| so this is a base64-encoded string. |
-----------------------+--------------------------------------+
priorities | an array of tr_info.filecount | tr_info
| numbers. each is the tr_priority_t |
| mode for the corresponding file. |
@ -410,4 +417,7 @@
| | | session-stats | added "current-stats"
| | | torrent-get | new arg "downloadDir"
------+---------+-----------+----------------+-------------------------------
6 | 1.60 | yes | torrent-get | new arg "pieces"
------+---------+-----------+----------------+-------------------------------

View file

@ -24,6 +24,7 @@
#include "session.h"
#include "stats.h"
#include "torrent.h"
#include "completion.h"
#include "utils.h"
#include "web.h"
@ -424,6 +425,12 @@ addField( const tr_torrent * tor,
tr_bencDictAddInt( d, key, st->peersKnown );
else if( !strcmp( key, "peersSendingToUs" ) )
tr_bencDictAddInt( d, key, st->peersSendingToUs );
else if( !strcmp( key, "pieces" ) ) {
const tr_bitfield * pieces = tr_cpPieceBitfield( &tor->completion );
char * str = tr_base64_encode( pieces->bits, pieces->byteCount, NULL );
tr_bencDictAddStr( d, key, str );
tr_free( str );
}
else if( !strcmp( key, "pieceCount" ) )
tr_bencDictAddInt( d, key, inf->pieceCount );
else if( !strcmp( key, "pieceSize" ) )