Changeset 1631
- Timestamp:
- Apr 1, 2007, 7:35:28 AM (16 years ago)
- Location:
- branches/daemon/daemon
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/daemon/daemon/client.c
r1626 r1631 331 331 struct req * req; 332 332 333 req = addreq( IPC_MSG_ADD FILES, -1, NULL );333 req = addreq( IPC_MSG_ADDMANYFILES, -1, NULL ); 334 334 if( NULL == req ) 335 335 { … … 696 696 buf = ipc_mkempty( &con->ipc, &buflen, req->id, req->tag ); 697 697 break; 698 case IPC_MSG_ADD FILES:698 case IPC_MSG_ADDMANYFILES: 699 699 buf = ipc_mkstrlist( &con->ipc, &buflen, req->id, -1, 700 700 req->strs ); -
branches/daemon/daemon/ipc.c
r1617 r1631 78 78 static struct msg gl_msgs[] = 79 79 { 80 { "addfiles", 1, IPC_MSG_ADDFILES, RB_ENTRY_INITIALIZER() }, 80 { "addfiles", 1, IPC_MSG_ADDMANYFILES, RB_ENTRY_INITIALIZER() }, 81 { "addfile-detailed", 2, IPC_MSG_ADDONEFILE, RB_ENTRY_INITIALIZER() }, 81 82 { "automap", 2, IPC_MSG_AUTOMAP, RB_ENTRY_INITIALIZER() }, 82 83 { "autostart", 2, IPC_MSG_AUTOSTART, RB_ENTRY_INITIALIZER() }, … … 90 91 { "get-info", 2, IPC_MSG_GETINFO, RB_ENTRY_INITIALIZER() }, 91 92 { "get-info-all", 2, IPC_MSG_GETINFOALL, RB_ENTRY_INITIALIZER() }, 93 { "get-pex", 2, IPC_MSG_GETPEX, RB_ENTRY_INITIALIZER() }, 92 94 { "get-port", 2, IPC_MSG_GETPORT, RB_ENTRY_INITIALIZER() }, 93 95 { "get-status", 2, IPC_MSG_GETSTAT, RB_ENTRY_INITIALIZER() }, … … 99 101 { "noop", 2, IPC_MSG_NOOP, RB_ENTRY_INITIALIZER() }, 100 102 { "not-supported", 2, IPC_MSG_NOTSUP, RB_ENTRY_INITIALIZER() }, 103 { "pex", 2, IPC_MSG_PORT, RB_ENTRY_INITIALIZER() }, 101 104 { "port", 2, IPC_MSG_PORT, RB_ENTRY_INITIALIZER() }, 102 105 { "quit", 1, IPC_MSG_QUIT, RB_ENTRY_INITIALIZER() }, -
branches/daemon/daemon/ipc.h
r1621 r1631 38 38 enum ipc_msg 39 39 { 40 IPC_MSG_ADDFILES = 0, 40 IPC_MSG_ADDMANYFILES = 0, 41 IPC_MSG_ADDONEFILE, 41 42 IPC_MSG_AUTOMAP, 42 43 IPC_MSG_AUTOSTART, … … 50 51 IPC_MSG_GETINFO, 51 52 IPC_MSG_GETINFOALL, 53 IPC_MSG_GETPEX, 52 54 IPC_MSG_GETPORT, 53 55 IPC_MSG_GETSTAT, … … 59 61 IPC_MSG_NOOP, 60 62 IPC_MSG_NOTSUP, 63 IPC_MSG_PEX, 61 64 IPC_MSG_PORT, 62 65 IPC_MSG_QUIT, -
branches/daemon/daemon/ipcproto.txt
r1617 r1631 83 83 understand. 84 84 85 If a reference to a boolean is seen, it should be taken to mean an 86 integer with a value of 0 representing false, 1 representing true, and 87 any other value undefined. 88 89 Individual torrents are identified by a unique integer. This integer 90 is only valid for the current connection and may be invalid or refer 91 to another torrent in a future connection. If a torrent is closed it's 92 ID will never be reused to refer to another torrent for at least the 93 duration of the connection. Negative integers or 0 are not valid IDs. 94 85 95 A list of keys and the format of their values follows. Also listed is 86 96 the minimum protocol version that the key may be used with. … … 91 101 Format: list of strings 92 102 Example: 8:addfilesl21:/torrents/foo.torrent20:/home/me/bar.torrente 93 Details: Each string is the absolute path to a torrent file for the 94 server to add. Note that whether or not the torrent file is 95 copied (allowing the original to be moved or deleted safely) 96 is implementation dependent and may not currently be known or 97 changed with this protocol. 103 Details: Each string is the absolute path to a torrent metainfo file 104 for the server to add. Note that whether or not the torrent 105 metainfo file is copied (allowing the original to be moved or 106 deleted safely) is implementation dependent and may not 107 currently be known or changed with this protocol. 108 109 Key: "addfile-detailed" 110 Version: 2 111 Format: dict 112 Example: 16:addfile-detailedde 113 Details: Dictionary containing information about a torrent for the 114 server to add. Valid keys include: 115 "file" string, filename of torrent metainfo file 116 "data" string, contents of a torrent metainfo file 117 "directory" string, directory for data files for the torrent 118 "autostart" boolean, start the torrent automatically 119 Either "file" or "data" is required, but both are not allowed. 98 120 99 121 Key: "automap" 100 122 Version: 2 101 Format: int, 0 or 1123 Format: boolean 102 124 Example: 7:automapi1e 103 125 Details: Enable (1) or disable (0) automatic port mapping on the … … 107 129 Key: "autostart" 108 130 Version: 2 109 Format: int, 0 or 1131 Format: boolean 110 132 Example: 9:autostarti0e 111 133 Details: Enable (1) or disable (0) automatic starting of new torrents … … 173 195 Details: Same as "getinfo" message with all torrent IDs specified. 174 196 197 Key: "get-pex" 198 Version: 2 199 Format: value is ignored 200 Example: 7:get-pex0: 201 Details: Requests that a "pex" message be sent back. 202 175 203 Key: "get-port" 176 204 Version: 2 … … 234 262 Details: Sent in response to a tagged message to indicated that the 235 263 message was not supported. 264 265 Key: "pex" 266 Version: 2 267 Format: boolean 268 Example: 3:pexi0e 269 Details: Enables or disables peer exchange. 236 270 237 271 Key: "port" … … 315 349 Negative values are interpreted as no limit. 316 350 317 Key: "version"318 Version: 1319 Format: dict containing int "min" and "max"320 Example: 7:versiond3:mini1e3:maxi2ee321 Details: Described above.322 323 324 Individual torrents are identified by a unique integer. This integer325 is only valid for the current connection and may be invalid or refer326 to another torrent in a future connection. If a torrent is closed it's327 ID will never be reused to refer to another torrent for at least the328 duration of the connection. Negative integers or 0 are not valid IDs.329 330 351 331 352 Info types for "get-info" and "info" messages. The only type for which … … 336 357 "name" string, torrent name 337 358 "path" string, path to .torrent file 338 "saved" integer, 1 if a copy of this torrent was saved, 0 otherwise339 "private" integer, 1 if the torrent is private, 0 otherwise359 "saved" boolean, true if a copy of this torrent was saved 360 "private" boolean, true if the torrent is private 340 361 "trackers" a list of lists of dictionaries containing tracker info: 341 362 "address" string, hostname or ip address of tracker … … 378 399 "peers-total" integer, total connected peers 379 400 "peers-uploading" integer, peers uploading to us 380 "running" integer, 0 if torrent is stopped or stopping, 1 otherwise401 "running" boolean, false if torrent is stopped or stopping 381 402 "state" string, one of the following: 382 403 "checking" performing hash check on file data -
branches/daemon/daemon/remote.c
r1627 r1631 66 66 struct strlist remove; 67 67 char dir[MAXPATHLEN]; 68 int pex; 68 69 }; 69 70 -
branches/daemon/daemon/server.c
r1621 r1631 66 66 static void defmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); 67 67 static void noopmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); 68 static void addmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); 68 static void addmsg1 ( enum ipc_msg, benc_val_t *, int64_t, void * ); 69 static void addmsg2 ( enum ipc_msg, benc_val_t *, int64_t, void * ); 69 70 static void quitmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); 70 71 static void intmsg ( enum ipc_msg, benc_val_t *, int64_t, void * ); … … 98 99 } 99 100 100 if( 0 > ipc_addmsg( gl_tree, IPC_MSG_ADDFILES, addmsg ) || 101 if( 0 > ipc_addmsg( gl_tree, IPC_MSG_ADDMANYFILES, addmsg1 ) || 102 0 > ipc_addmsg( gl_tree, IPC_MSG_ADDONEFILE, addmsg2 ) || 101 103 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOMAP, intmsg ) || 102 104 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOSTART, intmsg ) || … … 109 111 0 > ipc_addmsg( gl_tree, IPC_MSG_GETINFO, infomsg ) || 110 112 0 > ipc_addmsg( gl_tree, IPC_MSG_GETINFOALL, infomsg ) || 113 0 > ipc_addmsg( gl_tree, IPC_MSG_GETPEX, prefmsg ) || 111 114 0 > ipc_addmsg( gl_tree, IPC_MSG_GETPORT, prefmsg ) || 112 115 0 > ipc_addmsg( gl_tree, IPC_MSG_GETSTAT, infomsg ) || … … 116 119 0 > ipc_addmsg( gl_tree, IPC_MSG_LOOKUP, lookmsg ) || 117 120 0 > ipc_addmsg( gl_tree, IPC_MSG_NOOP, noopmsg ) || 121 0 > ipc_addmsg( gl_tree, IPC_MSG_PEX, intmsg ) || 118 122 0 > ipc_addmsg( gl_tree, IPC_MSG_PORT, intmsg ) || 119 123 0 > ipc_addmsg( gl_tree, IPC_MSG_QUIT, quitmsg ) || … … 390 394 391 395 void 392 addmsg( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg ) 393 { 394 struct client * client = arg; 395 benc_val_t * file; 396 int64_t * added, tor; 397 int ii; 398 size_t count, buflen; 396 addmsg1( enum ipc_msg id UNUSED, benc_val_t * val, int64_t tag, void * arg ) 397 { 398 struct client * client = arg; 399 benc_val_t pk, * added, * file; 400 int ii, tor; 401 size_t buflen; 399 402 uint8_t * buf; 403 tr_info_t * inf; 400 404 401 405 if( NULL == val || TYPE_LIST != val->type ) … … 405 409 } 406 410 407 if( 0 < tag ) 408 { 409 added = calloc( val->val.l.count, sizeof( added[0] ) ); 410 if( NULL == added ) 411 { 412 mallocmsg( val->val.l.count * sizeof( added[0] ) ); 413 byebye( client->ev, EVBUFFER_EOF, NULL ); 414 return; 415 } 416 count = 0; 411 if( 0 > ipc_initinfo( &client->ipc, IPC_MSG_INFO, tag, &pk, &added ) ) 412 { 413 errnomsg( "failed to build message" ); 414 byebye( client->ev, EVBUFFER_EOF, NULL ); 415 return; 417 416 } 418 417 … … 425 424 } 426 425 /* XXX need to somehow inform client of skipped or failed files */ 427 tor = torrent_add( file->val.s.s ); 428 if( 0 < tag ) 429 { 430 added[count] = tor; 431 count++; 432 } 433 } 434 435 if( 0 < tag ) 436 { 437 buf = ipc_mkints( &client->ipc, &buflen, tag, IPC_MSG_INFO, 438 count, added ); 426 tor = torrent_add( file->val.s.s, NULL, -1 ); 427 if( TORRENT_ID_VALID( tor ) ) 428 { 429 inf = torrent_info( tor ); 430 if( 0 > ipc_addinfo( added, tor, inf, 0 ) ) 431 { 432 errnomsg( "failed to build message" ); 433 tr_bencFree( &pk ); 434 byebye( client->ev, EVBUFFER_EOF, NULL ); 435 return; 436 } 437 } 438 } 439 440 buf = ipc_mkinfo( &pk, &buflen ); 441 tr_bencFree( &pk ); 442 queuemsg( client, buf, buflen ); 443 free( buf ); 444 } 445 446 void 447 addmsg2( enum ipc_msg id UNUSED, benc_val_t * dict, int64_t tag, void * arg ) 448 { 449 struct client * client = arg; 450 benc_val_t * val, pk; 451 int tor, start; 452 size_t buflen; 453 uint8_t * buf; 454 const char * dir; 455 tr_info_t * inf; 456 457 if( NULL == dict || TYPE_DICT != dict->type ) 458 { 459 msgresp( client, tag, IPC_MSG_NOTSUP ); 460 return; 461 } 462 463 val = tr_bencDictFind( dict, "directory" ); 464 dir = ( NULL == val || TYPE_STR != val->type ? NULL : val->val.s.s ); 465 val = tr_bencDictFind( dict, "autostart" ); 466 start = ( NULL == val || TYPE_INT != val->type ? -1 : 467 ( val->val.i ? 1 : 0 ) ); 468 val = tr_bencDictFind( dict, "data" ); 469 if( NULL != val && TYPE_STR == val->type ) 470 { 471 /* XXX not quite yet */ 472 msgresp( client, tag, IPC_MSG_NOTSUP ); 473 return; 474 } 475 else 476 { 477 val = tr_bencDictFind( dict, "file" ); 478 if( NULL == val || TYPE_STR != val->type ) 479 { 480 msgresp( client, tag, IPC_MSG_NOTSUP ); 481 return; 482 } 483 /* XXX detect duplicates and return a message indicating so */ 484 tor = torrent_add( val->val.s.s, dir, start ); 485 } 486 487 if( TORRENT_ID_VALID( tor ) ) 488 { 489 if( 0 > ipc_initinfo( &client->ipc, IPC_MSG_INFO, tag, &pk, &val ) ) 490 { 491 errnomsg( "failed to build message" ); 492 byebye( client->ev, EVBUFFER_EOF, NULL ); 493 return; 494 } 495 inf = torrent_info( tor ); 496 if( 0 > ipc_addinfo( val, tor, inf, 0 ) ) 497 { 498 errnomsg( "failed to build message" ); 499 tr_bencFree( &pk ); 500 byebye( client->ev, EVBUFFER_EOF, NULL ); 501 return; 502 } 503 buf = ipc_mkinfo( &pk, &buflen ); 504 tr_bencFree( &pk ); 439 505 queuemsg( client, buf, buflen ); 440 free( added );441 506 free( buf ); 507 } 508 else 509 { 510 msgresp( client, tag, IPC_MSG_FAIL ); 442 511 } 443 512 } … … 482 551 case IPC_MSG_DOWNLIMIT: 483 552 torrent_set_downlimit( num ); 553 break; 554 case IPC_MSG_PEX: 555 torrent_set_pex( num ? 1 : 0 ); 484 556 break; 485 557 case IPC_MSG_PORT: … … 803 875 torrent_get_downlimit() ); 804 876 break; 877 case IPC_MSG_GETPEX: 878 buf = ipc_mkint( &client->ipc, &buflen, IPC_MSG_PEX, tag, 879 torrent_get_pex() ); 880 break; 805 881 case IPC_MSG_GETPORT: 806 882 buf = ipc_mkint( &client->ipc, &buflen, IPC_MSG_PORT, tag, -
branches/daemon/daemon/torrents.c
r1621 r1631 57 57 uint8_t hash[SHA_DIGEST_LENGTH]; 58 58 tr_torrent_t * tor; 59 int pexset; 60 int pex; 59 61 RB_ENTRY( tor ) idlinks; 60 62 RB_ENTRY( tor ) hashlinks; … … 64 66 RB_HEAD( hashtree, tor ); 65 67 66 static struct tor * opentorrent ( const char *, const char * );68 static struct tor * opentorrent ( const char *, const char *, const char * ); 67 69 static void closetorrent( struct tor *, int ); 68 70 static void starttimer ( int ); … … 76 78 static struct tor * idlookup ( int, int ); 77 79 static struct tor * hashlookup ( const uint8_t *, int ); 80 static struct tor * iterate ( struct tor * ); 78 81 79 82 static struct event_base * gl_base = NULL; … … 89 92 90 93 static int gl_autostart = 1; 94 static int gl_pex = 1; 91 95 static int gl_port = TR_DEFAULT_PORT; 92 96 static int gl_mapping = 0; … … 113 117 114 118 loadstate(); 115 116 if( TR_DEFAULT_PORT != gl_port ) 117 { 118 tr_setBindPort( gl_handle, gl_port ); 119 } 120 tr_natTraversalEnable( gl_handle, gl_mapping ); 121 tr_setGlobalUploadLimit( gl_handle, gl_uplimit ); 122 tr_setGlobalDownloadLimit( gl_handle, gl_downlimit ); 123 } 124 125 int 126 torrent_add( const char * path ) 119 } 120 121 int 122 torrent_add( const char * path, const char * dir, int autostart ) 127 123 { 128 124 struct tor * tor; … … 131 127 assert( !gl_exiting ); 132 128 133 tor = opentorrent( path, NULL );129 tor = opentorrent( path, NULL, dir ); 134 130 if( NULL == tor ) 135 131 { … … 137 133 } 138 134 139 if( gl_autostart ) 135 if( 0 > autostart ) 136 { 137 autostart = gl_autostart; 138 } 139 if( autostart ) 140 140 { 141 141 tr_torrentStart( tor->tor ); … … 284 284 assert( !gl_exiting ); 285 285 286 if( NULL == tor ) 287 { 288 tor = RB_MIN( tortree, &gl_tree ); 289 } 290 else 291 { 292 tor = RB_NEXT( tortree, &gl_tree, tor ); 293 } 294 295 while( NULL != tor && tor->deleting ) 296 { 297 tor = RB_NEXT( tortree, &gl_tree, tor ); 298 } 286 tor = iterate( tor ); 299 287 300 288 if( NULL != tor ) … … 360 348 361 349 void 350 torrent_set_pex( int pex ) 351 { 352 struct tor * tor; 353 354 assert( NULL != gl_handle ); 355 assert( !gl_exiting ); 356 357 if( pex == gl_pex ) 358 { 359 return; 360 } 361 gl_pex = pex; 362 363 for( tor = iterate( NULL ); NULL != tor; tor = iterate( tor ) ) 364 { 365 if( tor->pexset ) 366 { 367 continue; 368 } 369 tr_torrentDisablePex( tor->tor, !gl_pex ); 370 } 371 372 savestate(); 373 } 374 375 int 376 torrent_get_pex( void ) 377 { 378 return gl_pex; 379 } 380 381 void 362 382 torrent_enable_port_mapping( int automap ) 363 383 { … … 424 444 425 445 struct tor * 426 opentorrent( const char * path, const char * hash )446 opentorrent( const char * path, const char * hash, const char * dir ) 427 447 { 428 448 struct tor * tor, * found; … … 432 452 assert( NULL == path || NULL == hash ); 433 453 assert( NULL != path || NULL != hash ); 454 455 /* XXX should probably wrap around back to 1 and avoid duplicates */ 456 if( INT_MAX == gl_lastid ) 457 { 458 errmsg( "Congratulations, you're the %ith torrent! Your prize the " 459 "inability to load any more torrents, enjoy!", INT_MAX ); 460 return NULL; 461 } 434 462 435 463 tor = calloc( 1, sizeof *tor ); … … 473 501 return found; 474 502 } 475 tor->id = ++gl_lastid; 503 gl_lastid++; 504 tor->id = gl_lastid; 476 505 tor->deleting = 0; 477 506 … … 480 509 memcpy( tor->hash, inf->hash, sizeof tor->hash ); 481 510 482 tr_torrentSetFolder( tor->tor, gl_dir ); 511 tr_torrentSetFolder( tor->tor, ( NULL == dir ? gl_dir : dir ) ); 512 513 if( TR_FLAG_PRIVATE & inf->flags ) 514 { 515 tor->pexset = 1; 516 tor->pex = 0; 517 } 518 else 519 { 520 tr_torrentDisablePex( tor->tor, !gl_pex ); 521 } 483 522 484 523 found = RB_INSERT( tortree, &gl_tree, tor ); … … 600 639 uint8_t * buf; 601 640 size_t len; 602 benc_val_t top, * num, * str, * list, * dict , * hash, * pause, * dir;641 benc_val_t top, * num, * str, * list, * dict; 603 642 int ii; 604 643 struct tor * tor; 644 const char * dir; 605 645 606 646 buf = readfile( gl_state, &len ); … … 621 661 if( NULL != num && TYPE_INT == num->type ) 622 662 { 623 gl_autostart = num->val.i; 624 } 663 gl_autostart = ( num->val.i ? 1 : 0 ); 664 } 665 625 666 num = tr_bencDictFind( &top, "port" ); 626 667 if( NULL != num && TYPE_INT == num->type && … … 629 670 gl_port = num->val.i; 630 671 } 672 tr_setBindPort( gl_handle, gl_port ); 673 674 num = tr_bencDictFind( &top, "default-pex" ); 675 if( NULL != num && TYPE_INT == num->type ) 676 { 677 gl_pex = ( num->val.i ? 1 : 0 ); 678 } 679 631 680 num = tr_bencDictFind( &top, "port-mapping" ); 632 681 if( NULL != num && TYPE_INT == num->type ) 633 682 { 634 gl_mapping = num->val.i; 635 } 683 gl_mapping = ( num->val.i ? 1 : 0 ); 684 } 685 tr_natTraversalEnable( gl_handle, gl_mapping ); 686 636 687 num = tr_bencDictFind( &top, "upload-limit" ); 637 688 if( NULL != num && TYPE_INT == num->type ) … … 639 690 gl_uplimit = num->val.i; 640 691 } 692 tr_setGlobalUploadLimit( gl_handle, gl_uplimit ); 693 641 694 num = tr_bencDictFind( &top, "download-limit" ); 642 695 if( NULL != num && TYPE_INT == num->type ) … … 644 697 gl_downlimit = num->val.i; 645 698 } 699 tr_setGlobalDownloadLimit( gl_handle, gl_downlimit ); 700 646 701 str = tr_bencDictFind( &top, "default-directory" ); 647 702 if( NULL != str && TYPE_STR == str->type ) … … 651 706 652 707 list = tr_bencDictFind( &top, "torrents" ); 653 if( NULL != list && TYPE_LIST == list->type ) 654 { 655 for( ii = 0; ii < list->val.l.count; ii++ ) 656 { 657 dict = &list->val.l.vals[ii]; 658 if( TYPE_DICT != dict->type ) 659 { 660 continue; 661 } 662 hash = tr_bencDictFind( dict, "hash" ); 663 if( NULL == hash || TYPE_STR != hash->type || 664 2 * SHA_DIGEST_LENGTH != hash->val.s.i ) 665 { 666 continue; 667 } 668 tor = opentorrent( NULL, hash->val.s.s ); 669 if( NULL == tor ) 670 { 671 continue; 672 } 673 dir = tr_bencDictFind( dict, "directory" ); 674 if( NULL != dir && TYPE_STR == dir->type ) 675 { 676 tr_torrentSetFolder( tor->tor, dir->val.s.s ); 677 } 678 pause = tr_bencDictFind( dict, "paused" ); 679 if( NULL != pause && TYPE_INT == pause->type && !pause->val.i ) 680 { 681 tr_torrentStart( tor->tor ); 682 } 708 if( NULL == list || TYPE_LIST != list->type ) 709 { 710 return 0; 711 } 712 713 for( ii = 0; ii < list->val.l.count; ii++ ) 714 { 715 dict = &list->val.l.vals[ii]; 716 if( TYPE_DICT != dict->type ) 717 { 718 continue; 719 } 720 721 str = tr_bencDictFind( dict, "directory" ); 722 dir = ( NULL != str && TYPE_STR == str->type ? str->val.s.s : NULL ); 723 724 str = tr_bencDictFind( dict, "hash" ); 725 if( NULL == str || TYPE_STR != str->type || 726 2 * SHA_DIGEST_LENGTH != str->val.s.i ) 727 { 728 continue; 729 } 730 731 tor = opentorrent( NULL, str->val.s.s, dir ); 732 if( NULL == tor ) 733 { 734 continue; 735 } 736 737 num = tr_bencDictFind( dict, "pex" ); 738 if( NULL != num && TYPE_INT == num->type ) 739 { 740 tor->pexset = 1; 741 tor->pex = ( num->val.i ? 1 : 0 ); 742 } 743 tr_torrentDisablePex( tor->tor, !( tor->pexset ? tor->pex : gl_pex ) ); 744 745 num = tr_bencDictFind( dict, "paused" ); 746 if( NULL != num && TYPE_INT == num->type && !num->val.i ) 747 { 748 tr_torrentStart( tor->tor ); 683 749 } 684 750 } … … 695 761 tr_stat_t * st; 696 762 uint8_t * buf; 697 int len ;763 int len, pexset; 698 764 699 765 tr_bencInit( &top, TYPE_DICT ); … … 707 773 tr_bencInitInt( tr_bencDictAdd( &top, "autostart" ), gl_autostart ); 708 774 tr_bencInitInt( tr_bencDictAdd( &top, "port" ), gl_port ); 775 tr_bencInitInt( tr_bencDictAdd( &top, "default-pex" ), gl_pex ); 709 776 tr_bencInitInt( tr_bencDictAdd( &top, "port-mapping" ), gl_mapping ); 710 777 tr_bencInitInt( tr_bencDictAdd( &top, "upload-limit" ), gl_uplimit ); … … 737 804 assert( NULL != tor ); 738 805 tr_bencInit( tor, TYPE_DICT ); 739 if( tr_bencDictReserve( tor, 3 ) ) 806 inf = tr_torrentInfo( ii->tor ); 807 st = tr_torrentStat( ii->tor ); 808 pexset = ( ii->pexset && !( TR_FLAG_PRIVATE & inf->flags ) ); 809 if( tr_bencDictReserve( tor, ( pexset ? 4 : 3 ) ) ) 740 810 { 741 811 goto nomem; 742 812 } 743 inf = tr_torrentInfo( ii->tor );744 st = tr_torrentStat( ii->tor );745 813 tr_bencInitStr( tr_bencDictAdd( tor, "hash" ), 746 814 inf->hashString, 2 * SHA_DIGEST_LENGTH, 1 ); … … 749 817 tr_bencInitStr( tr_bencDictAdd( tor, "directory" ), 750 818 tr_torrentGetFolder( ii->tor ), -1, 1 ); 819 if( pexset ) 820 { 821 tr_bencInitInt( tr_bencDictAdd( tor, "pex" ), ii->pex ); 822 } 751 823 } 752 824 … … 894 966 return found; 895 967 } 968 969 struct tor * 970 iterate( struct tor * tor ) 971 { 972 assert( NULL != gl_handle ); 973 assert( !gl_exiting ); 974 975 if( NULL == tor ) 976 { 977 tor = RB_MIN( tortree, &gl_tree ); 978 } 979 else 980 { 981 tor = RB_NEXT( tortree, &gl_tree, tor ); 982 } 983 984 while( NULL != tor && tor->deleting ) 985 { 986 tor = RB_NEXT( tortree, &gl_tree, tor ); 987 } 988 989 return tor; 990 } -
branches/daemon/daemon/torrents.h
r1617 r1631 34 34 35 35 void torrent_init ( struct event_base * ); 36 int torrent_add ( const char * );36 int torrent_add ( const char *, const char *, int ); 37 37 void torrent_start ( int ); 38 38 void torrent_stop ( int ); … … 48 48 void torrent_set_port ( int ); 49 49 int torrent_get_port ( void ); 50 void torrent_set_pex ( int ); 51 int torrent_get_pex ( void ); 50 52 void torrent_enable_port_mapping ( int ); 51 53 int torrent_get_port_mapping ( void );
Note: See TracChangeset
for help on using the changeset viewer.