source: trunk/libtransmission/torrent.h @ 5611

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

'resume' cleanup

  • Property svn:keywords set to Date Rev Author Id
File size: 6.6 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 5611 2008-04-14 11:52:50Z charles $
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                            tr_file_index_t  * files,
31                            tr_file_index_t    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,
41                            tr_piece_index_t   pieceIndex,
42                            int                has );
43
44void tr_torrentLock    ( const tr_torrent * );
45void tr_torrentUnlock  ( const tr_torrent * );
46
47int  tr_torrentIsSeed  ( const tr_torrent * );
48
49void tr_torrentChangeMyPort  ( tr_torrent * );
50
51int tr_torrentExists( tr_handle *, const uint8_t * );
52tr_torrent* tr_torrentFindFromHash( tr_handle *, const uint8_t * );
53tr_torrent* tr_torrentFindFromObfuscatedHash( tr_handle *, const uint8_t* );
54
55void tr_torrentGetRates( const tr_torrent *, float * toClient, float * toPeer );
56
57int tr_torrentAllowsPex( const tr_torrent * );
58
59/* get the index of this piece's first block */
60#define tr_torPieceFirstBlock(tor,piece) ( (piece) * (tor)->blockCountInPiece )
61
62/* what piece index is this block in? */
63#define tr_torBlockPiece(tor,block) ( (block) / (tor)->blockCountInPiece )
64
65/* how many blocks are in this piece? */
66#define tr_torPieceCountBlocks(tor,piece) \
67    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->blockCountInLastPiece : (tor)->blockCountInPiece )
68
69/* how many bytes are in this piece? */
70#define tr_torPieceCountBytes(tor,piece) \
71    ( ((piece)==((tor)->info.pieceCount-1)) ? (tor)->lastPieceSize : (tor)->info.pieceSize )
72
73/* how many bytes are in this block? */
74#define tr_torBlockCountBytes(tor,block) \
75    ( ((block)==((tor)->blockCount-1)) ? (tor)->lastBlockSize : (tor)->blockSize )
76
77#define tr_block(a,b) _tr_block(tor,a,b)
78tr_block_index_t _tr_block( const tr_torrent * tor,
79                            tr_piece_index_t   index,
80                            uint32_t           offset );
81
82int tr_torrentReqIsValid( const tr_torrent * tor,
83                          tr_piece_index_t   index,
84                          uint32_t           offset,
85                          uint32_t           length );
86
87uint64_t tr_pieceOffset( const tr_torrent * tor,
88                         tr_piece_index_t   index,
89                         uint32_t           offset,
90                         uint32_t           length );
91
92void tr_torrentInitFilePriority( tr_torrent       * tor,
93                                 tr_file_index_t    fileIndex,
94                                 tr_priority_t      priority );
95
96
97int  tr_torrentCountUncheckedPieces( const tr_torrent * );
98int  tr_torrentIsPieceChecked      ( const tr_torrent *, tr_piece_index_t piece );
99int  tr_torrentIsFileChecked       ( const tr_torrent *, tr_file_index_t file );
100void tr_torrentSetPieceChecked     ( tr_torrent *, tr_piece_index_t piece, int isChecked );
101void tr_torrentSetFileChecked      ( tr_torrent *, tr_file_index_t file, int isChecked );
102void tr_torrentUncheck             ( tr_torrent * );
103
104time_t* tr_torrentGetMTimes        ( const tr_torrent *, int * setmeCount );
105
106typedef enum
107{
108   TR_VERIFY_NONE,
109   TR_VERIFY_WAIT,
110   TR_VERIFY_NOW
111}
112tr_verify_state;
113
114struct tr_torrent
115{
116    tr_handle                * handle;
117    tr_info                    info;
118
119    tr_speedlimit              uploadLimitMode;
120    tr_speedlimit              downloadLimitMode;
121    struct tr_ratecontrol    * upload;
122    struct tr_ratecontrol    * download;
123    struct tr_ratecontrol    * swarmspeed;
124
125    int                        error;
126    char                       errorString[128];
127
128    uint8_t                    obfuscatedHash[SHA_DIGEST_LENGTH];
129
130    /* Where to download */
131    char                     * destination;
132   
133    /* How many bytes we ask for per request */
134    uint32_t                   blockSize;
135    tr_block_index_t           blockCount;
136
137    uint32_t                   lastBlockSize;
138    uint32_t                   lastPieceSize;
139
140    uint32_t                   blockCountInPiece;
141    uint32_t                   blockCountInLastPiece;
142   
143    struct tr_completion     * completion;
144
145    struct tr_bitfield       * checkedPieces;
146    cp_status_t                cpStatus;
147
148    struct tr_tracker        * tracker;
149    struct tr_publisher_tag  * trackerSubscription;
150
151    uint64_t                   downloadedCur;
152    uint64_t                   downloadedPrev;
153    uint64_t                   uploadedCur;
154    uint64_t                   uploadedPrev;
155    uint64_t                   corruptCur;
156    uint64_t                   corruptPrev;
157
158    uint64_t                   startDate;
159    uint64_t                   stopDate;
160    uint64_t                   activityDate;
161
162    tr_torrent_status_func   * status_func;
163    void                     * status_func_user_data;
164
165    tr_torrent_active_func   * active_func;
166    void                     * active_func_user_data;
167
168    unsigned int               isRunning : 1;
169    unsigned int               isDeleting : 1;
170
171    uint16_t                   maxConnectedPeers;
172
173    tr_verify_state            verifyState;
174
175    time_t                     lastStatTime;
176    tr_stat                    stats;
177
178    tr_torrent               * next;
179};
180
181#endif
Note: See TracBrowser for help on using the repository browser.