mirror of
https://github.com/transmission/transmission.git
synced 2025-12-24 20:35:36 +00:00
Add IPC messages to set and retrieve the encryption mode.
Implement encryption mode messages in -daemon and -remote.
This commit is contained in:
@@ -495,6 +495,31 @@ client_dir( const char * dir )
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
client_crypto( const char * mode )
|
||||
{
|
||||
struct req * req;
|
||||
char * modecpy;
|
||||
|
||||
modecpy = strdup( mode );
|
||||
if( NULL == modecpy )
|
||||
{
|
||||
mallocmsg( strlen( mode ) );
|
||||
return -1;
|
||||
}
|
||||
|
||||
req = addreq( IPC_MSG_CRYPTO, -1, NULL );
|
||||
if( NULL == req )
|
||||
{
|
||||
free( modecpy );
|
||||
return -1;
|
||||
}
|
||||
|
||||
req->str = modecpy;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
addintlistreq( enum ipc_msg which, size_t len, const int * list )
|
||||
{
|
||||
@@ -800,6 +825,7 @@ flushreqs( struct con * con )
|
||||
case IPC_MSG_PEX:
|
||||
buf = ipc_mkint( con->ipc, &buflen, req->id, -1, req->num );
|
||||
break;
|
||||
case IPC_MSG_CRYPTO:
|
||||
case IPC_MSG_DIR:
|
||||
buf = ipc_mkstr( con->ipc, &buflen, req->id, -1, req->str );
|
||||
SAFEFREE( req->str );
|
||||
|
||||
@@ -64,6 +64,7 @@ int client_pex ( int );
|
||||
int client_downlimit( int );
|
||||
int client_uplimit ( int );
|
||||
int client_dir ( const char * );
|
||||
int client_crypto ( const char * );
|
||||
int client_start ( size_t, const int * );
|
||||
int client_stop ( size_t, const int * );
|
||||
int client_remove ( size_t, const int * );
|
||||
|
||||
@@ -72,6 +72,7 @@ struct opts
|
||||
struct strlist remove;
|
||||
char dir[MAXPATHLEN];
|
||||
int pex;
|
||||
const char * crypto;
|
||||
};
|
||||
|
||||
struct torinfo
|
||||
@@ -174,6 +175,7 @@ main( int argc, char ** argv )
|
||||
if( ( o.sendquit && 0 > client_quit ( ) ) ||
|
||||
( '\0' != o.dir[0] && 0 > client_dir ( o.dir ) ) ||
|
||||
( !SLIST_EMPTY( &o.files ) && 0 > client_addfiles ( &o.files ) ) ||
|
||||
( o.crypto && 0 > client_crypto ( o.crypto ) ) ||
|
||||
( o.startall && 0 > client_start ( 0, NULL ) ) ||
|
||||
( o.stopall && 0 > client_stop ( 0, NULL ) ) ||
|
||||
( o.removeall && 0 > client_remove ( 0, NULL ) ) ||
|
||||
@@ -229,6 +231,8 @@ usage( const char * msg, ... )
|
||||
"A fast and easy BitTorrent client\n"
|
||||
"\n"
|
||||
" -a --add <torrent> Add a torrent\n"
|
||||
" -c --encryption preferred Prefer peers to use encryption\n"
|
||||
" -c --encryption required Require encryption for all peers\n"
|
||||
" -d --download-limit <int> Max download rate in KiB/s\n"
|
||||
" -D --download-unlimited No download rate limit\n"
|
||||
" -e --enable-pex Enable peer exchange\n"
|
||||
@@ -260,10 +264,11 @@ usage( const char * msg, ... )
|
||||
int
|
||||
readargs( int argc, char ** argv, struct opts * opts )
|
||||
{
|
||||
char optstr[] = "a:d:DeEf:hilmMp:qr:s:S:t:u:Ux";
|
||||
char optstr[] = "a:c:d:DeEf:hilmMp:qr:s:S:t:u:Ux";
|
||||
struct option longopts[] =
|
||||
{
|
||||
{ "add", required_argument, NULL, 'a' },
|
||||
{ "encryption", required_argument, NULL, 'c' },
|
||||
{ "download-limit", required_argument, NULL, 'd' },
|
||||
{ "download-unlimited", no_argument, NULL, 'D' },
|
||||
{ "enable-pex", no_argument, NULL, 'e' },
|
||||
@@ -307,6 +312,14 @@ readargs( int argc, char ** argv, struct opts * opts )
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 'c':
|
||||
if(!strcasecmp(optarg, "preferred"))
|
||||
opts->crypto = "preferred";
|
||||
else if(!strcasecmp(optarg, "required"))
|
||||
opts->crypto = "required";
|
||||
else
|
||||
usage("invalid encryption mode: %s", optarg);
|
||||
break;
|
||||
case 'd':
|
||||
opts->downlimit = 1;
|
||||
opts->down = numarg( optarg );
|
||||
|
||||
@@ -104,10 +104,12 @@ server_init( struct event_base * base )
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_ADDONEFILE, addmsg2 ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOMAP, intmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOSTART, intmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_CRYPTO, strmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_DOWNLIMIT, intmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_DIR, strmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOMAP, prefmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOSTART, prefmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETCRYPTO, prefmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETDOWNLIMIT, prefmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETDIR, prefmsg ) ||
|
||||
0 > ipc_addmsg( gl_tree, IPC_MSG_GETINFO, infomsg ) ||
|
||||
@@ -635,6 +637,17 @@ strmsg( enum ipc_msg id, benc_val_t * val, int64_t tag, void * arg )
|
||||
|
||||
switch( id )
|
||||
{
|
||||
case IPC_MSG_CRYPTO:
|
||||
if(!strcasecmp(val->val.s.s, "preferred"))
|
||||
torrent_set_encryption(TR_ENCRYPTION_PREFERRED);
|
||||
else if(!strcasecmp(val->val.s.s, "required"))
|
||||
torrent_set_encryption(TR_ENCRYPTION_REQUIRED);
|
||||
else
|
||||
{
|
||||
msgresp(client, tag, IPC_MSG_BAD);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case IPC_MSG_DIR:
|
||||
torrent_set_directory( val->val.s.s );
|
||||
break;
|
||||
@@ -902,6 +915,7 @@ prefmsg( enum ipc_msg id, benc_val_t * val UNUSED, int64_t tag, void * arg )
|
||||
struct client * client = arg;
|
||||
uint8_t * buf;
|
||||
size_t buflen;
|
||||
const char * strval;
|
||||
|
||||
switch( id )
|
||||
{
|
||||
@@ -913,6 +927,21 @@ prefmsg( enum ipc_msg id, benc_val_t * val UNUSED, int64_t tag, void * arg )
|
||||
buf = ipc_mkint( client->ipc, &buflen, IPC_MSG_AUTOSTART, tag,
|
||||
torrent_get_autostart() );
|
||||
break;
|
||||
case IPC_MSG_GETCRYPTO:
|
||||
switch(torrent_get_encryption())
|
||||
{
|
||||
case TR_ENCRYPTION_PREFERRED:
|
||||
strval = "preferred";
|
||||
break;
|
||||
case TR_ENCRYPTION_REQUIRED:
|
||||
strval = "required";
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
buf = ipc_mkstr(client->ipc, &buflen, IPC_MSG_CRYPTO, tag, strval);
|
||||
break;
|
||||
case IPC_MSG_GETDIR:
|
||||
buf = ipc_mkstr( client->ipc, &buflen, IPC_MSG_DIR, tag,
|
||||
torrent_get_directory() );
|
||||
|
||||
@@ -97,6 +97,7 @@ static int gl_mapping = 0;
|
||||
static int gl_uplimit = -1;
|
||||
static int gl_downlimit = -1;
|
||||
static char gl_dir[MAXPATHLEN];
|
||||
static tr_encryption_mode gl_crypto = TR_ENCRYPTION_PREFERRED;
|
||||
|
||||
RB_GENERATE_STATIC( tortree, tor, idlinks, toridcmp )
|
||||
RB_GENERATE_STATIC( hashtree, tor, hashlinks, torhashcmp )
|
||||
@@ -467,6 +468,20 @@ torrent_get_directory( void )
|
||||
return gl_dir;
|
||||
}
|
||||
|
||||
void
|
||||
torrent_set_encryption(tr_encryption_mode mode)
|
||||
{
|
||||
tr_setEncryptionMode(gl_handle, mode);
|
||||
gl_crypto = mode;
|
||||
savestate();
|
||||
}
|
||||
|
||||
tr_encryption_mode
|
||||
torrent_get_encryption(void)
|
||||
{
|
||||
return tr_getEncryptionMode(gl_handle);
|
||||
}
|
||||
|
||||
struct tor *
|
||||
opentor( const char * path, const char * hash, uint8_t * data, size_t size,
|
||||
const char * dir )
|
||||
@@ -737,6 +752,17 @@ loadstate( void )
|
||||
strlcpy( gl_dir, str->val.s.s, sizeof gl_dir );
|
||||
}
|
||||
|
||||
str = tr_bencDictFind( &top, "encryption-mode" );
|
||||
if( NULL != str && TYPE_STR == str->type )
|
||||
{
|
||||
if(!strcasecmp(str->val.s.s, "preferred"))
|
||||
gl_crypto = TR_ENCRYPTION_PREFERRED;
|
||||
else if(!strcasecmp(str->val.s.s, "required"))
|
||||
gl_crypto = TR_ENCRYPTION_REQUIRED;
|
||||
}
|
||||
|
||||
tr_setEncryptionMode(gl_handle, gl_crypto);
|
||||
|
||||
list = tr_bencDictFind( &top, "torrents" );
|
||||
if( NULL == list || TYPE_LIST != list->type )
|
||||
{
|
||||
@@ -794,7 +820,7 @@ savestate( void )
|
||||
int len, pexset;
|
||||
|
||||
tr_bencInit( &top, TYPE_DICT );
|
||||
if( tr_bencDictReserve( &top, 8 ) )
|
||||
if( tr_bencDictReserve( &top, 9 ) )
|
||||
{
|
||||
nomem:
|
||||
tr_bencFree( &top );
|
||||
@@ -809,6 +835,10 @@ savestate( void )
|
||||
tr_bencInitInt( tr_bencDictAdd( &top, "download-limit" ), gl_downlimit );
|
||||
tr_bencInitStr( tr_bencDictAdd( &top, "default-directory" ),
|
||||
gl_dir, -1, 1 );
|
||||
if(TR_ENCRYPTION_REQUIRED == gl_crypto)
|
||||
tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "required", -1, 1);
|
||||
else
|
||||
tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "preferred", -1, 1);
|
||||
list = tr_bencDictAdd( &top, "torrents" );
|
||||
tr_bencInit( list, TYPE_LIST );
|
||||
|
||||
|
||||
@@ -57,5 +57,7 @@ void torrent_set_downlimit ( int );
|
||||
int torrent_get_downlimit ( void );
|
||||
void torrent_set_directory ( const char * );
|
||||
const char * torrent_get_directory ( void );
|
||||
void torrent_set_encryption ( tr_encryption_mode );
|
||||
tr_encryption_mode torrent_get_encryption ( void );
|
||||
|
||||
#endif /* TR_DAEMON_TORRENTS_H */
|
||||
|
||||
@@ -191,6 +191,15 @@ Example: 9:downlimiti100e
|
||||
Details: Set the server's download limit in kilobytes per second.
|
||||
Negative values are interpreted as no limit.
|
||||
|
||||
Key: "encryption"
|
||||
Version: 2
|
||||
Format: string
|
||||
Replies: "succeeded", "failed", "not-supported", "bad-format"
|
||||
Example: 10:encryption8:required
|
||||
"encryption", "required"
|
||||
Details: Set the encryption mode for peer connections. Valid values
|
||||
are "required" and "preferred".
|
||||
|
||||
Key: "failed"
|
||||
Version: 2
|
||||
Format: string
|
||||
@@ -231,6 +240,14 @@ Example: 13:get-downlimit0:
|
||||
"get-downlimit", ""
|
||||
Details: Requests that a "downlimit" message be sent back.
|
||||
|
||||
Key: "get-encryption"
|
||||
Version: 2
|
||||
Format: value is ignored
|
||||
Replies: "failed", "not-supported", "bad-format", "encryption"
|
||||
Example: 14:get-encryption0:
|
||||
"get-encryption", ""
|
||||
Details: Requests that an "encryption" message be sent back.
|
||||
|
||||
Key: "get-info"
|
||||
Version: 2
|
||||
Format: dict with keys "id" and "type" for lists of ints and strings
|
||||
|
||||
@@ -140,11 +140,13 @@ static struct msg gl_msgs[] =
|
||||
{ "automap", 2, IPC_MSG_AUTOMAP, RB_ENTRY_INITIALIZER() },
|
||||
{ "autostart", 2, IPC_MSG_AUTOSTART, RB_ENTRY_INITIALIZER() },
|
||||
{ "bad-format", 2, IPC_MSG_BAD, RB_ENTRY_INITIALIZER() },
|
||||
{ "encryption", 2, IPC_MSG_CRYPTO, RB_ENTRY_INITIALIZER() },
|
||||
{ "directory", 2, IPC_MSG_DIR, RB_ENTRY_INITIALIZER() },
|
||||
{ "downlimit", 2, IPC_MSG_DOWNLIMIT, RB_ENTRY_INITIALIZER() },
|
||||
{ "failed", 2, IPC_MSG_FAIL, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-automap", 2, IPC_MSG_GETAUTOMAP, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-autostart", 2, IPC_MSG_GETAUTOSTART, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-encryption", 2, IPC_MSG_GETCRYPTO, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-directory", 2, IPC_MSG_GETDIR, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-downlimit", 2, IPC_MSG_GETDOWNLIMIT, RB_ENTRY_INITIALIZER() },
|
||||
{ "get-info", 2, IPC_MSG_GETINFO, RB_ENTRY_INITIALIZER() },
|
||||
|
||||
@@ -42,11 +42,13 @@ enum ipc_msg
|
||||
IPC_MSG_AUTOMAP,
|
||||
IPC_MSG_AUTOSTART,
|
||||
IPC_MSG_BAD,
|
||||
IPC_MSG_CRYPTO,
|
||||
IPC_MSG_DIR,
|
||||
IPC_MSG_DOWNLIMIT,
|
||||
IPC_MSG_FAIL,
|
||||
IPC_MSG_GETAUTOMAP,
|
||||
IPC_MSG_GETAUTOSTART,
|
||||
IPC_MSG_GETCRYPTO,
|
||||
IPC_MSG_GETDIR,
|
||||
IPC_MSG_GETDOWNLIMIT,
|
||||
IPC_MSG_GETINFO,
|
||||
|
||||
Reference in New Issue
Block a user