1 | 1656,1666d1655 |
---|
2 | < int |
---|
3 | < tr_availableCount(const tr_peer ** peers, int peerCount, int piece) { |
---|
4 | < int count = 0; |
---|
5 | < int i; |
---|
6 | < for( i = 0; i < peerCount; ++i ) |
---|
7 | < if( tr_bitfieldHas( peers[i]->have, piece ) ) |
---|
8 | < count++; |
---|
9 | < |
---|
10 | < return count; |
---|
11 | < } |
---|
12 | < |
---|
13 | 1691,1724c1680 |
---|
14 | < if( isSeed ) |
---|
15 | < tab[i] = -1; |
---|
16 | < else |
---|
17 | < { |
---|
18 | < int first_piece = i * interval; |
---|
19 | < |
---|
20 | < // Last piece of last interval is also the last piece of the torrent |
---|
21 | < int last_piece = i < tabCount - 1 ? ( i + 1 ) * interval : tor->info.pieceCount - 1; |
---|
22 | < |
---|
23 | < float lower_piece_fract = 1.0f - ((float)i * interval - first_piece ); |
---|
24 | < float upper_piece_fract = ((float)(i + 1) * interval - last_piece ); |
---|
25 | < |
---|
26 | < float sum = 0.0f, result; |
---|
27 | < |
---|
28 | < if ( first_piece == last_piece ) { |
---|
29 | < if ( tr_cpPieceIsComplete( &tor->completion, first_piece ) ) |
---|
30 | < result = -1; |
---|
31 | < else |
---|
32 | < result = tr_availableCount(peers, peerCount, first_piece); |
---|
33 | < } |
---|
34 | < else { |
---|
35 | < float incompleteCount = 0.0f; |
---|
36 | < |
---|
37 | < if ( !tr_cpPieceIsComplete( &tor->completion, first_piece ) ) |
---|
38 | < { |
---|
39 | < sum += tr_availableCount(peers, peerCount, first_piece) * lower_piece_fract; |
---|
40 | < incompleteCount += lower_piece_fract; |
---|
41 | < } |
---|
42 | < |
---|
43 | < if ( !tr_cpPieceIsComplete( &tor->completion, last_piece ) ) |
---|
44 | < { |
---|
45 | < sum += tr_availableCount(peers, peerCount, last_piece) * upper_piece_fract; |
---|
46 | < incompleteCount += upper_piece_fract; |
---|
47 | < } |
---|
48 | --- |
---|
49 | > const int piece = i * interval; |
---|
50 | 1725a1682,1684 |
---|
51 | > if( isSeed || tr_cpPieceIsComplete( &tor->completion, piece ) ) |
---|
52 | > tab[i] = -1; |
---|
53 | > else if( peerCount ) { |
---|
54 | 1727,1738c1686,1688 |
---|
55 | < for ( j = first_piece + 1; j < last_piece; j++ ) { |
---|
56 | < if ( !tr_cpPieceIsComplete( &tor->completion, j ) ) |
---|
57 | < { |
---|
58 | < sum += tr_availableCount(peers, peerCount, j ); |
---|
59 | < incompleteCount += 1.0f; |
---|
60 | < } |
---|
61 | < } |
---|
62 | < |
---|
63 | < result = incompleteCount > 0 ? ( sum / incompleteCount ) : -1.0f; |
---|
64 | < } |
---|
65 | < |
---|
66 | < tab[i] = (int)result; |
---|
67 | --- |
---|
68 | > for( j = 0; j < peerCount; ++j ) |
---|
69 | > if( tr_bitfieldHas( peers[j]->have, i ) ) |
---|
70 | > ++tab[i]; |
---|