source: trunk/libtransmission/torrent.h @ 5042

Last change on this file since 5042 was 5042, checked in by charles, 14 years ago

modify "verify local data" to not lose the blocks in incomplete pieces

File size: 5.9 KB
Line 
1/******************************************************************************
2 * $Id:$
3 *
4 * Copyright (c) 2005-2008 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#ifndef TR_TORRENT_H
26#define TR_TORRENT_H 1
27
28/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
29void tr_torrentInitFileDLs( tr_torrent   * tor,
30                            int          * files,
31                            int            fileCount,
32                            int            do_download );
33
34int tr_torrentIsPrivate( const tr_torrent * );
35
36void tr_torrentRecheckCompleteness( tr_torrent * );
37
38void tr_torrentResetTransferStats( tr_torrent * );
39
40void tr_torrentSetHasPiece( tr_torrent * tor, int pieceIndex, int has );
41
42void tr_torrentLock    ( const tr_torrent * );
43void tr_torrentUnlock  ( const tr_torrent * );
44
45int  tr_torrentIsSeed  ( const tr_torrent * );
46
47void tr_torrentChangeMyPort  ( tr_torrent * );
48
49int tr_torrentExists( tr_handle *, const uint8_t * );
50tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
51tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
52
53void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
54
55int tr_torrentAllowsPex( const tr_torrent * );
56
57/* get the index of this piece's first block */
58#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
59
60/* what piece index is this block in? */
61#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
62
63/* how many blocks are in this piece? */
64#define tr_torPieceCountBlocks(tor,piece) \
65    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
66
67/* how many bytes are in this piece? */
68#define tr_torPieceCountBytes(tor,piece) \
69    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
70
71/* how many bytes are in this block? */
72#define tr_torBlockCountBytes(tor,block) \
73    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
74
75#define tr_block(a,b) _tr_block(tor,a,b)
76int _tr_block( const tr_torrent * tor, int index, int begin );
77
78uint64_t tr_pieceOffset( const tr_torrent * tor, int index, int begin, int length );
79
80void tr_torrentInitFilePriority( tr_torrent   * tor,
81                                 int            fileIndex,
82                                 tr_priority_t  priority );
83
84
85int  tr_torrentCountUncheckedPieces( const tr_torrent * );
86int  tr_torrentIsPieceChecked      ( const tr_torrent *, int piece );
87int  tr_torrentIsFileChecked       ( const tr_torrent *, int file );
88void tr_torrentSetPieceChecked     ( tr_torrent *, int piece, int isChecked );
89void tr_torrentSetFileChecked      ( tr_torrent *, int file, int isChecked );
90void tr_torrentUncheck             ( tr_torrent * );
91
92typedef enum
93{
94   TR_VERIFY_NONE,
95   TR_VERIFY_WAIT,
96   TR_VERIFY_NOW
97}
98tr_verify_state;
99
100struct tr_torrent
101{
102    tr_handle                 * handle;
103    tr_info                     info;
104
105    tr_speedlimit               uploadLimitMode;
106    tr_speedlimit               downloadLimitMode;
107    struct tr_ratecontrol     * upload;
108    struct tr_ratecontrol     * download;
109    struct tr_ratecontrol     * swarmspeed;
110
111    int                        error;
112    char                       errorString[128];
113
114    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
115
116    /* Where to download */
117    char                     * destination;
118   
119    /* How many bytes we ask for per request */
120    int                        blockSize;
121    int                        blockCount;
122
123    int                        lastBlockSize;
124    int                        lastPieceSize;
125
126    int                        blockCountInPiece;
127    int                        blockCountInLastPiece;
128   
129    struct tr_completion     * completion;
130
131    struct tr_bitfield       * checkedPieces;
132    cp_status_t                cpStatus;
133
134    struct tr_tracker        * tracker;
135    struct tr_publisher_tag  * trackerSubscription;
136
137    uint64_t                   downloadedCur;
138    uint64_t                   downloadedPrev;
139    uint64_t                   uploadedCur;
140    uint64_t                   uploadedPrev;
141    uint64_t                   corruptCur;
142    uint64_t                   corruptPrev;
143
144    uint64_t                   startDate;
145    uint64_t                   stopDate;
146    uint64_t                   activityDate;
147
148    tr_torrent_status_func   * status_func;
149    void                     * status_func_user_data;
150
151    tr_torrent_active_func   * active_func;
152    void                     * active_func_user_data;
153
154    unsigned int               statCur : 1;
155    unsigned int               isRunning : 1;
156
157    uint16_t                   maxConnectedPeers;
158
159    tr_verify_state           verifyState;
160
161    time_t                     lastStatTime;
162    tr_stat                    stats[2];
163
164    tr_torrent               * next;
165};
166
167#endif
Note: See TracBrowser for help on using the repository browser.