Changeset 5001
- Timestamp:
- Feb 10, 2008, 4:03:19 AM (15 years ago)
- Location:
- trunk/libtransmission
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/completion.c
r4840 r5001 260 260 } 261 261 262 int 263 tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece ) 264 { 265 assert( cp != NULL ); 266 267 return tr_torPieceCountBlocks(cp->tor,piece) - cp->completeBlocks[piece]; 268 } 269 262 270 /*** 263 271 **** -
trunk/libtransmission/completion.h
r4404 r5001 55 55 void tr_cpBlockBitfieldSet( tr_completion *, struct tr_bitfield * ); 56 56 float tr_cpPercentBlocksInPiece( const tr_completion * cp, int piece ); 57 int tr_cpMissingBlocksInPiece( const tr_completion * cp, int piece ); 58 57 59 58 60 const struct tr_bitfield * tr_cpPieceBitfield( const tr_completion* ); -
trunk/libtransmission/peer-mgr.c
r4856 r5001 548 548 } 549 549 550 static int 551 clientIsDownloadingFrom( const tr_peer * peer ) 552 { 553 return peer->clientIsInterested && !peer->clientIsChoked; 554 } 555 556 static int 557 clientIsUploadingTo( const tr_peer * peer ) 558 { 559 return peer->peerIsInterested && !peer->peerIsChoked; 560 } 561 550 562 /*** 551 563 **** Refill … … 555 567 { 556 568 tr_priority_t priority; 557 int percentDone;569 int missingBlockCount; 558 570 uint16_t random; 559 571 uint32_t piece; … … 568 580 const struct tr_refill_piece * a = aIn; 569 581 const struct tr_refill_piece * b = bIn; 582 583 /* fewer missing pieces goes first */ 584 if( a->missingBlockCount != b->missingBlockCount ) 585 return a->missingBlockCount < b->missingBlockCount ? -1 : 1; 570 586 571 587 /* if one piece has a higher priority, it goes first */ 572 588 if( a->priority != b->priority ) 573 589 return a->priority > b->priority ? -1 : 1; 574 575 /* try to fill partial pieces */576 if( a->percentDone != b->percentDone )577 return a->percentDone > b->percentDone ? -1 : 1;578 590 579 591 /* if one *might be* fastallowed to us, get it first... … … 646 658 setme->fastAllowed = 0; 647 659 setme->random = tr_rand( UINT16_MAX ); 648 setme-> percentDone = (int)( 100.0 * tr_cpPercentBlocksInPiece( tor->completion, piece ));660 setme->missingBlockCount = tr_cpMissingBlocksInPiece( tor->completion, piece ); 649 661 650 662 for( k=0; k<peerCount; ++k ) { … … 762 774 } 763 775 776 static tr_peer** 777 getPeersUploadingToClient( Torrent * t, int * setmeCount ) 778 { 779 int i; 780 int peerCount = 0; 781 int retCount = 0; 782 tr_peer ** peers = (tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount ); 783 tr_peer ** ret = tr_new( tr_peer*, peerCount ); 784 785 /* get a list of peers we're downloading from */ 786 for( i=0; i<peerCount; ++i ) 787 if( clientIsDownloadingFrom( peers[i] ) ) 788 ret[retCount++] = peers[i]; 789 790 /* pick a different starting point each time so all peers 791 * get a chance at the first blocks in the queue */ 792 if( retCount ) { 793 tr_peer ** tmp = tr_new( tr_peer*, retCount ); 794 i = tr_rand( retCount ); 795 memcpy( tmp, ret, sizeof(tr_peer*) * retCount ); 796 memcpy( ret, tmp+i, sizeof(tr_peer*) * (retCount-i) ); 797 memcpy( ret+(retCount-i), tmp, sizeof(tr_peer*) * i ); 798 tr_free( tmp ); 799 } 800 801 *setmeCount = retCount; 802 return ret; 803 } 804 764 805 static int 765 806 refillPulse( void * vtorrent ) … … 782 823 783 824 blocks = getPreferredBlocks( t, &blockCount ); 784 peers = get ConnectedPeers( t, &peerCount );825 peers = getPeersUploadingToClient( t, &peerCount ); 785 826 786 827 for( i=0; peerCount && i<blockCount; ++i ) 787 828 { 829 int j; 830 788 831 const uint64_t block = blocks[i]; 789 832 const uint32_t index = tr_torBlockPiece( tor, block ); 790 833 const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize); 791 834 const uint32_t length = tr_torBlockCountBytes( tor, (int)block ); 792 int j; 835 793 836 assert( _tr_block( tor, index, begin ) == (int)block ); 794 837 assert( begin < (uint32_t)tr_torPieceCountBytes( tor, (int)index ) ); … … 1406 1449 managerUnlock( (tr_peerMgr*)manager ); 1407 1450 return ret; 1408 }1409 1410 static int1411 clientIsDownloadingFrom( const tr_peer * peer )1412 {1413 return peer->clientIsInterested && !peer->clientIsChoked;1414 }1415 1416 static int1417 clientIsUploadingTo( const tr_peer * peer )1418 {1419 return peer->peerIsInterested && !peer->peerIsChoked;1420 1451 } 1421 1452 -
trunk/libtransmission/peer-msgs.c
r4839 r5001 77 77 MAX_FAST_ALLOWED_THRESHOLD = 10, /* max threshold for allowing fast-pieces requests */ 78 78 79 REQUEST_TTL_SECS = 120 79 QUEUED_REQUEST_TTL_SECS = 20, 80 81 SENT_REQUEST_TTL_SECS = 90 80 82 81 83 }; … … 590 592 for( l=msgs->clientWillAskFor; l!=NULL; l=l->next ) { 591 593 struct peer_request * req = l->data; 592 if( req->time_requested + REQUEST_TTL_SECS < now )594 if( req->time_requested + QUEUED_REQUEST_TTL_SECS < now ) 593 595 tr_list_prepend( &prune, req ); 594 596 } … … 598 600 for( l=msgs->clientAskedFor; l!=NULL; l=l->next ) { 599 601 struct peer_request * req = l->data; 600 if( req->time_requested + REQUEST_TTL_SECS < now )602 if( req->time_requested + SENT_REQUEST_TTL_SECS < now ) 601 603 tr_list_prepend( &prune, req ); 602 604 } … … 1551 1553 msgs->info->rateToClient = tr_rcRate( msgs->info->rcToClient ); 1552 1554 msgs->info->rateToPeer = tr_rcRate( msgs->info->rcToPeer ); 1553 msgs->maxActiveRequests = MIN( 8 + (int)(msgs->info->rateToClient/5), 100 );1555 msgs->maxActiveRequests = MIN( 4 + (int)(msgs->info->rateToClient/4), 100 ); 1554 1556 msgs->minActiveRequests = msgs->maxActiveRequests / 3; 1555 1557 return TRUE;
Note: See TracChangeset
for help on using the changeset viewer.