source: trunk/libtransmission/torrent.h @ 7064

Last change on this file since 7064 was 7064, checked in by charles, 13 years ago

#1429 (libT) cleaner handling of the special case where the upload or download speed limit is zero

  • Property svn:keywords set to Date Rev Author Id
File size: 8.8 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 7064 2008-11-07 04:10:27Z 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
28struct tr_ratecontrol;
29
30/**
31***  Package-visible ctor API
32**/
33
34void        tr_ctorSetSave( tr_ctor * ctor,
35                            int       saveMetadataInOurTorrentsDir );
36
37int         tr_ctorGetSave( const tr_ctor * ctor );
38
39/**
40***
41**/
42
43/* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */
44void        tr_torrentInitFileDLs( tr_torrent *      tor,
45                                   tr_file_index_t * files,
46                                   tr_file_index_t   fileCount,
47                                   int               do_download );
48
49int         tr_torrentIsPrivate( const tr_torrent * );
50
51void        tr_torrentRecheckCompleteness( tr_torrent * );
52
53void        tr_torrentResetTransferStats( tr_torrent * );
54
55void        tr_torrentSetHasPiece( tr_torrent *     tor,
56                                   tr_piece_index_t pieceIndex,
57                                   int              has );
58
59void        tr_torrentLock( const tr_torrent * session );
60
61void        tr_torrentUnlock( const tr_torrent * session );
62
63int         tr_torrentIsSeed( const tr_torrent * session );
64
65void        tr_torrentChangeMyPort( tr_torrent * session );
66
67int         tr_torrentExists( const tr_session * session,
68                              const uint8_t    * hash );
69
70tr_torrent* tr_torrentFindFromId( tr_session * session,
71                                  int          id );
72
73tr_torrent* tr_torrentFindFromHash( tr_session *    session,
74                                    const uint8_t * hash );
75
76tr_torrent* tr_torrentFindFromHashString( tr_session * session,
77                                          const char * hashString );
78
79tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session    * session,
80                                              const uint8_t * hash );
81
82int         tr_torrentAllowsPex( const tr_torrent * );
83
84int         tr_torrentPieceTransferIsAllowed( const tr_torrent * torrent,
85                                              tr_direction       direction );
86
87/* get the index of this piece's first block */
88#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
89                                             ( tor )->blockCountInPiece )
90
91/* what piece index is this block in? */
92#define tr_torBlockPiece( tor, block ) ( ( block ) /\
93                                        ( tor )->blockCountInPiece )
94
95/* how many blocks are in this piece? */
96#define tr_torPieceCountBlocks( tor, piece ) \
97    ( ( ( piece ) ==\
98       ( ( tor )->info.pieceCount - \
99        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
100
101/* how many bytes are in this piece? */
102#define tr_torPieceCountBytes( tor, piece ) \
103    ( ( ( piece ) ==\
104       ( ( tor )->info.pieceCount - \
105        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
106
107/* how many bytes are in this block? */
108#define tr_torBlockCountBytes( tor, block ) \
109    ( ( ( block ) ==\
110       ( ( tor )->blockCount - \
111        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
112
113#define tr_block( a, b ) _tr_block( tor, a, b )
114tr_block_index_t _tr_block( const tr_torrent * tor,
115                            tr_piece_index_t   index,
116                            uint32_t           offset );
117
118int              tr_torrentReqIsValid( const tr_torrent * tor,
119                                       tr_piece_index_t   index,
120                                       uint32_t           offset,
121                                       uint32_t           length );
122
123uint64_t         tr_pieceOffset( const tr_torrent * tor,
124                                 tr_piece_index_t   index,
125                                 uint32_t           offset,
126                                 uint32_t           length );
127
128void             tr_torrentInitFilePriority( tr_torrent       * tor,
129                                             tr_file_index_t    fileIndex,
130                                             tr_priority_t      priority );
131
132
133int              tr_torrentCountUncheckedPieces( const tr_torrent * );
134
135int              tr_torrentIsPieceChecked( const tr_torrent  * tor,
136                                           tr_piece_index_t    piece );
137
138int              tr_torrentIsFileChecked( const tr_torrent  * tor,
139                                          tr_file_index_t     file );
140
141void             tr_torrentSetPieceChecked( tr_torrent       * tor,
142                                            tr_piece_index_t   piece,
143                                            int                isChecked );
144
145void             tr_torrentSetFileChecked( tr_torrent       * tor,
146                                           tr_file_index_t    file,
147                                           int                isChecked );
148
149void             tr_torrentUncheck( tr_torrent * tor );
150
151int              tr_torrentPromoteTracker( tr_torrent   * tor,
152                                           int            trackerIndex );
153
154time_t*          tr_torrentGetMTimes( const tr_torrent  * tor,
155                                      size_t            * setmeCount );
156
157typedef enum
158{
159    TR_VERIFY_NONE,
160    TR_VERIFY_WAIT,
161    TR_VERIFY_NOW
162}
163tr_verify_state;
164
165struct tr_torrent
166{
167    tr_session *             session;
168    tr_info                  info;
169
170    int                      uploadLimit;
171    tr_speedlimit            uploadLimitMode;
172    int                      downloadLimit;
173    tr_speedlimit            downloadLimitMode;
174
175    struct tr_ratecontrol *  swarmSpeed;
176
177    int                      error;
178    char                     errorString[128];
179
180    uint8_t                  obfuscatedHash[SHA_DIGEST_LENGTH];
181
182    /* Where to download */
183    char *  downloadDir;
184
185    /* How many bytes we ask for per request */
186    uint32_t                   blockSize;
187    tr_block_index_t           blockCount;
188
189    uint32_t                   lastBlockSize;
190    uint32_t                   lastPieceSize;
191
192    uint32_t                   blockCountInPiece;
193    uint32_t                   blockCountInLastPiece;
194
195    struct tr_completion *     completion;
196
197    struct tr_bitfield *       checkedPieces;
198    tr_completeness            completeness;
199
200    struct tr_tracker *        tracker;
201    struct tr_publisher_tag *  trackerSubscription;
202
203    uint64_t                   downloadedCur;
204    uint64_t                   downloadedPrev;
205    uint64_t                   uploadedCur;
206    uint64_t                   uploadedPrev;
207    uint64_t                   corruptCur;
208    uint64_t                   corruptPrev;
209
210    time_t                     addedDate;
211    time_t                     activityDate;
212    time_t                     doneDate;
213    time_t                     startDate;
214
215    tr_torrent_completeness_func *   completeness_func;
216    void *                     completeness_func_user_data;
217
218    unsigned int               isRunning  : 1;
219    unsigned int               isDeleting : 1;
220
221    uint16_t                   maxConnectedPeers;
222
223    tr_verify_state            verifyState;
224
225    time_t                     lastStatTime;
226    tr_stat                    stats;
227
228    tr_torrent *               next;
229
230    int                        uniqueId;
231
232    /* this is the count of raw bytes transferred between the
233     * client and its peers over the past HISTORY time slices.
234     * this count is used for bandwidth allocation, and includes
235     * piece data, protocol overhead, and estimated tcp header overhead. */
236    double                     rateHistory[2][BANDWIDTH_PULSE_HISTORY];
237
238    /* the rate at which pieces are being transferred between client and
239     * its peers.  protocol overhead is NOT included; only the piece data */
240    struct tr_ratecontrol    * pieceSpeed[2];
241};
242
243#endif
Note: See TracBrowser for help on using the repository browser.