(trunk rpc) add the ability to set file priorities and download flags when adding a new torrent via rpc

This commit is contained in:
Charles Kerr
2009-04-02 20:43:42 +00:00
parent c3b24bc471
commit b6daa50ecf
6 changed files with 169 additions and 9 deletions
+10
View File
@@ -321,6 +321,11 @@
"metainfo" | string base64-encoded .torrent content
"paused" | 'boolean' if true, don't start the torrent
"peer-limit" | number maximum number of peers
"files-wanted" | array indices of file(s) to download
"files-unwanted" | array indices of file(s) to not download
"priority-high" | array indices of high-priority file(s)
"priority-low" | array indices of low-priority file(s)
"priority-normal" | array indices of normal-priority file(s)
Either "filename" OR "metainfo" MUST be included.
All other arguments are optional.
@@ -454,6 +459,11 @@
| | yes | torrent-set | new arg "downloadLimited"
| | yes | torrent-set | new arg "uploadLimited"
| | yes | torrent-set | new arg "honorsSessionLimits"
| | yes | torrent-add | new arg "files-wanted"
| | yes | torrent-add | new arg "files-unwanted"
| | yes | torrent-add | new arg "priority-high"
| | yes | torrent-add | new arg "priority-low"
| | yes | torrent-add | new arg "priority-normal"
| | yes | session-get | new arg "seedRatioLimit"
| | yes | session-get | new arg "seedRatioLimited"
| | yes | session-get | new arg "alt-speed-enabled"
+54
View File
@@ -818,6 +818,24 @@ isCurlURL( const char * filename )
|| ( strstr( filename, "https://" ) != NULL );
}
static tr_file_index_t*
fileListFromList( tr_benc * list, tr_file_index_t * setmeCount )
{
size_t i;
const size_t childCount = tr_bencListSize( list );
tr_file_index_t n = 0;
tr_file_index_t * files = tr_new0( tr_file_index_t, childCount );
for( i=0; i<childCount; ++i ) {
int64_t intVal;
if( tr_bencGetInt( tr_bencListChild( list, i ), &intVal ) )
files[n++] = (tr_file_index_t)intVal;
}
*setmeCount = n;
return files;
}
static const char*
torrentAdd( tr_session * session,
tr_benc * args_in,
@@ -838,16 +856,52 @@ torrentAdd( tr_session * session,
int64_t i;
tr_bool boolVal;
const char * str;
tr_benc * l;
tr_ctor * ctor = tr_ctorNew( session );
/* set the optional arguments */
if( tr_bencDictFindStr( args_in, "download-dir", &str ) )
tr_ctorSetDownloadDir( ctor, TR_FORCE, str );
if( tr_bencDictFindBool( args_in, "paused", &boolVal ) )
tr_ctorSetPaused( ctor, TR_FORCE, boolVal );
if( tr_bencDictFindInt( args_in, "peer-limit", &i ) )
tr_ctorSetPeerLimit( ctor, TR_FORCE, i );
if( tr_bencDictFindList( args_in, "files-unwanted", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
tr_ctorSetFilesWanted( ctor, files, fileCount, FALSE );
tr_free( files );
}
if( tr_bencDictFindList( args_in, "files-wanted", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
tr_ctorSetFilesWanted( ctor, files, fileCount, TRUE );
tr_free( files );
}
if( tr_bencDictFindList( args_in, "priority-low", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_LOW );
tr_free( files );
}
if( tr_bencDictFindList( args_in, "priority-normal", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_NORMAL );
tr_free( files );
}
if( tr_bencDictFindList( args_in, "priority-high", &l ) ) {
tr_file_index_t fileCount;
tr_file_index_t * files = fileListFromList( l, &fileCount );
tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_HIGH );
tr_free( files );
}
dbgmsg( "torrentAdd: filename is \"%s\"", filename );
if( isCurlURL( filename ) )
+77 -1
View File
@@ -16,7 +16,7 @@
#include "platform.h"
#include "session.h" /* tr_sessionFindTorrentFile() */
#include "torrent.h" /* tr_ctorGetSave() */
#include "utils.h"
#include "utils.h" /* tr_new0 */
struct optional_args
{
@@ -43,6 +43,17 @@ struct tr_ctor
char * sourceFile;
struct optional_args optionalArgs[2];
tr_file_index_t * want;
tr_file_index_t wantSize;
tr_file_index_t * notWant;
tr_file_index_t notWantSize;
tr_file_index_t * low;
tr_file_index_t lowSize;
tr_file_index_t * normal;
tr_file_index_t normalSize;
tr_file_index_t * high;
tr_file_index_t highSize;
};
/***
@@ -150,6 +161,66 @@ tr_ctorSetMetainfoFromHash( tr_ctor * ctor,
****
***/
void
tr_ctorSetFilePriorities( tr_ctor * ctor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
tr_priority_t priority )
{
tr_file_index_t ** myfiles;
tr_file_index_t * mycount;
switch( priority ) {
case TR_PRI_NORMAL: myfiles = &ctor->normal; mycount = &ctor->normalSize; break;
case TR_PRI_LOW: myfiles = &ctor->low; mycount = &ctor->lowSize; break;
case TR_PRI_HIGH: myfiles = &ctor->high; mycount = &ctor->highSize; break;
}
tr_free( *myfiles );
*myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount );
*mycount = fileCount;
}
void
tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor )
{
tr_file_index_t i;
for( i=0; i<ctor->lowSize; ++i )
tr_torrentInitFilePriority( tor, ctor->low[i], TR_PRI_LOW );
for( i=0; i<ctor->normalSize; ++i )
tr_torrentInitFilePriority( tor, ctor->normal[i], TR_PRI_NORMAL );
for( i=0; i<ctor->highSize; ++i )
tr_torrentInitFilePriority( tor, ctor->high[i], TR_PRI_HIGH );
}
void
tr_ctorSetFilesWanted( tr_ctor * ctor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
tr_bool wanted )
{
tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant;
tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize;
tr_free( *myfiles );
*myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount );
*mycount = fileCount;
}
void
tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor )
{
if( ctor->notWantSize )
tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE );
if( ctor->wantSize )
tr_torrentInitFileDLs( tor, ctor->notWant, ctor->wantSize, TRUE );
}
/***
****
***/
void
tr_ctorSetDeleteSource( tr_ctor * ctor,
tr_bool deleteSource )
@@ -322,5 +393,10 @@ tr_ctorFree( tr_ctor * ctor )
clearMetainfo( ctor );
tr_free( ctor->optionalArgs[1].downloadDir );
tr_free( ctor->optionalArgs[0].downloadDir );
tr_free( ctor->want );
tr_free( ctor->notWant );
tr_free( ctor->low );
tr_free( ctor->high );
tr_free( ctor->normal );
tr_free( ctor );
}
+4
View File
@@ -581,6 +581,10 @@ torrentRealInit( tr_torrent * tor, const tr_ctor * ctor )
assert( !tor->downloadedCur );
assert( !tor->uploadedCur );
tr_ctorInitTorrentPriorities( ctor, tor );
tr_ctorInitTorrentWanted( ctor, tor );
tor->error = 0;
tr_bitfieldConstruct( &tor->checkedPieces, tor->info.pieceCount );
+4
View File
@@ -35,6 +35,10 @@ void tr_ctorSetSave( tr_ctor * ctor,
int tr_ctorGetSave( const tr_ctor * ctor );
void tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor );
void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor );
/**
***
**/
+20 -8
View File
@@ -65,6 +65,15 @@ typedef uint64_t tr_block_index_t;
typedef uint16_t tr_port;
typedef uint8_t tr_bool;
enum
{
TR_PRI_LOW = -1,
TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */
TR_PRI_HIGH = 1
};
typedef int8_t tr_priority_t;
/**
* @brief returns Transmission's default configuration file directory.
*
@@ -792,6 +801,17 @@ void tr_ctorSetPaused( tr_ctor * ctor,
tr_ctorMode mode,
tr_bool isPaused );
void tr_ctorSetFilePriorities( tr_ctor * ctor,
const tr_file_index_t * files,
tr_file_index_t fileCount,
tr_priority_t priority );
void tr_ctorSetFilesWanted( tr_ctor * ctor,
const tr_file_index_t * fileIndices,
tr_file_index_t fileCount,
tr_bool wanted );
int tr_ctorGetPeerLimit( const tr_ctor * ctor,
tr_ctorMode mode,
uint16_t * setmeCount );
@@ -947,14 +967,6 @@ uint16_t tr_torrentGetPeerLimit( const tr_torrent * tor );
***** File Priorities
****/
enum
{
TR_PRI_LOW = -1,
TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */
TR_PRI_HIGH = 1
};
typedef int8_t tr_priority_t;
/**
* @brief Set a batch of files to a particular priority.