Changeset 8413
- Timestamp:
- May 16, 2009, 1:43:21 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libtransmission/torrent.c
r8398 r8413 843 843 int usableSeeds = 0; 844 844 uint64_t now; 845 double downloadedForRatio, seedRatio ;845 double downloadedForRatio, seedRatio=0; 846 846 tr_bool checkSeedRatio; 847 847 … … 983 983 984 984 static uint64_t 985 fileBytesCompleted( const tr_torrent * tor,985 oldFileBytesCompleted( const tr_torrent * tor, 986 986 tr_file_index_t fileIndex ) 987 987 { … … 1031 1031 1032 1032 return haveBytes; 1033 } 1034 1035 static uint64_t 1036 fileBytesCompleted( const tr_torrent * tor, tr_file_index_t index ) 1037 { 1038 uint64_t total = 0; 1039 1040 const tr_file * f = &tor->info.files[index]; 1041 const tr_block_index_t firstBlock = f->offset / tor->blockSize; 1042 const uint64_t lastByte = f->offset + f->length - (f->length?1:0); 1043 const tr_block_index_t lastBlock = lastByte / tor->blockSize; 1044 1045 if( firstBlock == lastBlock ) 1046 { 1047 if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) ) 1048 total = f->length; 1049 } 1050 else 1051 { 1052 uint32_t i; 1053 1054 /* the first block */ 1055 if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) ) 1056 total += tor->blockSize - ( f->offset % tor->blockSize ); 1057 1058 /* the middle blocks */ 1059 if( f->firstPiece == f->lastPiece ) 1060 { 1061 for( i=firstBlock+1; i<lastBlock; ++i ) 1062 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) ) 1063 total += tor->blockSize; 1064 } 1065 else 1066 { 1067 const tr_block_index_t firstBlockOfLastPiece = tr_torPieceFirstBlock( tor, f->lastPiece ); 1068 const tr_block_index_t lastBlockOfFirstPiece = tr_torPieceFirstBlock( tor, f->firstPiece ) 1069 + tr_torPieceCountBlocks( tor, f->firstPiece ) 1070 - 1; 1071 /* the rest of the first piece */ 1072 for( i=firstBlock+1; i<lastBlock && i<=lastBlockOfFirstPiece; ++i ) 1073 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) ) 1074 total += tor->blockSize; 1075 1076 /* the middle pieces */ 1077 if( f->firstPiece + 1 < f->lastPiece ) { 1078 uint64_t b = tor->blockCountInPiece * ( f->lastPiece - ( f->firstPiece + 1 ) ); 1079 for( i=f->firstPiece+1; i<f->lastPiece; ++i ) 1080 b -= tr_cpMissingBlocksInPiece( &tor->completion, i ); 1081 b *= tor->blockSize; 1082 total += b; 1083 } 1084 1085 /* the rest of the last piece */ 1086 for( i=firstBlockOfLastPiece; i<lastBlock; ++i ) 1087 if( tr_cpBlockIsCompleteFast( &tor->completion, i ) ) 1088 total += tor->blockSize; 1089 } 1090 1091 /* the last block */ 1092 if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) ) 1093 total += ( lastByte+1 - (lastBlock*tor->blockSize) ); 1094 } 1095 1096 assert( total == oldFileBytesCompleted( tor, index ) ); 1097 return total; 1033 1098 } 1034 1099
Note: See TracChangeset
for help on using the changeset viewer.