1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 16:24:02 +00:00

(daemon) #1420: transmission-remote --peers doesn't work right

This commit is contained in:
Charles Kerr 2008-11-04 17:04:41 +00:00
parent 4ec4c07929
commit b4d5883c17
2 changed files with 46 additions and 29 deletions

View file

@ -442,6 +442,7 @@ readargs( int argc,
case 'z': case 'z':
tr_bencDictAddStr( &top, "method", "torrent-get" ); tr_bencDictAddStr( &top, "method", "torrent-get" );
tr_bencDictAddInt( &top, "tag", TAG_PEERS ); tr_bencDictAddInt( &top, "tag", TAG_PEERS );
addIdArg( args, id );
fields = tr_bencDictAddList( args, "fields", 1 ); fields = tr_bencDictAddList( args, "fields", 1 );
tr_bencListAddStr( fields, "peers" ); tr_bencListAddStr( fields, "peers" );
break; break;
@ -929,32 +930,48 @@ printFileList( tr_benc * top )
} }
static void static void
printPeerList( tr_benc * top ) printPeersImpl( tr_benc * peers )
{ {
tr_benc *args, *list; int i, n;
printf( "%-20s %-12s %-6s %-6s %s\n",
"Address", "Flags", "Down", "Up", "Client" );
for( i = 0, n = tr_bencListSize( peers ); i < n; ++i )
{
const char * address, * client, * flagstr;
int64_t rateToClient, rateToPeer;
tr_benc * d = tr_bencListChild( peers, i );
if( tr_bencDictFindStr( d, "address", &address )
&& tr_bencDictFindStr( d, "clientName", &client )
&& tr_bencDictFindStr( d, "flagStr", &flagstr )
&& tr_bencDictFindInt( d, "rateToClient", &rateToClient )
&& tr_bencDictFindInt( d, "rateToPeer", &rateToPeer ) )
{
printf( "%-20s %-12s %6.1f %6.1f %s\n",
address, flagstr,
rateToClient / 1024.0,
rateToPeer / 1024.0,
client );
}
}
}
if( ( tr_bencDictFindDict( top, "arguments", &args ) ) static void
&& ( tr_bencDictFindList( args, "peers", &list ) ) ) printPeers( tr_benc * top )
{
tr_benc *args, *torrents;
if( tr_bencDictFindDict( top, "arguments", &args )
&& tr_bencDictFindList( args, "torrents", &torrents ) )
{ {
int i, n; int i, n;
printf( "%-20s %-12s %-5s %5s %s\n", for( i=0, n=tr_bencListSize( torrents ); i<n; ++i )
"Address", "Flags", "Down", "Up", "Client" );
for( i = 0, n = tr_bencListSize( list ); i < n; ++i )
{ {
const char * address, * client, * flagstr; tr_benc * peers;
int64_t rateToClient, rateToPeer; tr_benc * torrent = tr_bencListChild( torrents, i );
tr_benc * d = tr_bencListChild( list, i ); if( tr_bencDictFindList( torrent, "peers", &peers ) ) {
if( tr_bencDictFindStr( d, "address", &address ) printPeersImpl( peers );
&& tr_bencDictFindStr( d, "client", &client ) if( i+1<n )
&& tr_bencDictFindStr( d, "flagstr", &flagstr ) printf( "\n" );
&& tr_bencDictFindInt( d, "rateToClient", &rateToClient )
&& tr_bencDictFindInt( d, "rateToPeer", &rateToPeer ) )
{
printf( "%-20s %-12s %5.1f %5.1f %s\n",
address, flagstr,
rateToClient * 1024.0,
rateToPeer * 1024.0,
client );
} }
} }
} }
@ -1046,7 +1063,7 @@ processResponse( const char * host,
printTorrentList( &top ); break; printTorrentList( &top ); break;
case TAG_PEERS: case TAG_PEERS:
printPeerList( &top ); break; printPeers( &top ); break;
default: default:
if( tr_bencDictFindStr( &top, "result", &str ) ) if( tr_bencDictFindStr( &top, "result", &str ) )
@ -1091,7 +1108,7 @@ processRequests( const char * host,
CURLcode res; CURLcode res;
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, reqs[i] ); curl_easy_setopt( curl, CURLOPT_POSTFIELDS, reqs[i] );
if( debug ) if( debug )
tr_ninf( MY_NAME, "posting [%s]\n", reqs[i] ); fprintf( stderr, "posting [%s]\n", reqs[i] );
if( ( res = curl_easy_perform( curl ) ) ) if( ( res = curl_easy_perform( curl ) ) )
tr_nerr( MY_NAME, "(%s:%d) %s", host, port, tr_nerr( MY_NAME, "(%s:%d) %s", host, port,
curl_easy_strerror( res ) ); curl_easy_strerror( res ) );

View file

@ -170,7 +170,7 @@ Enable peer exchange (PEX).
.It Fl X Fl -no-pex .It Fl X Fl -no-pex
Disable peer exchange (PEX). Disable peer exchange (PEX).
.It Fl x Fl -peers .It Fl z Fl -peers
List the current torrent's connected peers. List the current torrent's connected peers.
In the `status' section of the list, the following shorthand is used: In the `status' section of the list, the following shorthand is used:
.D1 D: Downloading from this peer .D1 D: Downloading from this peer
@ -220,27 +220,27 @@ $ transmission-remote -a ~/Desktop/*torrent
Get detailed information on the torrent whose ID is '1': Get detailed information on the torrent whose ID is '1':
.Bd -literal -offset indent .Bd -literal -offset indent
$ transmission-remote -t1 -i" $ transmission-remote -t1 -i
.Ed .Ed
Get a list of a torrent's files: Get a list of a torrent's files:
.Bd -literal -offset indent .Bd -literal -offset indent
$ transmission-remote -t1 -l" $ transmission-remote -t1 -l
.Ed .Ed
Download only its second and fourth files: Download only its second and fourth files:
.Bd -literal -offset indent .Bd -literal -offset indent
$ transmission-remote -t1 -Gall -g2,4" $ transmission-remote -t1 -Gall -g2,4
.Ed .Ed
Set all torrents' first two files' priorities to high: Set all torrents' first two files' priorities to high:
.Bd -literal -offset indent .Bd -literal -offset indent
$ transmission-remote -tall -ph1,2" $ transmission-remote -tall -ph1,2
.Ed .Ed
Set all torrents' files' priorities to normal: Set all torrents' files' priorities to normal:
.Bd -literal -offset indent .Bd -literal -offset indent
$ transmission-remote -tall -pnall" $ transmission-remote -tall -pnall
.Ed .Ed
.Sh AUTHORS .Sh AUTHORS