(trunk rpc) added "fileStats" to rpc s.t. there's a simple interface for getting all the torrent's stat fields

This commit is contained in:
Charles Kerr 2009-03-31 22:13:43 +00:00
parent 3610272c4c
commit e649e80fe5
2 changed files with 32 additions and 0 deletions

View File

@ -153,6 +153,7 @@
errorString | number | tr_stat
eta | number | tr_stat
files | array (see below) | n/a
fileStats | array (see below) | n/a
hashString | string | tr_info
haveUnchecked | number | tr_stat
haveValid | number | tr_stat
@ -213,6 +214,14 @@
| length | number | tr_info
| name | string | tr_info
-----------------------+--------------------------------------+
fileStats | a file's non-constant properties. |
| array of tr_info.filecount objects, |
| each containing: |
+-------------------------+------------+
| bytesCompleted | number | tr_torrent
| wanted | 'boolean' | tr_info
| priority | number | tr_info
-----------------------+--------------------------------------+
peers | array of objects, each containing: |
+-------------------------+------------+
| address | string | tr_peer_stat
@ -440,6 +449,7 @@
| | yes | torrent-get | new arg "downloadDir"
------+---------+-----------+----------------+-------------------------------
6 | 1.60 | yes | torrent-get | new arg "pieces"
| | yes | torrent-get | new arg "fileStats"
| | yes | torrent-set | new arg "ratio"
| | yes | torrent-set | new arg "downloadLimited"
| | yes | torrent-set | new arg "uploadLimited"

View File

@ -288,6 +288,26 @@ torrentVerify( tr_session * session,
****
***/
static void
addFileStats( const tr_torrent * tor, tr_benc * list )
{
tr_file_index_t i;
tr_file_index_t n;
const tr_info * info = tr_torrentInfo( tor );
tr_file_stat * files = tr_torrentFiles( tor, &n );
for( i = 0; i < info->fileCount; ++i )
{
const tr_file * file = &info->files[i];
tr_benc * d = tr_bencListAddDict( list, 3 );
tr_bencDictAddInt( d, "bytesCompleted", files[i].bytesCompleted );
tr_bencDictAddInt( d, "priority", file->priority );
tr_bencDictAddBool( d, "wanted", !file->dnd );
}
tr_torrentFilesFree( files, n );
}
static void
addFiles( const tr_torrent * tor,
tr_benc * list )
@ -415,6 +435,8 @@ addField( const tr_torrent * tor,
tr_bencDictAddInt( d, key, st->eta );
else if( !strcmp( key, "files" ) )
addFiles( tor, tr_bencDictAddList( d, key, inf->fileCount ) );
else if( !strcmp( key, "fileStats" ) )
addFileStats( tor, tr_bencDictAddList( d, key, inf->fileCount ) );
else if( !strcmp( key, "hashString" ) )
tr_bencDictAddStr( d, key, tor->info.hashString );
else if( !strcmp( key, "haveUnchecked" ) )