1 | /****************************************************************************** |
---|
2 | * Copyright (c) 2005 Eric Petit |
---|
3 | * |
---|
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
5 | * copy of this software and associated documentation files (the "Software"), |
---|
6 | * to deal in the Software without restriction, including without limitation |
---|
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
8 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
9 | * Software is furnished to do so, subject to the following conditions: |
---|
10 | * |
---|
11 | * The above copyright notice and this permission notice shall be included in |
---|
12 | * all copies or substantial portions of the Software. |
---|
13 | * |
---|
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
20 | * DEALINGS IN THE SOFTWARE. |
---|
21 | *****************************************************************************/ |
---|
22 | |
---|
23 | struct tr_completion_s |
---|
24 | { |
---|
25 | tr_torrent_t * tor; |
---|
26 | uint8_t * blockBitfield; |
---|
27 | uint8_t * blockDownloaders; |
---|
28 | int blockCount; |
---|
29 | uint8_t * pieceBitfield; |
---|
30 | int * missingBlocks; |
---|
31 | }; |
---|
32 | |
---|
33 | tr_completion_t * tr_cpInit( tr_torrent_t * ); |
---|
34 | void tr_cpClose( tr_completion_t * ); |
---|
35 | void tr_cpReset( tr_completion_t * ); |
---|
36 | |
---|
37 | /* General */ |
---|
38 | float tr_cpCompletionAsFloat( tr_completion_t * ); |
---|
39 | static inline int tr_cpIsSeeding( tr_completion_t * cp ) |
---|
40 | { |
---|
41 | return ( cp->blockCount == cp->tor->blockCount ); |
---|
42 | } |
---|
43 | uint64_t tr_cpLeftBytes( tr_completion_t * ); |
---|
44 | |
---|
45 | /* Pieces */ |
---|
46 | int tr_cpPieceIsComplete( tr_completion_t *, int piece ); |
---|
47 | uint8_t * tr_cpPieceBitfield( tr_completion_t * ); |
---|
48 | void tr_cpPieceAdd( tr_completion_t *, int piece ); |
---|
49 | |
---|
50 | /* Blocks */ |
---|
51 | void tr_cpDownloaderAdd( tr_completion_t *, int block ); |
---|
52 | void tr_cpDownloaderRem( tr_completion_t *, int block ); |
---|
53 | int tr_cpBlockIsComplete( tr_completion_t *, int block ); |
---|
54 | void tr_cpBlockAdd( tr_completion_t *, int block ); |
---|
55 | void tr_cpBlockRem( tr_completion_t *, int block ); |
---|
56 | uint8_t * tr_cpBlockBitfield( tr_completion_t * ); |
---|
57 | void tr_cpBlockBitfieldSet( tr_completion_t *, uint8_t * ); |
---|
58 | /* Missing = we don't have it and we are not getting it from any peer yet */ |
---|
59 | static inline int tr_cpMissingBlocksForPiece( tr_completion_t * cp, int piece ) |
---|
60 | { |
---|
61 | return cp->missingBlocks[piece]; |
---|
62 | } |
---|
63 | int tr_cpMissingBlockInPiece( tr_completion_t *, int piece ); |
---|
64 | int tr_cpMostMissingBlockInPiece( tr_completion_t *, int piece, |
---|
65 | int * downloaders ); |
---|