(rpc) to lower the bandwidth/cpu used up by very large torrent lists, allow finer-grained control over which fields to return in the `torrent-get' request.

This commit is contained in:
Charles Kerr 2008-07-26 14:47:07 +00:00
parent d8c098f7a8
commit 771f299c53
5 changed files with 297 additions and 309 deletions

View File

@ -172,6 +172,28 @@ addFiles( tr_benc * args, const char * key, const char * arg )
}
}
#define TR_N_ELEMENTS( ary ) ( sizeof( ary ) / sizeof( *ary ) )
static const char * files_keys[] = {
"files", "name", "priorities", "wanted"
};
static const char * details_keys[] = {
"activityDate", "addedDate", "announceResponse", "announceURL",
"comment", "corruptEver", "creator", "dateCreated", "doneDate",
"downloadedEver", "errorString", "eta", "hashString", "haveUnchecked",
"haveValid", "id", "isPrivate", "lastAnnounceTime", "lastScrapeTime",
"leechers", "leftUntilDone", "name", "nextAnnounceTime", "nextScrapeTime",
"pieceCount", "pieceSize", "rateDownload", "rateUpload", "recheckProgress",
"scrapeResponse", "seeders", "sizeWhenDone", "sizeWhenDone", "startDate",
"status", "timesCompleted", "totalSize", "uploadedEver"
};
static const char * list_keys[] = {
"downloadedEver", "eta", "id", "leftUntilDone", "name", "rateDownload",
"rateUpload", "sizeWhenDone", "status", "uploadedEver"
};
static void
readargs( int argc, const char ** argv )
{
@ -184,11 +206,11 @@ readargs( int argc, const char ** argv )
while(( c = tr_getopt( getUsage(), argc, argv, opts, &optarg )))
{
int i, n;
char buf[MAX_PATH_LENGTH];
int addArg = TRUE;
tr_benc top, *args;
tr_benc top, *args, *fields;
tr_bencInitDict( &top, 3 );
int64_t fields = 0;
args = tr_bencDictAddDict( &top, "arguments", 0 );
switch( c )
@ -220,10 +242,10 @@ readargs( int argc, const char ** argv )
case 'f': tr_bencDictAddStr( &top, "method", "torrent-get" );
tr_bencDictAddInt( &top, "tag", TAG_FILES );
addIdArg( args, id );
fields = TR_RPC_TORRENT_ID
| TR_RPC_TORRENT_FILES
| TR_RPC_TORRENT_PRIORITIES;
tr_bencDictAddInt( args, "fields", fields );
n = TR_N_ELEMENTS( files_keys );
fields = tr_bencDictAddList( args, "fields", n );
for( i=0; i<n; ++i )
tr_bencListAddStr( fields, files_keys[i] );
break;
case 'g': tr_bencDictAddStr( &top, "method", "torrent-set" );
addIdArg( args, id );
@ -236,24 +258,17 @@ readargs( int argc, const char ** argv )
case 'i': tr_bencDictAddStr( &top, "method", "torrent-get" );
tr_bencDictAddInt( &top, "tag", TAG_DETAILS );
addIdArg( args, id );
fields = TR_RPC_TORRENT_ACTIVITY
| TR_RPC_TORRENT_ANNOUNCE
| TR_RPC_TORRENT_ERROR
| TR_RPC_TORRENT_HISTORY
| TR_RPC_TORRENT_ID
| TR_RPC_TORRENT_INFO
| TR_RPC_TORRENT_SCRAPE
| TR_RPC_TORRENT_SIZE
| TR_RPC_TORRENT_TRACKER_STATS;
tr_bencDictAddInt( args, "fields", fields );
n = TR_N_ELEMENTS( details_keys );
fields = tr_bencDictAddList( args, "fields", n );
for( i=0; i<n; ++i )
tr_bencListAddStr( fields, details_keys[i] );
break;
case 'l': tr_bencDictAddStr( &top, "method", "torrent-get" );
tr_bencDictAddInt( &top, "tag", TAG_LIST );
fields = TR_RPC_TORRENT_ID
| TR_RPC_TORRENT_ACTIVITY
| TR_RPC_TORRENT_HISTORY
| TR_RPC_TORRENT_SIZE;
tr_bencDictAddInt( args, "fields", fields );
n = TR_N_ELEMENTS( list_keys );
fields = tr_bencDictAddList( args, "fields", n );
for( i=0; i<n; ++i )
tr_bencListAddStr( fields, list_keys[i] );
break;
case 'm': tr_bencDictAddStr( &top, "method", "session-set" );
tr_bencDictAddInt( args, "port-forwarding-enabled", 1 );
@ -725,13 +740,12 @@ processResponse( const char * host, int port,
const char * str;
tr_bencDictFindInt( &top, "tag", &tag );
if( tr_bencDictFindStr( &top, "result", &str ) )
printf( "%s:%d responded: \"%s\"\n", host, port, str );
switch( tag ) {
case TAG_FILES: printFileList( &top ); break;
case TAG_DETAILS: printDetails( &top ); break;
case TAG_LIST: printTorrentList( &top ); break;
default: break;
default: if( tr_bencDictFindStr( &top, "result", &str ) )
printf( "%s:%d responded: \"%s\"\n", host, port, str );
}
tr_bencFree( &top );

View File

@ -100,138 +100,121 @@
Request arguments:
string | required? | default | value type & description
-------------+-----------+---------+---------------------------------------
"ids" | no | all | array described in 3.1
"fields" | yes | n/a | number bitwise-or'ed field
| | | values from the table below
(1) An opional "ids" array as described in 3.1.
(2) A required "fields" array of keys. (see list below)
Response arguments:
(1) A "fields" number identical to the request's
(2) A "torrents" array of objects, each of which contains the
key/value fields that match the "fields" argument.
See the table below for a complete list.
(1) A "torrents" array of objects, each of which contains
the key/value pairs matching the request's "fields" argument.
"fields" value | response | response | source
| value | key |
-------------------+----------+------------------------+-------------
activity, 1 | number | desiredAvailable | tr_stat
| number | eta | tr_stat
| number | peersConnected | tr_stat
| number | peersGettingFromUs | tr_stat
| number | peersSendingToUs | tr_stat
| number | rateDownload | tr_stat
| number | rateUpload | tr_stat
| number | recheckProgress | tr_stat
| number | status | tr_stat
| number | swarmSpeed (K/s) | tr_stat
| 'double' | uploadRatio | tr_stat
| number | webseedsSendingToUs | tr_stat
-------------------+----------+------------------------+-------------
announce, 2 | string | announceResponse | tr_stat
| string | announceURL | tr_stat
| number | lastAnnounceTime | tr_stat
| number | manualAnnounceTime | tr_stat
| number | nextAnnounceTime | tr_stat
-------------------+----------+------------------------+-------------
error, 4 | number | error | tr_stat
| number | errorString | tr_stat
-------------------+----------+------------------------+-------------
files, 8 | array | files
+----------+--------------------------------------
| files is an array of objects that contain:
+----------+------------------------+-------------
| number | bytesCompleted | tr_torrent
| number | length | tr_info
| string | name | tr_info
-------------------+----------+------------------------+-------------
history, 16 | number | activityDate | tr_stat
| number | addedDate | tr_stat
| number | corruptEver | tr_stat
| number | doneDate | tr_stat
| number | downloadedEver | tr_stat
| number | startDate | tr_stat
| number | uploadedEver | tr_stat
-------------------+----------+------------------------+-------------
id, 32 | number | uniqueId | tr_torrent
| string | hashString | tr_info
| string | name | tr_info
-------------------+----------+------------------------+-------------
info, 64 | string | comment | tr_info
| string | creator | tr_info
| number | dateCreated | tr_info
| number | pieceCount | tr_info
| number | pieceSize | tr_info
| 'boolean'| isPrivate | tr_torrent
-------------------+----------+------------------------+-------------
limits, 128 | number | downloadLimit | tr_torrent
| number | downloadLimitMode | tr_torrent
| number | maxConnectedPeers | tr_torrent
| number | uploadLimit | tr_torrent
| number | uploadLimitMode | tr_torrent
-------------------+----------+------------------------+-------------
peers, 256 | not defined yet
-------------------+----------+------------------------+-------------
peer stats, 512 | number | fromCache | tr_stat
| number | fromIncoming | tr_stat
| number | fromPex | tr_stat
| number | fromTracker | tr_stat
-------------------+----------+------------------------+-------------
priorities, 1024 | array | priorities | tr_info
| array | wanted | tr_info
+----------+--------------------------------------
| priorities is an array of tr_info.fileCount
| numbers. Each is the tr_priority_t mode for
| the corresponding file.
+-------------------------------------------------
| wanted is an array of tr_info.fileCount
| 'booleans' true if the corresponding file
| is to be downloaded.
-------------------+----------+------------------------+-------------
scrape, 2048 | number | lastScrapeTime | tr_stat
| number | nextScrapeTime | tr_stat
| string | scrapeResponse | tr_stat
| string | scrapeURL | tr_stat
-------------------+----------+------------------------+-------------
size, 4096 | number | haveUnchecked | tr_stat
| number | haveValid | tr_stat
| number | leftUntilDone | tr_stat
| number | sizeWhenDone | tr_stat
| number | totalSize | tr_info
-------------------+----------+------------------------+-------------
tracker stats, | number | leechers | tr_stat
8192 | number | peersKnown | tr_stat
| number | seeders | tr_stat
| number | timesCompleted | tr_stat
-------------------+----------+--------------------------------------
trackers, 16384 | array | trackers
+----------+--------------------------------------
| trackers is an array of objects that contain:
+----------+------------------------+-------------
| string | announce | tr_info
| string | scrape | tr_info
| number | tier | tr_info
-------------------+----------+------------------------+-------------
webseeds, 32768 | array | webseeds
+----------+--------------------------------------
| webseeds is an array of strings:
+----------+------------------------+-------------
| string | webseed URL | tr_info
-------------------+----------+------------------------+-------------
key | type | source
-----------------------+--------------------------------------+---------
activityDate | number | tr_stat
addedDate | number | tr_stat
announceResponse | string | tr_stat
announceURL | string | tr_stat
comment | string | tr_info
corruptEver | number | tr_stat
creator | string | tr_info
dateCreated | number | tr_info
desiredAvailable | number | tr_stat
doneDate | number | tr_stat
downloadedEver | number | tr_stat
downloadLimitMode | number | tr_torrent
downloadLimit | number | tr_torrent
error | number | tr_stat
errorString | number | tr_stat
eta | number | tr_stat
files | array (see below) | n/a
hashString | string | tr_info
haveUnchecked | number | tr_stat
haveValid | number | tr_stat
id | number | tr_torrent
isPrivate | 'boolean | tr_torrent
lastAnnounceTime | number | tr_stat
lastScrapeTime | number | tr_stat
leechers | number | tr_stat
leftUntilDone | number | tr_stat
manualAnnounceTime | number | tr_stat
maxConnectedPeers | number | tr_torrent
name | string | tr_info
nextAnnounceTime | number | tr_stat
nextScrapeTime | number | tr_stat
peersConnected | number | tr_stat
peersFrom | object (see below) | n/a
peersGettingFromUs | number | tr_stat
peersKnown | number | tr_stat
peersSendingToUs | number | tr_stat
pieceCount | tnumber | tr_info
pieceSize | tnumber | tr_info
priorities | array (see below) | n/a
rateDownload | number | tr_stat
rateUpload | number | tr_stat
recheckProgress | number | tr_stat
scrapeResponse | string | tr_stat
scrapeURL | string | tr_stat
seeders | number | tr_stat
sizeWhenDone | number | tr_stat
startDate | number | tr_stat
status | number | tr_stat
swarmSpeed (K/s) | number | tr_stat
timesCompleted | number | tr_stat
trackers | array (see below) | n/a
totalSize | number | tr_info
uploadedEver | number | tr_stat
uploadLimitMode | number | tr_torrent
uploadLimit | number | tr_torrent
uploadRatio | 'double' | tr_stat
wanted | array (see below) | n/a
webseeds | array (see below) | n/a
webseedsSendingToUs | number | tr_stat
| |
| |
-----------------------+--------------------------------------+
files | array of objects, each containing: |
+------------------+-------------------+
| key | type |
| bytesCompleted | number | tr_torrent
| length | number | tr_info
| name | string | tr_info
-----------------------+--------------------------------------+
peersFrom | an object containing: |
+------------------+-------------------+
| fromCache | number | tr_stat
| fromIncoming | number | tr_stat
| fromPex | number | tr_stat
| fromTracker | number | tr_stat
-----------------------+--------------------------------------+
priorities | an array of tr_info.filecount | tr_info
| numbers. each is the tr_priority_t |
| mode for the corresponding file. |
-----------------------+--------------------------------------+
trackers | array of objects, each containing: |
+------------------+-------------------+
| announce | string | tr_info
| scrape | string | tr_info
| tier | number | tr_info
-----------------------+--------------------------------------+
wanted | an array of tr_info.fileCount | tr_info
| 'booleans' true if the corresponding |
| file is to be downloaded. |
-----------------------+--------------------------------------+
webseeds | an array of strings: |
+------------------+-------------------+
| webseed | string | tr_info
+------------------+-------------------+
Example:
Say we want to get the name and total size of torrents #7 and #10.
name is in the "id" section (32) and total size is in "size" (2048),
so the "fields" argument will be 32 + 2048 == 2080.
Request:
{
"arguments": {
"fields": 2080,
"ids": [ 7, 10 ],
"fields": [ "name", "totalSize" ],
"sort-method": "name"
}
"method": "torrent-get",
@ -246,24 +229,14 @@
"fields": 2080,
"torrents": [
{
"hashString": "sijioejisoefjiosejfioi",
"haveUnchecked", 23023,
"haveValid", 27986795145,
"leftUntilDone", 0,
"id": 10,
"name": "Fedora x86_64 DVD",
"sizeWhenDone", 34983493932,
"totalSize", 34983493932,
"uniqueId": 10,
}
{
"hashString": "asdasiofjosejfoasjfiosj",
"haveUnchecked", 0,
"haveValid", 9923890123,
"leftUntilDone", 0,
"id": 7,
"name": "Ubuntu x86_64 DVD",
"sizeWhenDone", 9923890123,
"totalSize", 9923890123,
"uniqueId": 7,
},
]
},

View File

@ -198,122 +198,157 @@ addTrackers( const tr_info * info, tr_benc * trackers )
}
static void
addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields )
addField( const tr_torrent * tor, tr_benc * d, const char * key )
{
const tr_info * inf = tr_torrentInfo( tor );
const tr_stat * st = tr_torrentStat( (tr_torrent*)tor );
tr_bencInitDict( d, 64 );
if( fields & TR_RPC_TORRENT_ACTIVITY ) {
tr_bencDictAddInt( d, "desiredAvailable", st->desiredAvailable );
tr_bencDictAddInt( d, "eta", st->eta );
tr_bencDictAddInt( d, "peersConnected", st->peersConnected );
tr_bencDictAddInt( d, "peersGettingFromUs", st->peersGettingFromUs );
tr_bencDictAddInt( d, "peersSendingToUs", st->peersSendingToUs );
tr_bencDictAddInt( d, "rateDownload", (int)(st->rateDownload*1024) );
tr_bencDictAddInt( d, "rateUpload", (int)(st->rateUpload*1024) );
tr_bencDictAddDouble( d, "recheckProgress", st->recheckProgress );
tr_bencDictAddInt( d, "status", st->status );
tr_bencDictAddInt( d, "swarmSpeed", (int)(st->swarmSpeed*1024) );
tr_bencDictAddInt( d, "webseedsSendingToUs", st->webseedsSendingToUs );
tr_bencDictAddDouble( d, "uploadRatio", tr_getRatio( st->uploadedEver, st->downloadedEver ) );
}
if( fields & TR_RPC_TORRENT_ANNOUNCE ) {
tr_bencDictAddStr( d, "announceResponse", st->announceResponse );
tr_bencDictAddStr( d, "announceURL", st->announceURL );
tr_bencDictAddInt( d, "lastAnnounceTime", st->lastAnnounceTime );
tr_bencDictAddInt( d, "manualAnnounceTime", st->manualAnnounceTime );
tr_bencDictAddInt( d, "nextAnnounceTime", st->nextAnnounceTime );
}
if( fields & TR_RPC_TORRENT_ERROR ) {
tr_bencDictAddInt( d, "error", st->error );
tr_bencDictAddStr( d, "errorString", st->errorString );
}
if( fields & TR_RPC_TORRENT_FILES )
addFiles( tor, tr_bencDictAddList( d, "files", inf->fileCount ) );
if( fields & TR_RPC_TORRENT_HISTORY ) {
tr_bencDictAddInt( d, "activityDate", st->activityDate );
tr_bencDictAddInt( d, "addedDate", st->addedDate );
tr_bencDictAddInt( d, "corruptEver", st->corruptEver );
tr_bencDictAddInt( d, "doneDate", st->doneDate );
tr_bencDictAddInt( d, "downloadedEver", st->downloadedEver );
tr_bencDictAddInt( d, "startDate", st->startDate );
tr_bencDictAddInt( d, "uploadedEver", st->uploadedEver );
}
if( fields & TR_RPC_TORRENT_ID ) {
tr_bencDictAddInt( d, "id", st->id );
tr_bencDictAddStr( d, "hashString", tor->info.hashString );
tr_bencDictAddStr( d, "name", inf->name );
}
if( fields & TR_RPC_TORRENT_INFO ) {
tr_bencDictAddStr( d, "comment", inf->comment ? inf->comment : "" );
tr_bencDictAddStr( d, "creator", inf->creator ? inf->creator : "" );
tr_bencDictAddInt( d, "dateCreated", inf->dateCreated );
tr_bencDictAddInt( d, "isPrivate", tr_torrentIsPrivate( tor ) );
tr_bencDictAddInt( d, "pieceCount", inf->pieceCount );
tr_bencDictAddInt( d, "pieceSize", inf->pieceSize );
}
if( fields & TR_RPC_TORRENT_LIMITS ) {
tr_bencDictAddInt( d, "downloadLimit", tr_torrentGetSpeedLimit( tor, TR_DOWN ) );
tr_bencDictAddInt( d, "downloadLimitMode", tr_torrentGetSpeedMode( tor, TR_DOWN ) );
tr_bencDictAddInt( d, "maxConnectedPeers", tr_torrentGetPeerLimit( tor ) );
tr_bencDictAddInt( d, "uploadLimit", tr_torrentGetSpeedLimit( tor, TR_UP ) );
tr_bencDictAddInt( d, "uploadLimitMode", tr_torrentGetSpeedMode( tor, TR_UP ) );
}
if( fields & TR_RPC_TORRENT_PEER_STATS ) {
if( !strcmp( key, "activityDate" ) )
tr_bencDictAddInt( d, key, st->activityDate );
else if( !strcmp( key, "addedDate" ) )
tr_bencDictAddInt( d, key, st->addedDate );
else if( !strcmp( key, "announceResponse" ) )
tr_bencDictAddStr( d, key, st->announceResponse );
else if( !strcmp( key, "announceURL" ) )
tr_bencDictAddStr( d, key, st->announceURL );
else if( !strcmp( key, "comment" ) )
tr_bencDictAddStr( d, key, inf->comment ? inf->comment : "" );
else if( !strcmp( key, "corruptEver" ) )
tr_bencDictAddInt( d, key, st->corruptEver );
else if( !strcmp( key, "creator" ) )
tr_bencDictAddStr( d, key, inf->creator ? inf->creator : "" );
else if( !strcmp( key, "dateCreated" ) )
tr_bencDictAddInt( d, key, inf->dateCreated );
else if( !strcmp( key, "desiredAvailable" ) )
tr_bencDictAddInt( d, key, st->desiredAvailable );
else if( !strcmp( key, "doneDate" ) )
tr_bencDictAddInt( d, key, st->doneDate );
else if( !strcmp( key, "downloadedEver" ) )
tr_bencDictAddInt( d, key, st->downloadedEver );
else if( !strcmp( key, "downloadLimitMode" ) )
tr_bencDictAddInt( d, key, tr_torrentGetSpeedMode( tor, TR_DOWN ) );
else if( !strcmp( key, "downloadLimit" ) )
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_DOWN ) );
else if( !strcmp( key, "error" ) )
tr_bencDictAddInt( d, key, st->error );
else if( !strcmp( key, "errorString" ) )
tr_bencDictAddStr( d, key, st->errorString );
else if( !strcmp( key, "eta" ) )
tr_bencDictAddInt( d, key, st->eta );
else if( !strcmp( key, "files" ) )
addFiles( tor, tr_bencDictAddList( d, key, inf->fileCount ) );
else if( !strcmp( key, "hashString" ) )
tr_bencDictAddStr( d, key, tor->info.hashString );
else if( !strcmp( key, "haveUnchecked" ) )
tr_bencDictAddInt( d, key, st->haveUnchecked );
else if( !strcmp( key, "haveValid" ) )
tr_bencDictAddInt( d, key, st->haveValid );
else if( !strcmp( key, "id" ) )
tr_bencDictAddInt( d, key, st->id );
else if( !strcmp( key, "isPrivate" ) )
tr_bencDictAddInt( d, key, tr_torrentIsPrivate( tor ) );
else if( !strcmp( key, "lastAnnounceTime" ) )
tr_bencDictAddInt( d, key, st->lastAnnounceTime );
else if( !strcmp( key, "lastScrapeTime" ) )
tr_bencDictAddInt( d, key, st->lastScrapeTime );
else if( !strcmp( key, "leechers" ) )
tr_bencDictAddInt( d, key, st->leechers );
else if( !strcmp( key, "leftUntilDone" ) )
tr_bencDictAddInt( d, key, st->leftUntilDone );
else if( !strcmp( key, "manualAnnounceTime" ) )
tr_bencDictAddInt( d, key, st->manualAnnounceTime );
else if( !strcmp( key, "maxConnectedPeers" ) )
tr_bencDictAddInt( d, key, tr_torrentGetPeerLimit( tor ) );
else if( !strcmp( key, "name" ) )
tr_bencDictAddStr( d, key, inf->name );
else if( !strcmp( key, "nextAnnounceTime" ) )
tr_bencDictAddInt( d, key, st->nextAnnounceTime );
else if( !strcmp( key, "nextScrapeTime" ) )
tr_bencDictAddInt( d, key, st->nextScrapeTime );
else if( !strcmp( key, "peersConnected" ) )
tr_bencDictAddInt( d, key, st->peersConnected );
else if( !strcmp( key, "peersFrom" ) ) {
tr_benc * tmp = tr_bencDictAddDict( d, key, 4 );
const int * f = st->peersFrom;
tr_bencDictAddInt( d, "fromCache", f[TR_PEER_FROM_CACHE] );
tr_bencDictAddInt( d, "fromIncoming", f[TR_PEER_FROM_INCOMING] );
tr_bencDictAddInt( d, "fromPex", f[TR_PEER_FROM_PEX] );
tr_bencDictAddInt( d, "fromTracker", f[TR_PEER_FROM_TRACKER] );
tr_bencDictAddInt( tmp, "fromCache", f[TR_PEER_FROM_CACHE] );
tr_bencDictAddInt( tmp, "fromIncoming", f[TR_PEER_FROM_INCOMING] );
tr_bencDictAddInt( tmp, "fromPex", f[TR_PEER_FROM_PEX] );
tr_bencDictAddInt( tmp, "fromTracker", f[TR_PEER_FROM_TRACKER] );
}
if( fields & TR_RPC_TORRENT_PRIORITIES ) {
else if( !strcmp( key, "peersGettingFromUs" ) )
tr_bencDictAddInt( d, key, st->peersGettingFromUs );
else if( !strcmp( key, "peersKnown" ) )
tr_bencDictAddInt( d, key, st->peersKnown );
else if( !strcmp( key, "peersSendingToUs" ) )
tr_bencDictAddInt( d, key, st->peersSendingToUs );
else if( !strcmp( key, "pieceCount" ) )
tr_bencDictAddInt( d, key, inf->pieceCount );
else if( !strcmp( key, "pieceSize" ) )
tr_bencDictAddInt( d, key, inf->pieceSize );
else if( !strcmp( key, "priorities" ) ) {
tr_file_index_t i;
tr_benc * p = tr_bencDictAddList( d, "priorities", inf->fileCount );
tr_benc * w = tr_bencDictAddList( d, "wanted", inf->fileCount );
for( i=0; i<inf->fileCount; ++i ) {
tr_benc * p = tr_bencDictAddList( d, key, inf->fileCount );
for( i=0; i<inf->fileCount; ++i )
tr_bencListAddInt( p, inf->files[i].priority );
}
else if( !strcmp( key, "rateDownload" ) )
tr_bencDictAddInt( d, key, (int)(st->rateDownload*1024) );
else if( !strcmp( key, "rateUpload" ) )
tr_bencDictAddInt( d, key, (int)(st->rateUpload*1024) );
else if( !strcmp( key, "recheckProgress" ) )
tr_bencDictAddDouble( d, key, st->recheckProgress );
else if( !strcmp( key, "scrapeResponse" ) )
tr_bencDictAddStr( d, key, st->scrapeResponse );
else if( !strcmp( key, "scrapeURL" ) )
tr_bencDictAddStr( d, key, st->scrapeURL );
else if( !strcmp( key, "seeders" ) )
tr_bencDictAddInt( d, key, st->seeders );
else if( !strcmp( key, "sizeWhenDone" ) )
tr_bencDictAddInt( d, key, st->sizeWhenDone );
else if( !strcmp( key, "startDate" ) )
tr_bencDictAddInt( d, key, st->startDate );
else if( !strcmp( key, "status" ) )
tr_bencDictAddInt( d, key, st->status );
else if( !strcmp( key, "swarmSpeed" ) )
tr_bencDictAddInt( d, key, (int)(st->swarmSpeed*1024) );
else if( !strcmp( key, "timesCompleted" ) )
tr_bencDictAddInt( d, key, st->timesCompleted );
else if( !strcmp( key, "trackers" ) )
addTrackers( inf, tr_bencDictAddList( d, key, inf->trackerCount ) );
else if( !strcmp( key, "totalSize" ) )
tr_bencDictAddInt( d, key, inf->totalSize );
else if( !strcmp( key, "uploadedEver" ) )
tr_bencDictAddInt( d, key, st->uploadedEver );
else if( !strcmp( key, "uploadLimitMode" ) )
tr_bencDictAddInt( d, key, tr_torrentGetSpeedMode( tor, TR_UP ) );
else if( !strcmp( key, "uploadLimit" ) )
tr_bencDictAddInt( d, key, tr_torrentGetSpeedLimit( tor, TR_UP ) );
else if( !strcmp( key, "uploadRatio" ) )
tr_bencDictAddDouble( d, key, tr_getRatio( st->uploadedEver, st->downloadedEver ) );
else if( !strcmp( key, "wanted" ) ) {
tr_file_index_t i;
tr_benc * w = tr_bencDictAddList( d, key, inf->fileCount );
for( i=0; i<inf->fileCount; ++i )
tr_bencListAddInt( w, inf->files[i].dnd ? 0 : 1 );
}
}
else if( !strcmp( key, "webseeds" ) )
addWebseeds( inf, tr_bencDictAddList( d, key, inf->trackerCount ) );
else if( !strcmp( key, "webseedsSendingToUs" ) )
tr_bencDictAddInt( d, key, st->webseedsSendingToUs );
}
if( fields & TR_RPC_TORRENT_SCRAPE ) {
tr_bencDictAddInt( d, "lastScrapeTime", st->lastScrapeTime );
tr_bencDictAddInt( d, "nextScrapeTime", st->nextScrapeTime );
tr_bencDictAddStr( d, "scrapeResponse", st->scrapeResponse );
tr_bencDictAddStr( d, "scrapeURL", st->scrapeURL );
}
static void
addInfo( const tr_torrent * tor, tr_benc * d, tr_benc * fields )
{
int i;
const int n = tr_bencListSize( fields );
const char * str;
if( fields & TR_RPC_TORRENT_SIZE ) {
tr_bencDictAddInt( d, "haveUnchecked", st->haveUnchecked );
tr_bencDictAddInt( d, "haveValid", st->haveValid );
tr_bencDictAddInt( d, "leftUntilDone", st->leftUntilDone );
tr_bencDictAddInt( d, "sizeWhenDone", st->sizeWhenDone );
tr_bencDictAddInt( d, "totalSize", inf->totalSize );
}
tr_bencInitDict( d, n );
if( fields & TR_RPC_TORRENT_TRACKER_STATS ) {
tr_bencDictAddInt( d, "leechers", st->leechers );
tr_bencDictAddInt( d, "peersKnown", st->peersKnown );
tr_bencDictAddInt( d, "seeders", st->seeders );
tr_bencDictAddInt( d, "timesCompleted", st->timesCompleted );
}
if( fields & TR_RPC_TORRENT_TRACKERS )
addTrackers( inf, tr_bencDictAddList( d, "trackers", inf->trackerCount ) );
if( fields & TR_RPC_TORRENT_WEBSEEDS )
addWebseeds( inf, tr_bencDictAddList( d, "webseeds", inf->trackerCount ) );
for( i=0; i<n; ++i )
if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) )
addField( tor, d, str );
}
static const char*
@ -322,11 +357,10 @@ torrentGet( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
int i, torrentCount;
tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
tr_benc * list = tr_bencDictAddList( args_out, "torrents", torrentCount );
int64_t fields = 0;
tr_benc * fields;
if( !tr_bencDictFindInt( args_in, "fields", &fields ) )
fields = ~(int64_t)0;
tr_bencDictAddInt( args_out, "fields", fields );
if( !tr_bencDictFindList( args_in, "fields", &fields ) )
return "no fields specified";
for( i=0; i<torrentCount; ++i )
addInfo( torrents[i], tr_bencListAdd( list ), fields );
@ -484,8 +518,14 @@ torrentAdd( tr_handle * h, tr_benc * args_in, tr_benc * args_out )
tr_ctorFree( ctor );
if( tor ) {
addInfo( tor, tr_bencDictAdd( args_out, "torrent-added" ), TR_RPC_TORRENT_ID );
tr_benc fields;
tr_bencInitList( &fields, 3 );
tr_bencListAddStr( &fields, "id" );
tr_bencListAddStr( &fields, "name" );
tr_bencListAddStr( &fields, "hashString" );
addInfo( tor, tr_bencDictAdd( args_out, "torrent-added" ), &fields );
notify( h, TR_RPC_TORRENT_ADDED, tor );
tr_bencFree( &fields );
} else if( err == TR_EDUPLICATE ) {
return "duplicate torrent";
} else if( err == TR_EINVALID ) {

View File

@ -17,26 +17,6 @@
**** RPC processing
***/
enum
{
TR_RPC_TORRENT_ACTIVITY = (1<<0),
TR_RPC_TORRENT_ANNOUNCE = (1<<1),
TR_RPC_TORRENT_ERROR = (1<<2),
TR_RPC_TORRENT_FILES = (1<<3),
TR_RPC_TORRENT_HISTORY = (1<<4),
TR_RPC_TORRENT_ID = (1<<5),
TR_RPC_TORRENT_INFO = (1<<6),
TR_RPC_TORRENT_LIMITS = (1<<7),
TR_RPC_TORRENT_PEERS = (1<<8),
TR_RPC_TORRENT_PEER_STATS = (1<<9),
TR_RPC_TORRENT_PRIORITIES = (1<<10),
TR_RPC_TORRENT_SCRAPE = (1<<11),
TR_RPC_TORRENT_SIZE = (1<<12),
TR_RPC_TORRENT_TRACKER_STATS = (1<<13),
TR_RPC_TORRENT_TRACKERS = (1<<14),
TR_RPC_TORRENT_WEBSEEDS = (1<<15)
};
struct tr_benc;
struct tr_handle;

View File

@ -21,23 +21,6 @@ RPC._PeerPort = 'port';
RPC._UpSpeedLimited = 'speed-limit-up-enabled';
RPC._DownSpeedLimited = 'speed-limit-down-enabled';
RPC._TorrentActivity = (1<<0);
RPC._TorrentAnnounce = (1<<1);
RPC._TorrentError = (1<<2);
RPC._TorrentFiles = (1<<3);
RPC._TorrentHistory = (1<<4);
RPC._TorrentId = (1<<5);
RPC._TorrentInfo = (1<<6);
RPC._TorrentLimits = (1<<7);
RPC._TorrentPeers = (1<<8);
RPC._TorrentPeerStats = (1<<9);
RPC._TorrentPriorities = (1<<10);
RPC._TorrentScrape = (1<<11);
RPC._TorrentSize = (1<<12);
RPC._TorrentTrackerStats = (1<<13);
RPC._TorrentTrackers = (1<<14);
RPC._TorrentWebseeds = (1<<15);
function TransmissionRemote( controller )
{
this.initialize( controller );
@ -103,16 +86,14 @@ TransmissionRemote.prototype =
var o = { };
o.method = 'torrent-get'
o.arguments = { };
o.arguments.fields = RPC._TorrentActivity
+ RPC._TorrentAnnounce
+ RPC._TorrentError
+ RPC._TorrentHistory
+ RPC._TorrentId
+ RPC._TorrentInfo
+ RPC._TorrentLimits
+ RPC._TorrentScrape
+ RPC._TorrentSize
+ RPC._TorrentTrackerStats;
o.arguments.fields = [
'addedDate', 'announceURL', 'comment', 'creator',
'dateCreated', 'downloadedEver', 'error', 'errorString',
'eta', 'hashString', 'haveUnchecked', 'haveValid', 'id',
'isPrivate', 'leechers', 'leftUntilDone', 'name',
'peersGettingFromUs', 'peersKnown', 'peersSendingToUs',
'rateDownload', 'rateUpload', 'seeders', 'sizeWhenDone',
'status', 'swarmSpeed', 'totalSize', 'uploadedEver' ];
this.sendRequest( RPC._Root, $.toJSON(o), function(data) {
tr.updateTorrents( data.arguments.torrents );
}, "json" );