source: trunk/libtransmission/torrent.h @ 6832

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

(libT) housekeeping: tr_torrent.handle --> tr_torrent.session

  • Property svn:keywords set to Date Rev Author Id
File size: 7.8 KB
Line 
1/******************************************************************************
2 * $Id: torrent.h 6832 2008-10-02 15:53:33Z 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 * session );
45
46void        tr_torrentUnlock( const tr_torrent * session );
47
48int         tr_torrentIsSeed( const tr_torrent * session );
49
50void        tr_torrentChangeMyPort( tr_torrent * session );
51
52int         tr_torrentExists( const tr_session * session,
53                              const uint8_t    * hash );
54
55tr_torrent* tr_torrentFindFromId( tr_session * session,
56                                  int          id );
57
58tr_torrent* tr_torrentFindFromHash( tr_session *    session,
59                                    const uint8_t * hash );
60
61tr_torrent* tr_torrentFindFromHashString( tr_session * session,
62                                          const char * hashString );
63
64tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session    * session,
65                                              const uint8_t * hash );
66
67int         tr_torrentAllowsPex( const tr_torrent * );
68
69/* get the index of this piece's first block */
70#define tr_torPieceFirstBlock( tor, piece ) ( ( piece ) *\
71                                             ( tor )->blockCountInPiece )
72
73/* what piece index is this block in? */
74#define tr_torBlockPiece( tor, block ) ( ( block ) /\
75                                        ( tor )->blockCountInPiece )
76
77/* how many blocks are in this piece? */
78#define tr_torPieceCountBlocks( tor, piece ) \
79    ( ( ( piece ) ==\
80       ( ( tor )->info.pieceCount - \
81        1 ) ) ? ( tor )->blockCountInLastPiece : ( tor )->blockCountInPiece )
82
83/* how many bytes are in this piece? */
84#define tr_torPieceCountBytes( tor, piece ) \
85    ( ( ( piece ) ==\
86       ( ( tor )->info.pieceCount - \
87        1 ) ) ? ( tor )->lastPieceSize : ( tor )->info.pieceSize )
88
89/* how many bytes are in this block? */
90#define tr_torBlockCountBytes( tor, block ) \
91    ( ( ( block ) ==\
92       ( ( tor )->blockCount - \
93        1 ) ) ? ( tor )->lastBlockSize : ( tor )->blockSize )
94
95#define tr_block( a, b ) _tr_block( tor, a, b )
96tr_block_index_t _tr_block( const tr_torrent * tor,
97                            tr_piece_index_t   index,
98                            uint32_t           offset );
99
100int              tr_torrentReqIsValid( const tr_torrent * tor,
101                                       tr_piece_index_t   index,
102                                       uint32_t           offset,
103                                       uint32_t           length );
104
105uint64_t         tr_pieceOffset( const tr_torrent * tor,
106                                 tr_piece_index_t   index,
107                                 uint32_t           offset,
108                                 uint32_t           length );
109
110void             tr_torrentInitFilePriority( tr_torrent *    tor,
111                                             tr_file_index_t fileIndex,
112                                             tr_priority_t   priority );
113
114
115int              tr_torrentCountUncheckedPieces( const tr_torrent * );
116
117int              tr_torrentIsPieceChecked( const            tr_torrent *,
118                                           tr_piece_index_t piece );
119
120int              tr_torrentIsFileChecked( const           tr_torrent *,
121                                          tr_file_index_t file );
122
123void             tr_torrentSetPieceChecked(
124                     tr_torrent *,
125    tr_piece_index_t piece,
126    int              isChecked );
127
128void             tr_torrentSetFileChecked(
129    tr_torrent *,
130    tr_file_index_t
131    file,
132    int
133    isChecked );
134
135void             tr_torrentUncheck( tr_torrent * );
136
137int              tr_torrentPromoteTracker(                 tr_torrent *,
138                                                       int trackerIndex );
139
140time_t*          tr_torrentGetMTimes( const    tr_torrent *,
141                                      size_t * setmeCount );
142
143typedef enum
144{
145    TR_VERIFY_NONE,
146    TR_VERIFY_WAIT,
147    TR_VERIFY_NOW
148}
149tr_verify_state;
150
151struct tr_torrent
152{
153    tr_session *             session;
154    tr_info                  info;
155
156    int                      uploadLimit;
157    tr_speedlimit            uploadLimitMode;
158    int                      downloadLimit;
159    tr_speedlimit            downloadLimitMode;
160
161    struct tr_ratecontrol *  swarmSpeed;
162
163    int                      error;
164    char                     errorString[128];
165
166    uint8_t                  obfuscatedHash[SHA_DIGEST_LENGTH];
167
168    /* Where to download */
169    char *  downloadDir;
170
171    /* How many bytes we ask for per request */
172    uint32_t                   blockSize;
173    tr_block_index_t           blockCount;
174
175    uint32_t                   lastBlockSize;
176    uint32_t                   lastPieceSize;
177
178    uint32_t                   blockCountInPiece;
179    uint32_t                   blockCountInLastPiece;
180
181    struct tr_completion *     completion;
182
183    struct tr_bitfield *       checkedPieces;
184    cp_status_t                cpStatus;
185
186    struct tr_tracker *        tracker;
187    struct tr_publisher_tag *  trackerSubscription;
188
189    uint64_t                   downloadedCur;
190    uint64_t                   downloadedPrev;
191    uint64_t                   uploadedCur;
192    uint64_t                   uploadedPrev;
193    uint64_t                   corruptCur;
194    uint64_t                   corruptPrev;
195
196    time_t                     addedDate;
197    time_t                     activityDate;
198    time_t                     doneDate;
199    time_t                     startDate;
200
201    tr_torrent_status_func *   status_func;
202    void *                     status_func_user_data;
203
204    unsigned int               isRunning  : 1;
205    unsigned int               isDeleting : 1;
206
207    uint16_t                   maxConnectedPeers;
208
209    tr_verify_state            verifyState;
210
211    time_t                     lastStatTime;
212    tr_stat                    stats;
213
214    tr_torrent *               next;
215
216    int                        uniqueId;
217
218    double                     rateHistory[2][BANDWIDTH_PULSE_HISTORY];
219};
220
221#endif
Note: See TracBrowser for help on using the repository browser.