source: trunk/libtransmission/torrent.h @ 7154

Last change on this file since 7154 was 7154, checked in by charles, 12 years ago

(libT) yet another stab at getting bandwidth management under control. this version may suck less than previous attempts. It also breaks the mac build until someone adds iobuf.[ch] to xcode...

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