(rpc) simplify the rpc accessors

This commit is contained in:
Charles Kerr 2008-06-16 03:47:50 +00:00
parent 1f361879bb
commit 6cce27bf54
8 changed files with 309 additions and 252 deletions

View File

@ -148,6 +148,7 @@ readargs( int argc, char ** argv )
char * tmp;
char buf[MAX_PATH_LENGTH];
int addArg = TRUE;
int64_t fields = 0;
tr_benc top, *args;
tr_bencInitDict( &top, 3 );
args = tr_bencDictAddDict( &top, "arguments", 0 );
@ -193,8 +194,12 @@ readargs( int argc, char ** argv )
case 'f': tr_bencDictAddStr( &top, "method", "session-set" );
tr_bencDictAddStr( args, "download-dir", absolutify(buf,sizeof(buf),optarg) );
break;
case 'l': tr_bencDictAddStr( &top, "method", "torrent-list" );
case 'l': tr_bencDictAddStr( &top, "method", "torrent-info" );
tr_bencDictAddInt( &top, "tag", TAG_LIST );
fields = TR_RPC_TORRENT_FIELD_ID
| TR_RPC_TORRENT_FIELD_ACTIVITY
| TR_RPC_TORRENT_FIELD_SIZE;
tr_bencDictAddInt( args, "fields", fields );
break;
case 'm': tr_bencDictAddStr( &top, "method", "session-set" );
tr_bencDictAddInt( args, "port-forwarding-enabled", 1 );
@ -306,7 +311,7 @@ processResponse( const char * host, int port,
if( ( tag == TAG_LIST ) &&
( tr_bencDictFindDict( &top, "arguments", &args ) ) &&
( tr_bencDictFindList( args, "list", &list ) ) )
( tr_bencDictFindList( args, "torrent-info", &list ) ) )
{
int i, n;
for( i=0, n=tr_bencListSize( list ); i<n; ++i )
@ -315,11 +320,11 @@ processResponse( const char * host, int port,
const char *name, *ratiostr, *upstr, *dnstr;
tr_benc * d = tr_bencListChild( list, i );
if( tr_bencDictFindInt( d, "id", &id )
&& tr_bencDictFindInt( d, "status", &status )
&& tr_bencDictFindStr( d, "name", &name )
&& tr_bencDictFindStr( d, "ratio", &ratiostr )
&& tr_bencDictFindStr( d, "rateDownload", &dnstr )
&& tr_bencDictFindStr( d, "rateUpload", &upstr )
&& tr_bencDictFindStr( d, "rateDownload", &dnstr ) )
&& tr_bencDictFindStr( d, "ratio", &ratiostr )
&& tr_bencDictFindInt( d, "status", &status ) )
{
printf( "%4d. Up: %5.1f Down: %5.1f Ratio: %4.1f %-15s %s\n",
(int)id,

View File

@ -75,105 +75,178 @@
Response arguments: none
3.2. Torrent List
An overview list of torrents.
Method name: "torrent-list".
Request arguments: none.
Response arguments: "list", an array of objects that contain these keys:
key | value type
----------------------+-------------------------------------------------
"downloadedEver" | number
"eta" | number
"hashString" | string
"id" | number
"name" | string
"peersConnected" | number
"peersSendingToUs" | number
"peersGettingFromUs" | number
"percentDone" | double
"rateDownload" | double
"rateUpload" | double
"ratio" | double
"sizeWhenDone" | number
"status" | number
"uploadedEver" | number
3.3. Torrent Info Requests
3.2. Torrent Information Requests
Method name: "torrent-info".
Request arguments: 3.1's optional "ids" argument.
The request takes two arguments: "ids", as described in section 3.1, and
"fields", a bitwise-or'ed number which specifies which torrent information
is being requested. (See libtransmission/rpc.h's enumeration)
The response arguments are "fields" (identical to the request argument)
and "torrent-info", a list of objects that each contain the pairs
shown here:
Response arguments: "torrent-info", an array of objects based on
libtransmission's tr_info struct but different in the following ways:
(1) the torrent's "id" field is added.
(2) tr_info's "hash" field is omitted.
(3) tr_info's "pieces" field is omitted.
(4) tr_file's only included pieces are "name" and "length".
field and | response | response | source
numeric value | type | name |
-------------------+----------+------------------------+-------------
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 | tr_stat
| number | webseedsSendingToUs | tr_stat
-------------------+----------+------------------------+-------------
announce, 2 | string | announceResponse | tr_stat
| string | announceURL | tr_stat
| string | lastAnnounceTime | tr_stat
| string | manualAnnounceTime | tr_stat
| string | 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 | 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
-------------------+----------+------------------------+-------------
limits, 128 | number | downloadLimit | tr_torrent
| number | downloadLimitMode | tr_torrent
| number | maxConnectedPeers | tr_torrent
| number | uploadLimit | tr_torrent
| number | uploadLimitMode | tr_torrent
-------------------+----------+------------------------+-------------
peers, 256 | object | peersFrom | tr_stat
+----------+------------------------+-------------
| peersFrom contains:
+----------+------------------------+-------------
| number | cache | tr_stat
| number | incoming | tr_stat
| number | pex | tr_stat
| number | tracker | tr_stat
-------------------+----------+------------------------+-------------
scrape, 512 | number | lastScrapeTime | tr_stat
| number | nextScrapeTime | tr_stat
| string | scrapeResponse | tr_stat
| string | scrapeURL | tr_stat
-------------------+----------+------------------------+-------------
size, 1024 | number | haveUnchecked | tr_stat
| number | haveValid | tr_stat
| number | leftUntilDone | tr_stat
| 'double' | percentComplete | tr_stat
| 'double' | percentDone | tr_stat
| 'double' | ratio | tr_stat
| number | sizeWhenDone | tr_stat
| number | totalSize | tr_stat
-------------------+----------+------------------------+-------------
tracker stats, | number | leechers | tr_stat
2048 | number | peersKnown | tr_stat
| number | seeders | tr_stat
| number | timesCompleted | tr_stat
-------------------+----------+--------------------------------------
trackers, 4096 | array | trackers
+----------+--------------------------------------
| trackers is an array of objects that contain:
+----------+------------------------+-------------
| string | announce | tr_info
| string | scrape | tr_info
| number | tier | tr_info
-------------------+----------+------------------------+-------------
webseeds, 8192 | object | webseeds
+----------+--------------------------------------
| webseeds contains:
| an array of weseed url strings
-------------------+----------+------------------------+-------------
Note that this is a fairly high-bandwidth request and that its results
don't change. You should try to cache its results instead of re-calling it.
Example Request:
Example:
Say we want to get the ratio and name of torrents 7 and 10.
name is in the "id" section (32) and ratio is in "size" (1024),
so the "fields" argument will be 32 + 1024 == 1056.
Request:
{
"arguments": { "ids": [ 7, 10 ] }
"arguments": {
"fields": 1056,
"ids": [ 7, 10 ],
}
"method": "torrent-info",
"tag": 39693
}
Example Response:
Response:
{
"tag": 39693
"result": "success",
"arguments": {
"fields": 1056,
"torrent-info": [
{
"id": 7,
"name": "Ubuntu x86_64 DVD",
"pieceCount": 1209233,
"pieceSize": 4096,
"totalSize": 9803930483,
...
{
"hashString": "asdasiofjosejfoasjfiosj",
"haveUnchecked", 0,
"haveValid", 9923890123,
"leftUntilDone", 0,
"name": "Ubundu x86_64 DVD",
"percentComplete", "1.0000",
"percentDone", "1.0000",
"ratio", "2.23222",
"sizeWhenDone", 9923890123,
"totalSize", 9923890123,
"uniqueId": 7,
},
{
"id": 10,
"name": "Ubuntu i386 DVD",
"pieceCount": 83943,
"pieceSize": 12345,
"totalSize": 2398480394,
...
"hashString": "sijioejisoefjiosejfioi",
"haveUnchecked", 23023,
"haveValid", 27986795145,
"leftUntilDone", 0,
"name": "Fedora x86_64 DVD",
"percentComplete", "1.0000",
"percentDone", "0.8010",
"ratio", "0.604034",
"sizeWhenDone", 34983493932,
"totalSize", 34983493932,
"uniqueId": 10,
}
]
}
}
3.4. Torrent Status Requests
Method name: "torrent-status"
Request arguments: 3.1's optional "ids" argument.
Response arguments: "torrent-status", an array of objects
based on libtransmission's tr_stat struct but different
in the following ways:
(1) tr_info's "hashString" field is added.
3.5. Adding a Torrent
3.3. Adding a Torrent
Method name: "torrent-add"
Request arguments:
string | value type & description
key | value type & description
-------------------+-------------------------------------------------
"download-dir" | string path to download the torrent to
"filename" | string location of the .torrent file
@ -185,9 +258,10 @@
All other arguments are optional.
Response arguments: on success, a "torrent-added" object in the
form of one of 3.3's tr_info objects.
form of one of 3.3's tr_info objects with the
fields for id, name, and hashString.
3.6. Other Torrent Settings
3.4. Other Torrent Settings
Common arguments:
@ -199,21 +273,14 @@
"speed-limit-up" | int maximum upload speed (in KiB/s)
"speed-limit-up-enabled" | boolean true if the upload speed is limited
3.6.1. Mutators
3.4.1. Mutators
Method name: "torrent-set"
Request arguments: 3.1's "ids", plus one or more of 3.6's arguments
Response arguments: none
3.6.2. Accessors
Method name: "torrent-get"
Request arguments: none
Response arguments: A "torrents" list of objects containing all
of 3.6's arguments plus the torrent's "id" field.
3.7 File Priorities
3.5 File Priorities
Common arguments:
@ -225,13 +292,13 @@
"priority-low" | array indices of one or more low-priority files
"priority-normal" | array indices of one or more normal-priority files
3.7.1. Mutators
3.5.1. Mutators
Method name: "torrent-set-priorities"
Request arguments: 3.1's "ids", plus one or more of 3.7's arguments
Response arguments: none
3.7.2. Accessors
3.5.2. Accessors
Method name: "torrent-get-priorities"
Request arguments: none

View File

@ -527,7 +527,7 @@ refresh_peers (GtkWidget * top)
fmtpeercount (p->seeders_lb, stat->seeders);
fmtpeercount (p->leechers_lb, stat->leechers);
fmtpeercount (p->completed_lb, stat->completedFromTracker );
fmtpeercount (p->completed_lb, stat->timesCompleted );
free( peers );
}
@ -765,7 +765,7 @@ peer_page_new ( TrTorrent * gtor )
gtk_box_pack_start_defaults (GTK_BOX(hbox),
gtk_alignment_new (0.0f, 0.0f, 0.0f, 0.0f));
l = gtk_label_new (NULL);
gtk_label_set_markup (GTK_LABEL(l), _( "<b>Completed:</b>" ) );
gtk_label_set_markup (GTK_LABEL(l), _( "<b>Times Completed:</b>" ) );
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);
l = p->completed_lb = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX(hbox), l, FALSE, FALSE, 0);

View File

@ -17,6 +17,7 @@
#include "transmission.h"
#include "bencode.h"
#include "ratecontrol.h"
#include "rpc.h"
#include "json.h"
#include "session.h"
@ -154,75 +155,6 @@ torrentVerify( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
****
***/
static const char*
torrentStatus( 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, "torrent-status", torrentCount );
for( i=0; i<torrentCount; ++i )
{
tr_torrent * tor = torrents[i];
const tr_stat * st = tr_torrentStat( tor );
const int * f = st->peersFrom;
tr_benc * d = tr_bencListAddDict( list, 41 );
tr_benc * t;
tr_bencDictAddInt( d, "activityDate", st->activityDate );
tr_bencDictAddStr( d, "announceResponse", st->announceResponse );
tr_bencDictAddStr( d, "announceURL", st->announceURL );
tr_bencDictAddInt( d, "completedFromTracker", st->completedFromTracker );
tr_bencDictAddInt( d, "corruptEver", st->corruptEver );
tr_bencDictAddInt( d, "desiredAvailable", st->desiredAvailable );
tr_bencDictAddInt( d, "downloadedEver", st->downloadedEver );
tr_bencDictAddInt( d, "error", st->error );
tr_bencDictAddStr( d, "errorString", st->errorString );
tr_bencDictAddInt( d, "eta", st->eta );
tr_bencDictAddStr( d, "hashString", tor->info.hashString );
tr_bencDictAddInt( d, "haveUnchecked", st->haveUnchecked );
tr_bencDictAddInt( d, "haveValid", st->haveValid );
tr_bencDictAddInt( d, "id", st->id );
tr_bencDictAddInt( d, "lastAnnounceTime", st->lastAnnounceTime );
tr_bencDictAddInt( d, "lastScrapeTime", st->lastScrapeTime );
tr_bencDictAddInt( d, "leechers", st->leechers );
tr_bencDictAddInt( d, "leftUntilDone", st->leftUntilDone );
tr_bencDictAddInt( d, "manualAnnounceTime", st->manualAnnounceTime );
tr_bencDictAddInt( d, "nextAnnounceTime", st->nextAnnounceTime );
tr_bencDictAddInt( d, "nextScrapeTime", st->nextScrapeTime );
tr_bencDictAddInt( d, "peersConnected", st->peersConnected );
t = tr_bencDictAddDict( d, "peersFrom", 4 );
tr_bencDictAddInt( t, "cache", f[TR_PEER_FROM_CACHE] );
tr_bencDictAddInt( t, "incoming", f[TR_PEER_FROM_INCOMING] );
tr_bencDictAddInt( t, "pex", f[TR_PEER_FROM_PEX] );
tr_bencDictAddInt( t, "tracker", f[TR_PEER_FROM_TRACKER] );
tr_bencDictAddInt( d, "peersGettingFromUs", st->peersGettingFromUs );
tr_bencDictAddInt( d, "peersKnown", st->peersKnown );
tr_bencDictAddInt( d, "peersSendingToUs", st->peersSendingToUs );
tr_bencDictAddDouble( d, "percentComplete", st->percentComplete );
tr_bencDictAddDouble( d, "percentDone", st->percentDone );
tr_bencDictAddDouble( d, "rateDownload", st->rateDownload );
tr_bencDictAddDouble( d, "rateUpload", st->rateUpload );
tr_bencDictAddDouble( d, "ratio", st->ratio );
tr_bencDictAddDouble( d, "recheckProgress", st->recheckProgress );
tr_bencDictAddStr( d, "scrapeResponse", st->scrapeResponse );
tr_bencDictAddStr( d, "scrapeURL", st->scrapeURL );
tr_bencDictAddInt( d, "seeders", st->seeders );
tr_bencDictAddInt( d, "sizeWhenDone", st->sizeWhenDone );
tr_bencDictAddInt( d, "startDate", st->startDate );
tr_bencDictAddInt( d, "status", st->status );
tr_bencDictAddDouble( d, "swarmSpeed", st->swarmSpeed );
tr_bencDictAddInt( d, "uploadedEver", st->uploadedEver );
}
tr_free( torrents );
return NULL;
}
/**
***
**/
static void
addFiles( const tr_info * info, tr_benc * files )
{
@ -236,6 +168,14 @@ addFiles( const tr_info * info, tr_benc * files )
}
}
static void
addWebseeds( const tr_info * info, tr_benc * webseeds )
{
int i;
for( i=0; i<info->webseedCount; ++i )
tr_bencListAddStr( webseeds, info->webseeds[i] );
}
static void
addTrackers( const tr_info * info, tr_benc * trackers )
{
@ -251,24 +191,115 @@ addTrackers( const tr_info * info, tr_benc * trackers )
}
static void
addInfo( const tr_torrent * tor, tr_benc * d )
addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields )
{
const tr_info * inf = tr_torrentInfo( tor );
tr_bencInitDict( d, 14 );
tr_bencDictAddStr( d, "comment", inf->comment ? inf->comment : "" );
tr_bencDictAddStr( d, "creator", inf->creator ? inf->creator : "" );
tr_bencDictAddInt( d, "dateCreated", inf->dateCreated );
addFiles( inf, tr_bencDictAddList( d, "files", inf->fileCount ) );
tr_bencDictAddStr( d, "hashString", inf->hashString );
tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
tr_bencDictAddInt( d, "isMultifile", inf->isMultifile );
tr_bencDictAddInt( d, "isPrivate", inf->isPrivate );
tr_bencDictAddStr( d, "name", inf->name );
tr_bencDictAddInt( d, "pieceCount", inf->pieceCount );
tr_bencDictAddInt( d, "pieceSize", inf->pieceSize );
tr_bencDictAddStr( d, "torrent", inf->torrent );
tr_bencDictAddInt( d, "totalSize", inf->totalSize );
addTrackers( inf, tr_bencDictAddList( d, "trackers", inf->trackerCount ) );
const tr_stat * st = tr_torrentStat( (tr_torrent*)tor );
tr_bencInitDict( d, 64 );
if( fields & TR_RPC_TORRENT_FIELD_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_bencDictAddDouble( d, "rateDownload", st->rateDownload );
tr_bencDictAddDouble( d, "rateUpload", st->rateUpload );
tr_bencDictAddDouble( d, "recheckProgress", st->recheckProgress );
tr_bencDictAddInt( d, "status", st->status );
tr_bencDictAddDouble( d, "swarmSpeed", st->swarmSpeed );
tr_bencDictAddInt( d, "webseedsSendingToUs", st->webseedsSendingToUs );
}
if( fields & TR_RPC_TORRENT_FIELD_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_FIELD_ERROR ) {
tr_bencDictAddInt( d, "error", st->error );
tr_bencDictAddStr( d, "errorString", st->errorString );
}
if( fields & TR_RPC_TORRENT_FIELD_FILES )
addFiles( inf, tr_bencDictAddList( d, "files", inf->fileCount ) );
if( fields & TR_RPC_TORRENT_FIELD_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_FIELD_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_FIELD_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, "pieceCount", inf->pieceCount );
tr_bencDictAddInt( d, "pieceSize", inf->pieceSize );
}
if( fields & TR_RPC_TORRENT_FIELD_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_FIELD_PEERS ) {
const int * from = st->peersFrom;
tr_benc * f;
f = tr_bencDictAddDict( d, "peersFrom", 4 );
tr_bencDictAddInt( f, "cache", from[TR_PEER_FROM_CACHE] );
tr_bencDictAddInt( f, "incoming", from[TR_PEER_FROM_INCOMING] );
tr_bencDictAddInt( f, "pex", from[TR_PEER_FROM_PEX] );
tr_bencDictAddInt( f, "tracker", from[TR_PEER_FROM_TRACKER] );
}
if( fields & TR_RPC_TORRENT_FIELD_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 );
}
if( fields & TR_RPC_TORRENT_FIELD_SIZE ) {
tr_bencDictAddInt( d, "haveUnchecked", st->haveUnchecked );
tr_bencDictAddInt( d, "haveValid", st->haveValid );
tr_bencDictAddInt( d, "leftUntilDone", st->leftUntilDone );
tr_bencDictAddDouble( d, "percentComplete", st->percentComplete );
tr_bencDictAddDouble( d, "percentDone", st->percentDone );
tr_bencDictAddDouble( d, "ratio", st->ratio );
tr_bencDictAddInt( d, "sizeWhenDone", st->sizeWhenDone );
tr_bencDictAddInt( d, "totalSize", inf->totalSize );
}
if( fields & TR_RPC_TORRENT_FIELD_TRACKER_STATS ) {
tr_bencDictAddInt( d, "leechers", st->leechers );
tr_bencDictAddInt( d, "peersKnown", st->peersKnown );
tr_bencDictAddInt( d, "seeders", st->seeders );
tr_bencDictAddDouble( d, "timesCompleted", st->timesCompleted );
}
if( fields & TR_RPC_TORRENT_FIELD_TRACKERS )
addTrackers( inf, tr_bencDictAddList( d, "trackers", inf->trackerCount ) );
if( fields & TR_RPC_TORRENT_FIELD_WEBSEEDS )
addWebseeds( inf, tr_bencDictAddList( d, "webseeds", inf->trackerCount ) );
}
static const char*
@ -277,84 +308,22 @@ torrentInfo( 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, "torrent-info", torrentCount );
int64_t fields = 0;
if( !tr_bencDictFindInt( args_in, "fields", &fields ) )
fields = ~(int64_t)0;
tr_bencDictAddInt( args_out, "fields", fields );
for( i=0; i<torrentCount; ++i )
addInfo( torrents[i], tr_bencListAdd( list ) );
addInfo( torrents[i], tr_bencListAdd( list ), fields );
tr_free( torrents );
return NULL;
}
/**
***
**/
static const char*
torrentList( 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, "list", torrentCount );
for( i=0; i<torrentCount; ++i )
{
tr_torrent * tor = torrents[i];
const tr_stat * st = tr_torrentStat( tor );
tr_benc * d = tr_bencListAddDict( list, 15 );
tr_bencDictAddInt( d, "downloadedEver", st->downloadedEver );
tr_bencDictAddInt( d, "eta", st->eta );
tr_bencDictAddStr( d, "hashString", tor->info.hashString );
tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
tr_bencDictAddStr( d, "name", tor->info.name );
tr_bencDictAddInt( d, "peersConnected", st->peersConnected );
tr_bencDictAddInt( d, "peersGettingFromUs", st->peersGettingFromUs );
tr_bencDictAddInt( d, "peersSendingToUs", st->peersSendingToUs );
tr_bencDictAddDouble( d, "percentDone", st->percentDone );
tr_bencDictAddDouble( d, "rateDownload", st->rateDownload );
tr_bencDictAddDouble( d, "rateUpload", st->rateUpload );
tr_bencDictAddDouble( d, "ratio", st->ratio );
tr_bencDictAddInt( d, "sizeWhenDone", st->sizeWhenDone );
tr_bencDictAddInt( d, "status", st->status );
tr_bencDictAddInt( d, "uploadedEver", st->uploadedEver );
}
tr_free( torrents );
return NULL;
}
/**
***
**/
static const char*
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 );
for( i=0; i<torrentCount; ++i )
{
tr_torrent * tor = torrents[i];
tr_benc * d = tr_bencListAddDict( list, 6 );
tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
tr_bencDictAddInt( d, "peer-limit",
tr_torrentGetPeerLimit( tor ) );
tr_bencDictAddInt( d, "speed-limit-down",
tr_torrentGetSpeedLimit( tor, TR_DOWN ) );
tr_bencDictAddInt( d, "speed-limit-down-enabled",
tr_torrentGetSpeedMode( tor, TR_DOWN )
== TR_SPEEDLIMIT_SINGLE );
tr_bencDictAddInt( d, "speed-limit-up",
tr_torrentGetSpeedLimit( tor, TR_UP ) );
tr_bencDictAddInt( d, "speed-limit-up-enabled",
tr_torrentGetSpeedMode( tor, TR_UP )
== TR_SPEEDLIMIT_SINGLE );
}
tr_free( torrents );
return NULL;
}
/***
****
***/
static const char*
torrentSet( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED )
@ -572,7 +541,7 @@ 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" ) );
addInfo( tor, tr_bencDictAdd( args_out, "torrent-added" ), TR_RPC_TORRENT_FIELD_ID );
notify( h, TR_RPC_TORRENT_ADDED, tor );
} else if( err == TR_EDUPLICATE ) {
return "duplicate torrent";
@ -676,14 +645,11 @@ struct method {
{ "session-set", sessionSet },
{ "torrent-add", torrentAdd },
{ "torrent-get-priorities", torrentGetPriorities },
{ "torrent-get", torrentGet },
{ "torrent-info", torrentInfo },
{ "torrent-list", torrentList },
{ "torrent-remove", torrentRemove },
{ "torrent-set-priorities", torrentSetPriorities },
{ "torrent-set", torrentSet },
{ "torrent-start", torrentStart },
{ "torrent-status", torrentStatus },
{ "torrent-stop", torrentStop },
{ "torrent-verify", torrentVerify }
};

View File

@ -17,6 +17,24 @@
**** RPC processing
***/
enum
{
TR_RPC_TORRENT_FIELD_ACTIVITY = (1<<0),
TR_RPC_TORRENT_FIELD_ANNOUNCE = (1<<1),
TR_RPC_TORRENT_FIELD_ERROR = (1<<2),
TR_RPC_TORRENT_FIELD_FILES = (1<<3),
TR_RPC_TORRENT_FIELD_HISTORY = (1<<4),
TR_RPC_TORRENT_FIELD_ID = (1<<5),
TR_RPC_TORRENT_FIELD_INFO = (1<<6),
TR_RPC_TORRENT_FIELD_LIMITS = (1<<7),
TR_RPC_TORRENT_FIELD_PEERS = (1<<8),
TR_RPC_TORRENT_FIELD_SCRAPE = (1<<9),
TR_RPC_TORRENT_FIELD_SIZE = (1<<10),
TR_RPC_TORRENT_FIELD_TRACKER_STATS = (1<<11),
TR_RPC_TORRENT_FIELD_TRACKERS = (1<<12),
TR_RPC_TORRENT_FIELD_WEBSEEDS = (1<<13)
};
struct tr_benc;
struct tr_handle;
@ -39,4 +57,5 @@ tr_rpc_parse_list_str( struct tr_benc * setme,
const char * list_str,
size_t list_str_len );
#endif

View File

@ -712,7 +712,7 @@ tr_torrentStat( tr_torrent * tor )
s->announceURL = ti ? ti->announce : NULL;
s->scrapeURL = ti ? ti->scrape : NULL;
tr_trackerStat( tc, s );
tr_trackerGetCounts( tc, &s->completedFromTracker,
tr_trackerGetCounts( tc, &s->timesCompleted,
&s->leechers,
&s->seeders );
tr_peerMgrTorrentStats( tor->handle->peerMgr,

View File

@ -1247,7 +1247,7 @@ typedef struct tr_stat
int leechers;
/** Number of finished downloads that the tracker says torrent has */
int completedFromTracker;
int timesCompleted;
/** Byte count of all the piece data we'll have downloaded when we're done,
whether or not we have it yet. [0...tr_info.totalSize] */

View File

@ -1277,7 +1277,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
- (int) completedFromTracker
{
return fStat->completedFromTracker;
return fStat->timesCompleted;
}
- (int) totalPeersConnected