Changeset 3578
- Timestamp:
- Oct 26, 2007, 3:43:27 AM (15 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/daemon/client.c
r3175 r3578 492 492 493 493 req->str = dircpy; 494 495 return 0; 496 } 497 498 int 499 client_crypto( const char * mode ) 500 { 501 struct req * req; 502 char * modecpy; 503 504 modecpy = strdup( mode ); 505 if( NULL == modecpy ) 506 { 507 mallocmsg( strlen( mode ) ); 508 return -1; 509 } 510 511 req = addreq( IPC_MSG_CRYPTO, -1, NULL ); 512 if( NULL == req ) 513 { 514 free( modecpy ); 515 return -1; 516 } 517 518 req->str = modecpy; 494 519 495 520 return 0; … … 801 826 buf = ipc_mkint( con->ipc, &buflen, req->id, -1, req->num ); 802 827 break; 828 case IPC_MSG_CRYPTO: 803 829 case IPC_MSG_DIR: 804 830 buf = ipc_mkstr( con->ipc, &buflen, req->id, -1, req->str ); -
trunk/daemon/client.h
r1708 r3578 65 65 int client_uplimit ( int ); 66 66 int client_dir ( const char * ); 67 int client_crypto ( const char * ); 67 68 int client_start ( size_t, const int * ); 68 69 int client_stop ( size_t, const int * ); -
trunk/daemon/remote.c
r3401 r3578 73 73 char dir[MAXPATHLEN]; 74 74 int pex; 75 const char * crypto; 75 76 }; 76 77 … … 175 176 ( '\0' != o.dir[0] && 0 > client_dir ( o.dir ) ) || 176 177 ( !SLIST_EMPTY( &o.files ) && 0 > client_addfiles ( &o.files ) ) || 178 ( o.crypto && 0 > client_crypto ( o.crypto ) ) || 177 179 ( o.startall && 0 > client_start ( 0, NULL ) ) || 178 180 ( o.stopall && 0 > client_stop ( 0, NULL ) ) || … … 230 232 "\n" 231 233 " -a --add <torrent> Add a torrent\n" 234 " -c --encryption preferred Prefer peers to use encryption\n" 235 " -c --encryption required Require encryption for all peers\n" 232 236 " -d --download-limit <int> Max download rate in KiB/s\n" 233 237 " -D --download-unlimited No download rate limit\n" … … 261 265 readargs( int argc, char ** argv, struct opts * opts ) 262 266 { 263 char optstr[] = "a: d:DeEf:hilmMp:qr:s:S:t:u:Ux";267 char optstr[] = "a:c:d:DeEf:hilmMp:qr:s:S:t:u:Ux"; 264 268 struct option longopts[] = 265 269 { 266 270 { "add", required_argument, NULL, 'a' }, 271 { "encryption", required_argument, NULL, 'c' }, 267 272 { "download-limit", required_argument, NULL, 'd' }, 268 273 { "download-unlimited", no_argument, NULL, 'D' }, … … 307 312 return -1; 308 313 } 314 break; 315 case 'c': 316 if(!strcasecmp(optarg, "preferred")) 317 opts->crypto = "preferred"; 318 else if(!strcasecmp(optarg, "required")) 319 opts->crypto = "required"; 320 else 321 usage("invalid encryption mode: %s", optarg); 309 322 break; 310 323 case 'd': -
trunk/daemon/server.c
r3577 r3578 105 105 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOMAP, intmsg ) || 106 106 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOSTART, intmsg ) || 107 0 > ipc_addmsg( gl_tree, IPC_MSG_CRYPTO, strmsg ) || 107 108 0 > ipc_addmsg( gl_tree, IPC_MSG_DOWNLIMIT, intmsg ) || 108 109 0 > ipc_addmsg( gl_tree, IPC_MSG_DIR, strmsg ) || 109 110 0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOMAP, prefmsg ) || 110 111 0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOSTART, prefmsg ) || 112 0 > ipc_addmsg( gl_tree, IPC_MSG_GETCRYPTO, prefmsg ) || 111 113 0 > ipc_addmsg( gl_tree, IPC_MSG_GETDOWNLIMIT, prefmsg ) || 112 114 0 > ipc_addmsg( gl_tree, IPC_MSG_GETDIR, prefmsg ) || … … 636 638 switch( id ) 637 639 { 640 case IPC_MSG_CRYPTO: 641 if(!strcasecmp(val->val.s.s, "preferred")) 642 torrent_set_encryption(TR_ENCRYPTION_PREFERRED); 643 else if(!strcasecmp(val->val.s.s, "required")) 644 torrent_set_encryption(TR_ENCRYPTION_REQUIRED); 645 else 646 { 647 msgresp(client, tag, IPC_MSG_BAD); 648 return; 649 } 650 break; 638 651 case IPC_MSG_DIR: 639 652 torrent_set_directory( val->val.s.s ); … … 903 916 uint8_t * buf; 904 917 size_t buflen; 918 const char * strval; 905 919 906 920 switch( id ) … … 913 927 buf = ipc_mkint( client->ipc, &buflen, IPC_MSG_AUTOSTART, tag, 914 928 torrent_get_autostart() ); 929 break; 930 case IPC_MSG_GETCRYPTO: 931 switch(torrent_get_encryption()) 932 { 933 case TR_ENCRYPTION_PREFERRED: 934 strval = "preferred"; 935 break; 936 case TR_ENCRYPTION_REQUIRED: 937 strval = "required"; 938 break; 939 default: 940 assert(0); 941 return; 942 } 943 buf = ipc_mkstr(client->ipc, &buflen, IPC_MSG_CRYPTO, tag, strval); 915 944 break; 916 945 case IPC_MSG_GETDIR: -
trunk/daemon/torrents.c
r3576 r3578 98 98 static int gl_downlimit = -1; 99 99 static char gl_dir[MAXPATHLEN]; 100 static tr_encryption_mode gl_crypto = TR_ENCRYPTION_PREFERRED; 100 101 101 102 RB_GENERATE_STATIC( tortree, tor, idlinks, toridcmp ) … … 466 467 { 467 468 return gl_dir; 469 } 470 471 void 472 torrent_set_encryption(tr_encryption_mode mode) 473 { 474 tr_setEncryptionMode(gl_handle, mode); 475 gl_crypto = mode; 476 savestate(); 477 } 478 479 tr_encryption_mode 480 torrent_get_encryption(void) 481 { 482 return tr_getEncryptionMode(gl_handle); 468 483 } 469 484 … … 738 753 } 739 754 755 str = tr_bencDictFind( &top, "encryption-mode" ); 756 if( NULL != str && TYPE_STR == str->type ) 757 { 758 if(!strcasecmp(str->val.s.s, "preferred")) 759 gl_crypto = TR_ENCRYPTION_PREFERRED; 760 else if(!strcasecmp(str->val.s.s, "required")) 761 gl_crypto = TR_ENCRYPTION_REQUIRED; 762 } 763 764 tr_setEncryptionMode(gl_handle, gl_crypto); 765 740 766 list = tr_bencDictFind( &top, "torrents" ); 741 767 if( NULL == list || TYPE_LIST != list->type ) … … 795 821 796 822 tr_bencInit( &top, TYPE_DICT ); 797 if( tr_bencDictReserve( &top, 8) )823 if( tr_bencDictReserve( &top, 9 ) ) 798 824 { 799 825 nomem: … … 810 836 tr_bencInitStr( tr_bencDictAdd( &top, "default-directory" ), 811 837 gl_dir, -1, 1 ); 838 if(TR_ENCRYPTION_REQUIRED == gl_crypto) 839 tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "required", -1, 1); 840 else 841 tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "preferred", -1, 1); 812 842 list = tr_bencDictAdd( &top, "torrents" ); 813 843 tr_bencInit( list, TYPE_LIST ); -
trunk/daemon/torrents.h
r3111 r3578 58 58 void torrent_set_directory ( const char * ); 59 59 const char * torrent_get_directory ( void ); 60 void torrent_set_encryption ( tr_encryption_mode ); 61 tr_encryption_mode torrent_get_encryption ( void ); 60 62 61 63 #endif /* TR_DAEMON_TORRENTS_H */ -
trunk/doc/ipcproto.txt
r3403 r3578 192 192 Negative values are interpreted as no limit. 193 193 194 Key: "encryption" 195 Version: 2 196 Format: string 197 Replies: "succeeded", "failed", "not-supported", "bad-format" 198 Example: 10:encryption8:required 199 "encryption", "required" 200 Details: Set the encryption mode for peer connections. Valid values 201 are "required" and "preferred". 202 194 203 Key: "failed" 195 204 Version: 2 … … 231 240 "get-downlimit", "" 232 241 Details: Requests that a "downlimit" message be sent back. 242 243 Key: "get-encryption" 244 Version: 2 245 Format: value is ignored 246 Replies: "failed", "not-supported", "bad-format", "encryption" 247 Example: 14:get-encryption0: 248 "get-encryption", "" 249 Details: Requests that an "encryption" message be sent back. 233 250 234 251 Key: "get-info" -
trunk/libtransmission/ipcparse.c
r3486 r3578 141 141 { "autostart", 2, IPC_MSG_AUTOSTART, RB_ENTRY_INITIALIZER() }, 142 142 { "bad-format", 2, IPC_MSG_BAD, RB_ENTRY_INITIALIZER() }, 143 { "encryption", 2, IPC_MSG_CRYPTO, RB_ENTRY_INITIALIZER() }, 143 144 { "directory", 2, IPC_MSG_DIR, RB_ENTRY_INITIALIZER() }, 144 145 { "downlimit", 2, IPC_MSG_DOWNLIMIT, RB_ENTRY_INITIALIZER() }, … … 146 147 { "get-automap", 2, IPC_MSG_GETAUTOMAP, RB_ENTRY_INITIALIZER() }, 147 148 { "get-autostart", 2, IPC_MSG_GETAUTOSTART, RB_ENTRY_INITIALIZER() }, 149 { "get-encryption", 2, IPC_MSG_GETCRYPTO, RB_ENTRY_INITIALIZER() }, 148 150 { "get-directory", 2, IPC_MSG_GETDIR, RB_ENTRY_INITIALIZER() }, 149 151 { "get-downlimit", 2, IPC_MSG_GETDOWNLIMIT, RB_ENTRY_INITIALIZER() }, -
trunk/libtransmission/ipcparse.h
r3565 r3578 43 43 IPC_MSG_AUTOSTART, 44 44 IPC_MSG_BAD, 45 IPC_MSG_CRYPTO, 45 46 IPC_MSG_DIR, 46 47 IPC_MSG_DOWNLIMIT, … … 48 49 IPC_MSG_GETAUTOMAP, 49 50 IPC_MSG_GETAUTOSTART, 51 IPC_MSG_GETCRYPTO, 50 52 IPC_MSG_GETDIR, 51 53 IPC_MSG_GETDOWNLIMIT,
Note: See TracChangeset
for help on using the changeset viewer.