Changeset 6957
- Timestamp:
- Oct 25, 2008, 3:19:46 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/peer-mgr.c
r6954 r6957 631 631 uint32_t piece; 632 632 uint32_t peerCount; 633 int missingBlockCount;634 633 int random; 635 634 int pendingRequestCount; 635 int missingBlockCount; 636 636 }; 637 637 … … 684 684 /* make a list of the pieces that we want but don't have */ 685 685 for( i = 0; i < inf->pieceCount; ++i ) 686 if( !tor->info.pieces[i].dnd && !tr_cpPieceIsComplete( tor->completion, i ) ) 686 if( !tor->info.pieces[i].dnd 687 && !tr_cpPieceIsComplete( tor->completion, i ) ) 687 688 pool[poolSize++] = i; 688 689 689 /* sort the pool from most interesting to least...*/690 /* sort the pool by which to request next */ 690 691 if( poolSize > 1 ) 691 692 { … … 703 704 setme->peerCount = 0; 704 705 setme->random = tr_cryptoWeakRandInt( INT_MAX ); 705 setme->missingBlockCount = tr_cpMissingBlocksInPiece( tor->completion, piece );706 706 setme->pendingRequestCount = getPieceRequests( t, piece ); 707 setme->missingBlockCount 708 = tr_cpMissingBlocksInPiece( tor->completion, piece ); 707 709 708 710 for( k = 0; k < peerCount; ++k ) 709 711 { 710 712 const tr_peer * peer = peers[k]; 711 if( peer->peerIsInterested && !peer->clientIsChoked 712 && tr_bitfieldHas( peer->have, piece ) ) 713 if( peer->peerIsInterested 714 && !peer->clientIsChoked 715 && tr_bitfieldHas( peer->have, piece ) ) 713 716 ++setme->peerCount; 714 717 } … … 780 783 blockIteratorFree( struct tr_blockIterator * i ) 781 784 { 785 tr_free( i->blocks ); 782 786 tr_free( i->pieces ); 783 tr_free( i->blocks );784 787 tr_free( i ); 785 788 } … … 800 803 /* Get a list of peers we're downloading from. 801 804 Pick a different starting point each time so all peers 802 get a chance at the first blocks in the queue */805 get a chance at being the first in line */ 803 806 const int fencepost = tr_cryptoWeakRandInt( peerCount ); 804 807 int i = fencepost; … … 815 818 } 816 819 820 static uint32_t 821 getBlockOffsetInPiece( const tr_torrent * tor, uint64_t b ) 822 { 823 const uint64_t piecePos = tor->info.pieceSize * tr_torBlockPiece( tor, b ); 824 const uint64_t blockPos = tor->blockSize * b; 825 assert( blockPos >= piecePos ); 826 return (uint32_t)( blockPos - piecePos ); 827 } 828 817 829 static int 818 830 refillPulse( void * vtorrent ) … … 848 860 849 861 const tr_piece_index_t index = tr_torBlockPiece( tor, block ); 850 const uint32_t begin = (block * tor->blockSize) - (index * tor->info.pieceSize);862 const uint32_t offset = getBlockOffsetInPiece( tor, block ); 851 863 const uint32_t length = tr_torBlockCountBytes( tor, block ); 852 864 853 assert( tr_torrentReqIsValid( tor, index, begin, length ) );854 assert( _tr_block( tor, index, begin) == block );855 assert( begin< tr_torPieceCountBytes( tor, index ) );856 assert( ( begin+ length) <= tr_torPieceCountBytes( tor, index ) );865 assert( tr_torrentReqIsValid( tor, index, offset, length ) ); 866 assert( _tr_block( tor, index, offset ) == block ); 867 assert( offset < tr_torPieceCountBytes( tor, index ) ); 868 assert( (offset + length) <= tr_torPieceCountBytes( tor, index ) ); 857 869 858 870 /* find a peer who can ask for this block */ 859 871 for( j=0; !handled && j<peerCount; ) 860 872 { 861 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, index, begin, length ); 873 const int val = tr_peerMsgsAddRequest( peers[j]->msgs, 874 index, offset, length ); 862 875 switch( val ) 863 876 { … … 886 899 for( j=0; !handled && j<webseedCount; ) 887 900 { 888 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], index, begin, length ); 901 const tr_addreq_t val = tr_webseedAddRequest( webseeds[j], 902 index, offset, length ); 889 903 switch( val ) 890 904 {
Note: See TracChangeset
for help on using the changeset viewer.