source: trunk/libtransmission/completion.h @ 5

Last change on this file since 5 was 5, checked in by root, 16 years ago

Update 2005-11-18

File size: 2.9 KB
Line 
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
23struct 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
33tr_completion_t * tr_cpInit( tr_torrent_t * );
34void              tr_cpClose( tr_completion_t * );
35void              tr_cpReset( tr_completion_t * );
36
37/* General */
38float             tr_cpCompletionAsFloat( tr_completion_t * );
39static inline int tr_cpIsSeeding( tr_completion_t * cp )
40{
41    return ( cp->blockCount == cp->tor->blockCount );
42}
43uint64_t          tr_cpLeftBytes( tr_completion_t * );
44
45/* Pieces */
46int               tr_cpPieceIsComplete( tr_completion_t *, int piece );
47uint8_t         * tr_cpPieceBitfield( tr_completion_t * );
48void              tr_cpPieceAdd( tr_completion_t *, int piece );
49
50/* Blocks */
51void              tr_cpDownloaderAdd( tr_completion_t *, int block );
52void              tr_cpDownloaderRem( tr_completion_t *, int block );
53int               tr_cpBlockIsComplete( tr_completion_t *, int block );
54void              tr_cpBlockAdd( tr_completion_t *, int block );
55void              tr_cpBlockRem( tr_completion_t *, int block );
56uint8_t         * tr_cpBlockBitfield( tr_completion_t * );
57void              tr_cpBlockBitfieldSet( tr_completion_t *, uint8_t * );
58/* Missing = we don't have it and we are not getting it from any peer yet */
59static inline int tr_cpMissingBlocksForPiece( tr_completion_t * cp, int piece )
60{
61    return cp->missingBlocks[piece];
62}
63int               tr_cpMissingBlockInPiece( tr_completion_t *, int piece );
64int               tr_cpMostMissingBlockInPiece( tr_completion_t *, int piece,
65                                                int * downloaders );
Note: See TracBrowser for help on using the repository browser.