source: trunk/libtransmission/torrent.h @ 6932

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

#1366: move tr_ctor{Set,Get}Save() to a package-private header.

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