Changeset 6073
- Timestamp:
- Jun 7, 2008, 9:26:41 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gtk/tr-prefs.c
r6068 r6073 263 263 char url[256]; 264 264 snprintf( url, sizeof(url), "http://portcheck.transmissionbt.com/%d", port ); 265 tr_webRun( handle, url, testing_port_done, data );265 tr_webRun( handle, url, NULL, testing_port_done, data ); 266 266 } 267 267 return FALSE; … … 493 493 gtk_widget_show( d ); 494 494 495 tr_webRun( handle, url, got_blocklist, data );495 tr_webRun( handle, url, NULL, got_blocklist, data ); 496 496 } 497 497 -
trunk/libtransmission/Makefile.am
r6031 r6073 43 43 utils.c \ 44 44 verify.c \ 45 web.c 45 web.c \ 46 webseed.c 46 47 47 48 noinst_HEADERS = \ … … 64 65 natpmp.h \ 65 66 net.h \ 67 peer-common.h \ 66 68 peer-io.h \ 67 69 peer-mgr.h \ … … 85 87 utils.h \ 86 88 verify.h \ 87 web.h 89 web.h \ 90 webseed.h 88 91 89 92 TESTS = \ -
trunk/libtransmission/bencode.c
r5988 r6073 497 497 tr_bencInit( val, TYPE_STR ); 498 498 val->val.s.i = byteCount; 499 val->val.s.s = tr_ new( char, byteCount );499 val->val.s.s = tr_memdup( src, byteCount ); 500 500 val->val.s.nofree = 0; 501 memcpy( val->val.s.s, src, byteCount );502 501 } 503 502 -
trunk/libtransmission/inout.c
r5843 r6073 100 100 } 101 101 102 staticvoid103 findFileLocation( const tr_torrent * tor,104 tr_piece_index_t pieceIndex,105 uint32_t pieceOffset,106 tr_file_index_t * fileIndex,107 uint64_t * fileOffset )102 void 103 tr_ioFindFileLocation( const tr_torrent * tor, 104 tr_piece_index_t pieceIndex, 105 uint32_t pieceOffset, 106 tr_file_index_t * fileIndex, 107 uint64_t * fileOffset ) 108 108 { 109 109 const uint64_t offset = tr_pieceOffset( tor, pieceIndex, pieceOffset, 0 ); … … 173 173 return TR_ERROR_ASSERT; 174 174 175 findFileLocation( tor, pieceIndex, pieceOffset,176 175 tr_ioFindFileLocation( tor, pieceIndex, pieceOffset, 176 &fileIndex, &fileOffset ); 177 177 178 178 while( buflen && !err ) -
trunk/libtransmission/inout.h
r5645 r6073 58 58 59 59 60 /** 61 * Converts a piece index + offset into a file index + offset. 62 */ 63 void tr_ioFindFileLocation( const tr_torrent * tor, 64 tr_piece_index_t pieceIndex, 65 uint32_t pieceOffset, 66 tr_file_index_t * fileIndex, 67 uint64_t * fileOffset ); 68 69 70 60 71 #endif -
trunk/libtransmission/metainfo.c
r5963 r6073 222 222 223 223 return scrape; 224 } 225 226 static void 227 geturllist( tr_info * inf, tr_benc * meta ) 228 { 229 benc_val_t * urls; 230 231 if( tr_bencDictFindList( meta, "url-list", &urls ) ) 232 { 233 int i; 234 const char * url; 235 const int n = tr_bencListSize( urls ); 236 237 inf->webseedCount = 0; 238 inf->webseeds = tr_new0( char*, n ); 239 240 for( i=0; i<n; ++i ) 241 if( tr_bencGetStr( tr_bencListChild( urls, i ), &url ) ) 242 inf->webseeds[inf->webseedCount++] = tr_strdup( url ); 243 } 224 244 } 225 245 … … 412 432 goto fail; 413 433 434 /* get the url-list */ 435 geturllist( inf, meta ); 436 414 437 /* filename of Transmission's copy */ 415 438 getTorrentFilename( handle, inf, buf, sizeof( buf ) ); … … 429 452 int i; 430 453 454 for( i=0; i<inf->webseedCount; ++i ) 455 tr_free( inf->webseeds[i] ); 456 431 457 for( ff=0; ff<inf->fileCount; ++ff ) 432 458 tr_free( inf->files[ff].name ); 433 459 460 tr_free( inf->webseeds ); 434 461 tr_free( inf->pieces ); 435 462 tr_free( inf->files ); -
trunk/libtransmission/peer-mgr.c
r6071 r6073 25 25 #include "crypto.h" 26 26 #include "handshake.h" 27 #include "inout.h" /* tr_ioTestPiece */ 27 28 #include "net.h" 28 29 #include "peer-io.h" … … 32 33 #include "ptrarray.h" 33 34 #include "ratecontrol.h" 35 #include "stats.h" /* tr_statsAddDownloaded */ 34 36 #include "torrent.h" 35 37 #include "trevent.h" 36 38 #include "utils.h" 39 #include "webseed.h" 37 40 38 41 enum … … 104 107 tr_ptrArray * pool; /* struct peer_atom */ 105 108 tr_ptrArray * peers; /* tr_peer */ 109 tr_ptrArray * webseeds; /* tr_webseed */ 106 110 tr_timer * reconnectTimer; 107 111 tr_timer * rechokeTimer; … … 333 337 atom->time = time( NULL ); 334 338 335 removed = tr_ptrArrayRemoveSorted 339 removed = tr_ptrArrayRemoveSorted( t->peers, peer, peerCompare ); 336 340 assert( removed == peer ); 337 341 peerDestructor( removed ); … … 364 368 365 369 tr_bitfieldFree( t->requested ); 370 tr_ptrArrayFree( t->webseeds, (PtrArrayForeachFunc)tr_webseedFree ); 366 371 tr_ptrArrayFree( t->pool, (PtrArrayForeachFunc)tr_free ); 367 372 tr_ptrArrayFree( t->outgoingHandshakes, NULL ); … … 371 376 } 372 377 378 static void peerCallbackFunc( void * vpeer, void * vevent, void * vt ); 379 373 380 static Torrent* 374 381 torrentConstructor( tr_peerMgr * manager, tr_torrent * tor ) 375 382 { 383 int i; 376 384 Torrent * t; 377 385 … … 381 389 t->pool = tr_ptrArrayNew( ); 382 390 t->peers = tr_ptrArrayNew( ); 391 t->webseeds = tr_ptrArrayNew( ); 383 392 t->outgoingHandshakes = tr_ptrArrayNew( ); 384 393 t->requested = tr_bitfieldNew( tor->blockCount ); 385 394 memcpy( t->hash, tor->info.hash, SHA_DIGEST_LENGTH ); 395 396 for( i=0; i<tor->info.webseedCount; ++i ) { 397 tr_webseed * w = tr_webseedNew( tor, tor->info.webseeds[i], peerCallbackFunc, t ); 398 tr_ptrArrayAppend( t->webseeds, w ); 399 } 386 400 387 401 return t; … … 537 551 if( a->priority != b->priority ) 538 552 return a->priority > b->priority ? -1 : 1; 539 553 540 554 /* otherwise if one has fewer peers, it goes first */ 541 555 if (a->peerCount != b->peerCount) 542 556 return a->peerCount < b->peerCount ? -1 : 1; 543 557 558 #if 0 559 /* otherwise download them in order */ 560 return tr_compareUint16( a->piece, b->piece ); 561 #else 544 562 /* otherwise go with our random seed */ 545 563 return tr_compareUint16( a->random, b->random ); 564 #endif 546 565 } 547 566 … … 742 761 tr_block_index_t i; 743 762 int peerCount; 763 int webseedCount; 744 764 tr_peer ** peers; 765 tr_webseed ** webseeds; 745 766 tr_block_index_t blockCount; 746 767 uint64_t * blocks; … … 756 777 blocks = getPreferredBlocks( t, &blockCount ); 757 778 peers = getPeersUploadingToClient( t, &peerCount ); 758 759 for( i=0; peerCount && i<blockCount; ++i ) 779 webseedCount = tr_ptrArraySize( t->webseeds ); 780 webseeds = tr_memdup( tr_ptrArrayBase(t->webseeds), webseedCount*sizeof(tr_webseed*) ); 781 782 783 #warning do not check in this line 784 peerCount = 0; 785 786 for( i=0; (webseedCount || peerCount) && i<blockCount; ++i ) 760 787 { 761 788 int j; 789 int handled = FALSE; 762 790 763 791 const tr_block_index_t block = blocks[i]; … … 765 793 const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize); 766 794 const uint32_t length = tr_torBlockCountBytes( tor, block ); 795 fprintf( stderr, "next block in the refill pulse is %d\n", (int)block ); 767 796 768 797 assert( tr_torrentReqIsValid( tor, index, begin, length ) ); … … 772 801 773 802 /* find a peer who can ask for this block */ 774 for( j=0; j<peerCount; )803 for( j=0; !handled && j<peerCount; ) 775 804 { 776 805 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length ); … … 781 810 memmove( peers+j, peers+j+1, sizeof(tr_peer*)*(--peerCount-j) ); 782 811 break; 783 784 812 case TR_ADDREQ_MISSING: 785 813 case TR_ADDREQ_DUPLICATE: 786 814 ++j; 787 815 break; 788 789 816 case TR_ADDREQ_OK: 790 817 tr_bitfieldAdd( t->requested, block ); 791 j = peerCount;818 handled = TRUE; 792 819 break; 793 794 820 default: 795 821 assert( 0 && "unhandled value" ); … … 797 823 } 798 824 } 825 826 /* maybe one of the webseeds can do it */ 827 for( j=0; !handled && j<webseedCount; ) 828 { 829 const int val = tr_webseedAddRequest( webseeds[j], index, begin, length ); 830 switch( val ) 831 { 832 case TR_ADDREQ_FULL: 833 memmove( webseeds+j, webseeds+j+1, sizeof(tr_webseed*)*(--webseedCount-j) ); 834 break; 835 case TR_ADDREQ_OK: 836 tr_bitfieldAdd( t->requested, block ); 837 handled = TRUE; 838 break; 839 default: 840 assert( 0 && "unhandled value" ); 841 break; 842 } 843 } 799 844 } 800 845 801 846 /* cleanup */ 847 tr_free( webseeds ); 802 848 tr_free( peers ); 803 849 tr_free( blocks ); … … 806 852 torrentUnlock( t ); 807 853 return FALSE; 808 }809 810 static void811 broadcastClientHave( Torrent * t, uint32_t index )812 {813 int i, size;814 tr_peer ** peers;815 816 assert( torrentIsLocked( t ) );817 818 peers = getConnectedPeers( t, &size );819 for( i=0; i<size; ++i )820 tr_peerMsgsHave( peers[i]->msgs, index );821 tr_free( peers );822 854 } 823 855 … … 851 883 852 884 static void 853 msgsCallbackFunc( void * vpeer, void * vevent, void * vt ) 854 { 855 tr_peer * peer = vpeer; 885 gotBadPiece( Torrent * t, tr_piece_index_t pieceIndex ) 886 { 887 tr_torrent * tor = t->tor; 888 const uint32_t byteCount = tr_torPieceCountBytes( tor, pieceIndex ); 889 tor->corruptCur += byteCount; 890 tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); 891 } 892 893 static void 894 peerCallbackFunc( void * vpeer, void * vevent, void * vt ) 895 { 896 tr_peer * peer = vpeer; /* may be NULL if peer is a webseed */ 856 897 Torrent * t = (Torrent *) vt; 857 const tr_peer msgs_event * e = (const tr_peermsgs_event *)vevent;898 const tr_peer_event * e = vevent; 858 899 859 900 torrentLock( t ); … … 861 902 switch( e->eventType ) 862 903 { 863 case TR_PEER MSG_NEED_REQ:904 case TR_PEER_NEED_REQ: 864 905 if( t->refillTimer == NULL ) 865 906 t->refillTimer = tr_timerNew( t->manager->handle, … … 868 909 break; 869 910 870 case TR_PEER MSG_CANCEL:911 case TR_PEER_CANCEL: 871 912 tr_bitfieldRem( t->requested, _tr_block( t->tor, e->pieceIndex, e->offset ) ); 872 913 break; 873 914 874 case TR_PEERMSG_PIECE_DATA: { 875 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 876 atom->piece_data_time = time( NULL ); 915 case TR_PEER_PEER_GOT_DATA: { 916 const time_t now = time( NULL ); 917 tr_torrent * tor = t->tor; 918 tor->activityDate = now; 919 tor->uploadedCur += e->length; 920 tr_rcTransferred( tor->upload, e->length ); 921 tr_rcTransferred( tor->handle->upload, e->length ); 922 tr_statsAddUploaded( tor->handle, e->length ); 923 if( peer ) { 924 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 925 atom->piece_data_time = time( NULL ); 926 } 877 927 break; 878 928 } 879 929 880 case TR_PEERMSG_CLIENT_HAVE: 881 broadcastClientHave( t, e->pieceIndex ); 882 tr_torrentRecheckCompleteness( t->tor ); 930 case TR_PEER_CLIENT_GOT_DATA: { 931 const time_t now = time( NULL ); 932 tr_torrent * tor = t->tor; 933 tor->activityDate = now; 934 tor->downloadedCur += e->length; 935 tr_rcTransferred( tor->download, e->length ); 936 tr_rcTransferred( tor->handle->download, e->length ); 937 tr_statsAddDownloaded( tor->handle, e->length ); 938 if( peer ) { 939 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 940 atom->piece_data_time = time( NULL ); 941 } 883 942 break; 884 885 case TR_PEERMSG_PEER_PROGRESS: { 886 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 887 const int peerIsSeed = e->progress >= 1.0; 888 if( peerIsSeed ) { 889 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr(&atom->addr,atom->port) ); 890 atom->flags |= ADDED_F_SEED_FLAG; 891 } else { 892 tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr(&atom->addr,atom->port) ); 893 atom->flags &= ~ADDED_F_SEED_FLAG; 894 } break; 895 } 896 897 case TR_PEERMSG_CLIENT_BLOCK: 943 } 944 945 case TR_PEER_PEER_PROGRESS: { 946 if( peer ) { 947 struct peer_atom * atom = getExistingAtom( t, &peer->in_addr ); 948 const int peerIsSeed = e->progress >= 1.0; 949 if( peerIsSeed ) { 950 tordbg( t, "marking peer %s as a seed", tr_peerIoAddrStr(&atom->addr,atom->port) ); 951 atom->flags |= ADDED_F_SEED_FLAG; 952 } else { 953 tordbg( t, "marking peer %s as a non-seed", tr_peerIoAddrStr(&atom->addr,atom->port) ); 954 atom->flags &= ~ADDED_F_SEED_FLAG; 955 } 956 } 957 break; 958 } 959 960 case TR_PEER_CLIENT_GOT_BLOCK: 961 { 962 tr_torrent * tor = t->tor; 963 964 tr_block_index_t block = _tr_block( tor, e->pieceIndex, e->offset ); 965 966 tr_cpBlockAdd( tor->completion, block ); 967 898 968 broadcastGotBlock( t, e->pieceIndex, e->offset, e->length ); 969 970 if( tr_cpPieceIsComplete( tor->completion, e->pieceIndex ) ) 971 { 972 const tr_piece_index_t p = e->pieceIndex; 973 const tr_errno err = tr_ioTestPiece( tor, p ); 974 975 if( err ) { 976 tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test: %s" ), 977 (unsigned long)p, tr_errorString( err ) ); 978 } 979 980 tr_torrentSetHasPiece( tor, p, !err ); 981 tr_torrentSetPieceChecked( tor, p, TRUE ); 982 tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, p, !err ); 983 984 if( err ) 985 gotBadPiece( t, p ); 986 987 tr_torrentRecheckCompleteness( tor ); 988 } 899 989 break; 900 901 case TR_PEERMSG_ERROR: 990 } 991 992 case TR_PEER_ERROR: 902 993 if( TR_ERROR_IS_IO( e->err ) ) { 903 994 t->tor->error = e->err; … … 1025 1116 peer->port = port; 1026 1117 peer->io = io; 1027 peer->msgs = tr_peerMsgsNew( t->tor, peer, msgsCallbackFunc, t, &peer->msgsTag );1118 peer->msgs = tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag ); 1028 1119 atom->time = time( NULL ); 1029 1120 } -
trunk/libtransmission/peer-msgs.c
r6071 r6073 156 156 reqListCopy( struct request_list * dest, const struct request_list * src ) 157 157 { 158 dest->count = src->count; 159 dest->max = src->max; 160 dest->requests = tr_new( struct peer_request, dest->max ); 161 memcpy( dest->requests, src->requests, sizeof( struct peer_request ) * dest->count ); 158 dest->count = dest->max = src->count; 159 dest->requests = tr_memdup( src->requests, dest->count * sizeof( struct peer_request ) ); 162 160 } 163 161 … … 397 395 **/ 398 396 399 static const tr_peer msgs_event blankEvent = { 0, 0, 0, 0, 0.0f, 0 };400 401 static void 402 publish( tr_peermsgs * msgs, tr_peer msgs_event * e )397 static const tr_peer_event blankEvent = { 0, 0, 0, 0, 0.0f, 0 }; 398 399 static void 400 publish( tr_peermsgs * msgs, tr_peer_event * e ) 403 401 { 404 402 tr_publisherPublish( msgs->publisher, msgs->info, e ); … … 408 406 fireError( tr_peermsgs * msgs, tr_errno err ) 409 407 { 410 tr_peer msgs_event e = blankEvent;411 e.eventType = TR_PEER MSG_ERROR;408 tr_peer_event e = blankEvent; 409 e.eventType = TR_PEER_ERROR; 412 410 e.err = err; 413 411 publish( msgs, &e ); … … 417 415 fireNeedReq( tr_peermsgs * msgs ) 418 416 { 419 tr_peer msgs_event e = blankEvent;420 e.eventType = TR_PEER MSG_NEED_REQ;417 tr_peer_event e = blankEvent; 418 e.eventType = TR_PEER_NEED_REQ; 421 419 publish( msgs, &e ); 422 420 } … … 425 423 firePeerProgress( tr_peermsgs * msgs ) 426 424 { 427 tr_peer msgs_event e = blankEvent;428 e.eventType = TR_PEER MSG_PEER_PROGRESS;425 tr_peer_event e = blankEvent; 426 e.eventType = TR_PEER_PEER_PROGRESS; 429 427 e.progress = msgs->info->progress; 430 428 publish( msgs, &e ); … … 432 430 433 431 static void 434 fireClientHave( tr_peermsgs * msgs, uint32_t pieceIndex )435 {436 tr_peermsgs_event e = blankEvent;437 e.eventType = TR_PEERMSG_CLIENT_HAVE;438 e.pieceIndex = pieceIndex;439 publish( msgs, &e );440 }441 442 static void443 432 fireGotBlock( tr_peermsgs * msgs, const struct peer_request * req ) 444 433 { 445 tr_peer msgs_event e = blankEvent;446 e.eventType = TR_PEER MSG_CLIENT_BLOCK;434 tr_peer_event e = blankEvent; 435 e.eventType = TR_PEER_CLIENT_GOT_BLOCK; 447 436 e.pieceIndex = req->index; 448 437 e.offset = req->offset; … … 452 441 453 442 static void 454 firePieceData( tr_peermsgs * msgs ) 455 { 456 tr_peermsgs_event e = blankEvent; 457 e.eventType = TR_PEERMSG_PIECE_DATA; 443 fireClientGotData( tr_peermsgs * msgs, uint32_t length ) 444 { 445 tr_peer_event e = blankEvent; 446 e.length = length; 447 e.eventType = TR_PEER_CLIENT_GOT_DATA; 458 448 publish( msgs, &e ); 459 449 } 460 450 461 451 static void 452 firePeerGotData( tr_peermsgs * msgs, uint32_t length ) 453 { 454 tr_peer_event e = blankEvent; 455 e.length = length; 456 e.eventType = TR_PEER_PEER_GOT_DATA; 457 publish( msgs, &e ); 458 } 459 460 static void 462 461 fireCancelledReq( tr_peermsgs * msgs, const struct peer_request * req ) 463 462 { 464 tr_peer msgs_event e = blankEvent;465 e.eventType = TR_PEER MSG_CANCEL;463 tr_peer_event e = blankEvent; 464 e.eventType = TR_PEER_CANCEL; 466 465 e.pieceIndex = req->index; 467 466 e.offset = req->offset; … … 1187 1186 clientGotBytes( tr_peermsgs * msgs, uint32_t byteCount ) 1188 1187 { 1189 const time_t now = time( NULL ); 1190 tr_torrent * tor = msgs->torrent; 1191 tor->activityDate = now; 1192 tor->downloadedCur += byteCount; 1193 msgs->info->pieceDataActivityDate = now; 1188 msgs->info->pieceDataActivityDate = time( NULL ); 1194 1189 tr_rcTransferred( msgs->info->rcToClient, byteCount ); 1195 tr_rcTransferred( tor->download, byteCount ); 1196 tr_rcTransferred( tor->handle->download, byteCount ); 1197 tr_statsAddDownloaded( msgs->handle, byteCount ); 1198 firePieceData( msgs ); 1190 fireClientGotData( msgs, byteCount ); 1199 1191 } 1200 1192 … … 1409 1401 peerGotBytes( tr_peermsgs * msgs, uint32_t byteCount ) 1410 1402 { 1411 const time_t now = time( NULL ); 1412 tr_torrent * tor = msgs->torrent; 1413 tor->activityDate = now; 1414 tor->uploadedCur += byteCount; 1415 msgs->info->pieceDataActivityDate = now; 1403 msgs->info->pieceDataActivityDate = time( NULL ); 1416 1404 tr_rcTransferred( msgs->info->rcToPeer, byteCount ); 1417 tr_rcTransferred( tor->upload, byteCount ); 1418 tr_rcTransferred( tor->handle->upload, byteCount ); 1419 tr_statsAddUploaded( msgs->handle, byteCount ); 1420 firePieceData( msgs ); 1405 firePeerGotData( msgs, byteCount ); 1421 1406 } 1422 1407 … … 1442 1427 tr_torrent * tor = msgs->torrent; 1443 1428 tor->downloadedCur -= MIN( tor->downloadedCur, byteCount ); 1444 }1445 1446 static void1447 reassignBytesToCorrupt( tr_peermsgs * msgs, uint32_t byteCount )1448 {1449 tr_torrent * tor = msgs->torrent;1450 1451 tor->corruptCur += byteCount;1452 1453 decrementDownloadedCount( msgs, byteCount );1454 }1455 1456 static void1457 gotBadPiece( tr_peermsgs * msgs, tr_piece_index_t pieceIndex )1458 {1459 const uint32_t byteCount =1460 tr_torPieceCountBytes( msgs->torrent, pieceIndex );1461 reassignBytesToCorrupt( msgs, byteCount );1462 1429 } 1463 1430 … … 1530 1497 return err; 1531 1498 1532 tr_cpBlockAdd( tor->completion, block );1533 1534 1499 addPeerToBlamefield( msgs, req->index ); 1535 1536 1500 fireGotBlock( msgs, req ); 1537 1538 /**1539 *** Handle if this was the last block in the piece1540 **/1541 1542 if( tr_cpPieceIsComplete( tor->completion, req->index ) )1543 {1544 const tr_errno err = tr_ioTestPiece( tor, req->index );1545 1546 if( err )1547 tr_torerr( tor, _( "Piece %lu, which was just downloaded, failed its checksum test: %s" ),1548 (unsigned long)req->index,1549 tr_errorString( err ) );1550 1551 tr_torrentSetHasPiece( tor, req->index, !err );1552 tr_torrentSetPieceChecked( tor, req->index, TRUE );1553 tr_peerMgrSetBlame( tor->handle->peerMgr, tor->info.hash, req->index, !err );1554 1555 if( !err )1556 fireClientHave( msgs, req->index );1557 else1558 gotBadPiece( msgs, req->index );1559 }1560 1561 1501 return 0; 1562 1502 } -
trunk/libtransmission/peer-msgs.h
r5199 r6073 15 15 16 16 #include <inttypes.h> 17 #include "peer-common.h" 17 18 #include "publish.h" 18 19 … … 43 44 44 45 46 #if 0 45 47 enum { 46 48 TR_ADDREQ_OK=0, … … 50 52 TR_ADDREQ_CLIENT_CHOKED 51 53 }; 54 #endif 52 55 53 56 int tr_peerMsgsAddRequest( tr_peermsgs * peer, … … 60 63 **/ 61 64 65 #if 0 62 66 typedef enum 63 67 { … … 82 86 } 83 87 tr_peermsgs_event; 88 #endif 84 89 85 tr_publisher_tag tr_peerMsgsSubscribe ( tr_peermsgs * peer, 86 tr_delivery_func func, 87 void * user ); 88 89 void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer, 90 tr_publisher_tag tag ); 90 void tr_peerMsgsUnsubscribe ( tr_peermsgs * peer, 91 tr_publisher_tag tag ); 91 92 92 93 #endif -
trunk/libtransmission/ptrarray.c
r5389 r6073 58 58 59 59 out = tr_new( tr_ptrArray, 1 ); 60 out->n_items = in->n_items; 61 out->n_alloc = in->n_items; 62 out->items = tr_new( void*, out->n_alloc ); 63 memcpy( out->items, in->items, out->n_items * sizeof(void*) ); 60 out->n_items = out->n_alloc = in->n_items; 61 out->items = tr_memdup( in->items, out->n_items * sizeof(void*) ); 64 62 65 63 return out; … … 96 94 { 97 95 *size = t->n_items; 96 return t->items; 97 } 98 99 void** 100 tr_ptrArrayBase( tr_ptrArray * t ) 101 { 98 102 return t->items; 99 103 } -
trunk/libtransmission/tracker.c
r6049 r6073 697 697 { 698 698 struct tr_tracker_request * req = vreq; 699 uint8_t * hash;700 699 tr_tracker * t = findTracker( req->session, req->torrent_hash ); 701 700 … … 721 720 ++req->session->tracker->runningCount; 722 721 723 hash = tr_new0( uint8_t, SHA_DIGEST_LENGTH ); 724 memcpy( hash, req->torrent_hash, SHA_DIGEST_LENGTH ); 725 tr_webRun( req->session, req->url, req->done_func, hash ); 722 tr_webRun( req->session, req->url, NULL, req->done_func, 723 tr_memdup( req->torrent_hash, SHA_DIGEST_LENGTH ) ); 726 724 727 725 freeRequest( req ); -
trunk/libtransmission/transmission.h
r6049 r6073 1037 1037 int trackerCount; 1038 1038 1039 char ** webseeds; 1040 int webseedCount; 1041 1039 1042 /* Torrent info */ 1040 1043 char * comment; -
trunk/libtransmission/utils.c
r6072 r6073 239 239 newmsg->level = level; 240 240 newmsg->when = time( NULL ); 241 newmsg->message = tr_strdup( (char*)EVBUFFER_DATA( buf ) );241 newmsg->message = tr_strdup( EVBUFFER_DATA( buf ) ); 242 242 newmsg->file = file; 243 243 newmsg->line = line; … … 598 598 599 599 char* 600 tr_strdup( const char* in )601 { 602 return tr_strndup( in, in ? strlen( in) : 0 );600 tr_strdup( const void * in ) 601 { 602 return tr_strndup( in, in ? strlen((const char*)in) : 0 ); 603 603 } 604 604 605 605 char* 606 tr_strndup( const char* in, int len )606 tr_strndup( const void * in, int len ) 607 607 { 608 608 char * out = NULL; -
trunk/libtransmission/utils.h
r6072 r6073 189 189 void tr_free ( void* ); 190 190 191 char* tr_strdup( const char* str ) TR_GNUC_MALLOC;192 char* tr_strndup( const char* str, int len ) TR_GNUC_MALLOC;191 char* tr_strdup( const void * str ) TR_GNUC_MALLOC; 192 char* tr_strndup( const void * str, int len ) TR_GNUC_MALLOC; 193 193 void* tr_memdup( const void * src, int byteCount ) TR_GNUC_MALLOC; 194 194 char* tr_strdup_printf( const char * fmt, ... ) TR_GNUC_PRINTF( 1, 2 ) TR_GNUC_MALLOC; -
trunk/libtransmission/web.c
r6052 r6073 47 47 struct evbuffer * response; 48 48 char * url; 49 char * range; 49 50 tr_session * session; 50 51 tr_web_done_func * done_func; … … 87 88 curl_easy_cleanup( easy ); 88 89 evbuffer_free( task->response ); 90 tr_free( task->range ); 89 91 tr_free( task->url ); 90 92 tr_free( task ); … … 155 157 curl_easy_setopt( ch, CURLOPT_MAXREDIRS, 5 ); 156 158 curl_easy_setopt( ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 157 curl_easy_setopt( ch, CURLOPT_ENCODING, "" ); 159 if( task->range ) 160 curl_easy_setopt( ch, CURLOPT_RANGE, task->range ); 161 else /* don't set encoding if range is sent; it messes up binary data */ 162 curl_easy_setopt( ch, CURLOPT_ENCODING, "" ); 158 163 curl_multi_add_handle( web->cm, ch ); 159 164 } … … 163 168 tr_webRun( tr_session * session, 164 169 const char * url, 170 const char * range, 165 171 tr_web_done_func * done_func, 166 172 void * done_func_user_data ) … … 174 180 task->session = session; 175 181 task->url = tr_strdup( url ); 182 task->range = tr_strdup( range ); 176 183 task->done_func = done_func; 177 184 task->done_func_user_data = done_func_user_data; -
trunk/libtransmission/web.h
r5714 r6073 17 17 typedef struct tr_web tr_web; 18 18 19 tr_web* tr_webInit( tr_handle * session );19 tr_web* tr_webInit( struct tr_handle * session ); 20 20 21 21 void tr_webClose( tr_web ** ); 22 22 23 typedef void (tr_web_done_func)( tr_handle * session,24 longresponse_code,25 const void* response,26 size_tresponse_byte_count,27 void* user_data );23 typedef void (tr_web_done_func)( struct tr_handle * session, 24 long response_code, 25 const void * response, 26 size_t response_byte_count, 27 void * user_data ); 28 28 29 29 const char * tr_webGetResponseStr( long response_code ); 30 30 31 void tr_webRun( tr_handle* session,31 void tr_webRun( struct tr_handle * session, 32 32 const char * url, 33 const char * range, 33 34 tr_web_done_func done_func, 34 35 void * done_func_user_data );
Note: See TracChangeset
for help on using the changeset viewer.