From dceabc5661f5b4dbff8be0660e5666c4ca7a752c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 May 2008 16:59:51 +0000 Subject: [PATCH] make tr_stat identical in transmission.h and rpc-spec.txt. --- doc/rpc-spec.txt | 31 ++++++++++++------------------- libtransmission/rpc.c | 11 +++++------ libtransmission/torrent.c | 17 +++++++++-------- libtransmission/transmission.h | 6 +++++- macosx/Torrent.m | 4 ++-- 5 files changed, 33 insertions(+), 36 deletions(-) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 5cf489148..2d4b263c9 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -7,8 +7,7 @@ The JSON terminology in RFC 4627 is used. "array" is equivalent to a benc list; "object" is equivalent to a benc dictionary; - an object's "keys" are the dictionary's string keys, - and an object's "members" are its key/value pairs. + and an object's "keys" are the dictionary's string keys. 2. Message Format @@ -26,8 +25,8 @@ Requests supports three keys: (1) A required "method" string telling the name of the method to invoke - (2) An optional "arguments" object of name/value pairs - (3) An optional "tag" integer used for clients to track responses. + (2) An optional "arguments" object of key/value pairs + (3) An optional "tag" integer used by clients to track responses. If provided by a request, the response MUST include the same tag. 2.2. Responses @@ -36,13 +35,13 @@ (1) A required "result" string whose value must be "success" on success, or an error string on failure. - (2) An optional "arguments" object of name/value pairs + (2) An optional "arguments" object of key/value pairs (3) An optional "tag" integer as described in 2.1. -2.3. Request IPC Notation +2.3. Request URL Query Notation - As a convenience, a casual URI notation is supported for requests via the - query portion of a URI. The advantage of this is that all current requests + As a convenience, a casual notation is supported for requests via the + query portion of a URL. The advantage of this is that all current requests can be invoked via a very simple http GET request. The possible future disadvantage is that it limits nesting and listing structured requests. @@ -97,7 +96,7 @@ (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 "firstPiece", "lastPiece", and "offset" fields are omitted. + (4) tr_file's only included pieces are "name" and "length". 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. @@ -143,14 +142,8 @@ Request arguments: 3.1's optional "ids" argument. - Response arguments: "torrent-status", an array of objects based - on libtransmission's tr_stat struct but differerent in the - following ways: - - (1) the torrent's "id" field is added. - (2) tr_info's "name" field is added. - (3) tr_stat's "tracker" field is omitted, and is instead - replaced with two strings: "announce-url" and scrape-url" + Response arguments: "torrent-status", an array of objects + identical to libtransmission's tr_stat struct. 3.5. Adding a Torrent @@ -172,7 +165,7 @@ Response arguments: on success, a "torrent-added" object in the form of one of 3.3's tr_info objects. -3.6. Other torrent settings +3.6. Other Torrent Settings Common arguments: @@ -195,7 +188,7 @@ 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" int. + of 3.6's arguments plus the torrent's "id" field. 3.7 File Priorities diff --git a/libtransmission/rpc.c b/libtransmission/rpc.c index 2e27143f7..0893a3b2d 100644 --- a/libtransmission/rpc.c +++ b/libtransmission/rpc.c @@ -167,10 +167,11 @@ torrentStatus( tr_handle * handle, tr_benc * args_in, tr_benc * args_out ) const tr_stat * st = tr_torrentStat( tor ); const int * f = st->peersFrom; const struct tr_tracker_stat * s = &st->trackerStat; - tr_benc * d = tr_bencListAddDict( list, 33 ); + tr_benc * d = tr_bencListAddDict( list, 35 ); tr_benc * t; tr_bencDictAddInt( d, "activityDate", st->activityDate ); + tr_bencDictAddStr( d, "announceURL", st->announceURL ); tr_bencDictAddInt( d, "completedFromTracker", st->completedFromTracker ); tr_bencDictAddInt( d, "corruptEver", st->corruptEver ); tr_bencDictAddInt( d, "desiredAvailable", st->desiredAvailable ); @@ -180,11 +181,10 @@ torrentStatus( tr_handle * handle, tr_benc * args_in, tr_benc * args_out ) tr_bencDictAddInt( d, "eta", st->eta ); tr_bencDictAddInt( d, "haveUnchecked", st->haveUnchecked ); tr_bencDictAddInt( d, "haveValid", st->haveValid ); - tr_bencDictAddInt( d, "id", tr_torrentId( tor ) ); + tr_bencDictAddInt( d, "id", st->id ); tr_bencDictAddInt( d, "leechers", st->leechers ); tr_bencDictAddInt( d, "leftUntilDone", st->leftUntilDone ); tr_bencDictAddInt( d, "manualAnnounceTime", st->manualAnnounceTime ); - tr_bencDictAddStr( d, "name", tor->info.name ); tr_bencDictAddInt( d, "peersConnected", st->peersConnected ); t = tr_bencDictAddDict( d, "peersFrom", 4 ); tr_bencDictAddInt( t, "cache", f[TR_PEER_FROM_CACHE] ); @@ -200,6 +200,7 @@ torrentStatus( tr_handle * handle, tr_benc * args_in, tr_benc * args_out ) tr_bencDictAddDouble( d, "rateUpload", st->rateUpload ); tr_bencDictAddDouble( d, "ratio", st->ratio ); tr_bencDictAddDouble( d, "recheckProgress", st->recheckProgress ); + tr_bencDictAddStr( d, "scrapeURL", st->scrapeURL ); tr_bencDictAddInt( d, "seeders", st->seeders ); tr_bencDictAddInt( d, "sizeWhenDone", st->sizeWhenDone ); tr_bencDictAddInt( d, "startDate", st->startDate ); @@ -231,11 +232,9 @@ addFiles( const tr_info * info, tr_benc * files ) for( i=0; ifileCount; ++i ) { const tr_file * file = &info->files[i]; - tr_benc * d = tr_bencListAddDict( files, 4 ); - tr_bencDictAddInt( d, "dnd", file->dnd ); + tr_benc * d = tr_bencListAddDict( files, 2 ); tr_bencDictAddInt( d, "length", file->length ); tr_bencDictAddStr( d, "name", file->name ); - tr_bencDictAddInt( d, "priority", file->priority ); } } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 191f2ef0d..9ce980068 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -686,6 +686,7 @@ tr_torrentStat( tr_torrent * tor ) { tr_stat * s; struct tr_tracker * tc; + const tr_tracker_info * ti; if( !tor ) return NULL; @@ -695,15 +696,20 @@ tr_torrentStat( tr_torrent * tor ) tor->lastStatTime = time( NULL ); s = &tor->stats; + s->id = tor->uniqueId; s->status = tr_torrentGetStatus( tor ); s->error = tor->error; memcpy( s->errorString, tor->errorString, sizeof( s->errorString ) ); tc = tor->tracker; - s->tracker = tr_trackerGetAddress( tor->tracker ); - - tr_trackerStat( tor->tracker, &s->trackerStat ); + ti = tr_trackerGetAddress( tor->tracker ); + s->announceURL = ti ? ti->announce : NULL; + s->scrapeURL = ti ? ti->scrape : NULL; + tr_trackerStat( tc, &s->trackerStat ); + tr_trackerGetCounts( tc, &s->completedFromTracker, + &s->leechers, + &s->seeders ); tr_peerMgrTorrentStats( tor->handle->peerMgr, tor->info.hash, @@ -725,11 +731,6 @@ tr_torrentStat( tr_torrent * tor ) 1.0 - (tr_torrentCountUncheckedPieces( tor ) / (double) tor->info.pieceCount); tr_torrentGetRates( tor, &s->rateDownload, &s->rateUpload ); - - tr_trackerGetCounts( tc, - &s->completedFromTracker, - &s->leechers, - &s->seeders ); s->swarmSpeed = tr_rcRate( tor->swarmSpeed ); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 5125b320f..11e6a3bed 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -900,10 +900,14 @@ tr_torrent_status tr_torrentGetStatus( tr_torrent * ); struct tr_stat { + int id; + tr_torrent_status status; struct tr_tracker_stat trackerStat; - const tr_tracker_info * tracker; + + char * announceURL; + char * scrapeURL; tr_errno error; char errorString[128]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 04a0e2e97..de8bda658 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -723,7 +723,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * - (NSString *) trackerAddressAnnounce { - return fStat->tracker->announce ? [NSString stringWithUTF8String: fStat->tracker->announce] : nil; + return fStat->announceURL ? [NSString stringWithUTF8String: fStat->announceURL] : nil; } - (NSDate *) lastAnnounceTime @@ -749,7 +749,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * - (NSString *) trackerAddressScrape { - return fStat->tracker->scrape ? [NSString stringWithUTF8String: fStat->tracker->scrape] : nil; + return fStat->scrapeURL ? [NSString stringWithUTF8String: fStat->scrapeURL] : nil; } - (NSDate *) lastScrapeTime